Пример #1
0
        public ExecutionResult Execute(T command)
        {
            var canExecute = PermissionChecker.CanExecute(command);

            if (!canExecute)
            {
                return(new ExecutionResult()
                {
                    Success = false,
                    Errors = new List <String>()
                    {
                        "You do not have the necessary authorizations to execute this operation"
                    }
                });
            }

            var results = BusinessRuleValidator.Validate(command);

            if (results.Count > 0)
            {
                return(new ExecutionResult()
                {
                    Success = false,
                    Errors = results
                });
            }

            try
            {
                this.Apply(command);
                Repository.Commit();

                return(new ExecutionResult()
                {
                    Success = true
                });
            }
            catch (Exception e)
            {
                return(new ExecutionResult()
                {
                    Success = false,
                    Errors = new string[] { e.Message }
                });
            }
        }