コード例 #1
0
        public override void Execute(ControllerContext context)
        {
            var modelState = context.Controller.ViewData.ModelState;

            if (modelState.IsValid)
            {
                var         rulesEngine = MvcContrib.Services.DependencyResolver.GetImplementationOf <IRulesEngine>();
                ICanSucceed result      = rulesEngine.Process(_message);
                if (result.Successful)
                {
                    _result = result.Result <TResult>();
                    Success.ExecuteResult(context);
                    return;
                }

                foreach (ErrorMessage errorMessage in result.Errors)
                {
                    string exception = GetErrorMessage(errorMessage);

                    modelState.AddModelError(UINameHelper.BuildNameFrom(errorMessage.InvalidProperty), exception);
                }
            }

            Failure.ExecuteResult(context);
        }
コード例 #2
0
        public int CountByProperty <TModel>(IEntitySpecification <TModel> specification) where TModel : PersistentObject
        {
            var property = UINameHelper.BuildNameFrom(specification.PropertyExpression);

            var criteria = GetSession().CreateCriteria(typeof(TModel));

            criteria.Add(Restrictions.Eq(property, specification.Value));

            if (specification.HasExistingId)
            {
                criteria.Add(Restrictions.Not(Restrictions.Eq(PersistentObject.ID, specification.ExistingId)));
            }

            return(criteria.List <TModel>().Count());
        }
コード例 #3
0
        public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types)
        {
            if (!AuditingEnabled)
            {
                return(false);
            }

            var propertyName = UINameHelper.BuildNameFrom <IAuditable>(x => x.ChangeAuditInfo);

            if (entity is IAuditable && !(entity is User))
            {
                var auditable = (IAuditable)entity;

                var setter = GetSetter(propertyNames, state, propertyName);
                CommonAudit(auditable, setter);
                return(true);
            }
            return(false);
        }
コード例 #4
0
        public ValidationResult AddError <T>(Expression <Func <T, object> > messageExpression, string message)
        {
            string key = UINameHelper.BuildNameFrom(messageExpression);

            if (_errors.ContainsKey(key))
            {
                var strings = new List <string>(_errors[key])
                {
                    message
                };
                _errors[key] = strings.ToArray();
            }
            else
            {
                _errors.Add(key, new[] { message });
            }

            IsValid = false;

            return(this);
        }
コード例 #5
0
 public string[] GetErrors <T>(Expression <Func <T, object> > messageExpression)
 {
     return(GetErrors(UINameHelper.BuildNameFrom(messageExpression)));
 }
コード例 #6
0
        public void Should_build_name_from_indexed_expression()
        {
            Expression <Func <ExampleForm, object> > expression = f => f.DrugTestDrugTestResults[5].SubstanceTested;

            UINameHelper.BuildNameFrom(expression).ShouldEqual("DrugTestDrugTestResults[5].SubstanceTested");
        }
コード例 #7
0
        public void Should_build_name_from_basic_expression()
        {
            Expression <Func <ExampleForm, object> > expression = f => f.DrugTestId;

            UINameHelper.BuildNameFrom(expression).ShouldEqual("DrugTestId");
        }
コード例 #8
0
 public string BuildFailureMessage <TModel>(object value, Expression <Func <TModel, object> > propertyExpression) where TModel : PersistentObject
 {
     return(string.Format("Property '{0}' should be unique, but the value '{1}' already exists.",
                          UINameHelper.BuildNameFrom(propertyExpression), value));
 }
コード例 #9
0
        public void Should_build_name_from_indexed_expression()
        {
            Expression <Func <Stub, object> > expression = f => f.Subs[5].Number;

            UINameHelper.BuildNameFrom(expression).ShouldEqual("Subs[5].Number");
        }
コード例 #10
0
        public void Should_build_name_from_basic_expression()
        {
            Expression <Func <Stub, object> > expression = f => f.Name;

            UINameHelper.BuildNameFrom(expression).ShouldEqual("Name");
        }