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); }
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()); }
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); }
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); }
public string[] GetErrors <T>(Expression <Func <T, object> > messageExpression) { return(GetErrors(UINameHelper.BuildNameFrom(messageExpression))); }
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"); }
public void Should_build_name_from_basic_expression() { Expression <Func <ExampleForm, object> > expression = f => f.DrugTestId; UINameHelper.BuildNameFrom(expression).ShouldEqual("DrugTestId"); }
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)); }
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"); }
public void Should_build_name_from_basic_expression() { Expression <Func <Stub, object> > expression = f => f.Name; UINameHelper.BuildNameFrom(expression).ShouldEqual("Name"); }