private static void RoleValidation(int roleId, HttpActionContext actionContext) { var actionName = actionContext.ActionDescriptor.ActionName; var controllerName = actionContext.ControllerContext.ControllerDescriptor.ControllerName; var roleConfigurationRepository = SimpleInjectorModule.GetContainer().GetInstance <IRoleConfigurationRepository>(); var permissionType = new PermissionType().GetValue(controllerName); var roleConfigsValidatePermission = roleConfigurationRepository.FindBy(roleConfig => roleConfig.RoleId == roleId && roleConfig.PermissionId == permissionType); if (roleConfigsValidatePermission.IsEmpty()) { ExceptionExtensions.ThrowCustomException(HttpStatusCode.Forbidden, "No tienes permisos"); } var accessLevelType = new AccessLevelType().GetValue(actionName); var roleConfigsValidateAccesLevel = roleConfigsValidatePermission.FirstOrDefault(roleConfig => roleConfig.PermissionId == permissionType && roleConfig.AccessLevelId == accessLevelType); if (roleConfigsValidateAccesLevel.IsNull()) { ExceptionExtensions.ThrowCustomException(HttpStatusCode.Forbidden, "No tienes nivel de acceso"); } }
public AccessLevelAttribute(AccessLevelType levelType) { this.LevelType = levelType; }