protected override ActionResult InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary <string, object> parameters) { #region 1.请求方法验证 string pageId = controllerContext.HttpContext.Request.Params[LsMvcConst.RequestMenuIdKey]; object[] attrs = actionDescriptor.GetCustomAttributes(typeof(ActionTemplateAttribute), true); if (attrs.Length > 0) { var actionTemplate = (actionDescriptor.GetCustomAttributes(true)[0] as ActionTemplateAttribute).ActionTemplate; var pageUrl = ((System.Web.Routing.Route)(controllerContext.RouteData.Route)).Url.Split('/')[0] + "/" + controllerContext.RouteData.Values["controller"]; if (!_permissionValidator.Validate(pageUrl, pageId, actionTemplate)) { throw new LsException("抱歉,你没有此操作权限!", LsExceptionEnum.NoPermission); } } #endregion #region 2.请求参数验证 foreach (var p in parameters) { var results = _validation.Validate(p.Value); _validatorHandler.Handle(results); } #endregion return(base.InvokeActionMethod(controllerContext, actionDescriptor, parameters)); }
private async ValueTask <ICommandResult> Process <TCommand>(TCommand command, CancellationToken cancellationToken = default) where TCommand : ICommand { var commandResult = new CommandResult(); try { await _permissionValidator.Validate(command, cancellationToken).ConfigureAwait(false); await _validation.Validate(command, cancellationToken).ConfigureAwait(false); var concreteCommand = _mapper.CreateConcreteObject(command); var handler = _resolveHandler.ResolveHandler <ICommandHandler <TCommand> >(); commandResult = (CommandResult)await handler.Handle(concreteCommand).ConfigureAwait(false); await _eventPublisher.Publish(commandResult.Events, cancellationToken).ConfigureAwait(false); } catch (PermissionValidationException ex) { _logger.Error(ex, "Error command permission validation"); commandResult.Exception = ex; } catch (ValidationException ex) { _logger.Error(ex, "Error command validation"); commandResult.Exception = ex; } catch (Exception ex) { _logger.Error(ex, "Command was not successful"); commandResult.Exception = ex; } return(commandResult); }
public async ValueTask Validate <TCommand>(TCommand command, CancellationToken cancellationToken = default) where TCommand : ICommand { await _permissionValidator.Validate(command, cancellationToken).ConfigureAwait(false); if (command is IValidatable) { await _validation.Validate(command, cancellationToken).ConfigureAwait(false); } }
public object PermissionUpsert(int userId, PermissionPostModel permissionPostModel) { var errors = permissionValidator.Validate(permissionPostModel, context); if (errors != null) { return(errors); } var existing = context.Users.Include("UserUserRoles.UserRole").FirstOrDefault(u => u.Id == userId); var permission = this.GetPermissionFromDb(permissionPostModel.UserRole); if (existing == null) { return(null); } if (existing.UserUserRoles.Any(u => u. UserRole.Equals(permission))) { UserUserRole currentUseRole = existing.UserUserRoles.FirstOrDefault(u => u.UserRole.Equals(permission)); currentUseRole.EndTime = permissionPostModel.EndTime; currentUseRole.StartTime = permissionPostModel.StartTime; context.UserUserRoles.Update(currentUseRole); } else { context.UserUserRoles.Add(new UserUserRole { User = existing, UserRole = permission, StartTime = permissionPostModel.StartTime, EndTime = permissionPostModel.EndTime, }); } context.SaveChanges(); return(this.GetPermission(userId)); }