protected override void OnModelUpdated(ControllerContext controllerContext,
                                               ModelBindingContext bindingContext)
        {
            IValidatable model = bindingContext.Model as IValidatable;

            if (model != null)
            {
                if (!model.IsValid())
                {
                    foreach (IValidationResult validationResult in model.ValidationResults())
                    {
                        bindingContext.ModelState
                        .AddModelError(validationResult.ClassContext.Name +
                                       (!string.IsNullOrEmpty(validationResult.PropertyName)
                                ? "." + validationResult.PropertyName
                                : ""),
                                       validationResult.Message);
                    }
                }
            }
        }
Beispiel #2
0
        public static bool Validate(this IValidatable validatable)
        {
            var status = validatable?.IsValid();

            return(status ?? false);
        }
Beispiel #3
0
        public static bool IsValid <T>(this IValidatable <T> entity)
        {
            var validator = ValidatorsTable.Get <T>();

            return(entity.IsValid(validator));
        }
 public void AssertIsValid(IValidatable obj)
 {
     Assert.That(obj.IsValid(), Is.True);
     Assert.That(obj.ValidationResults(), Has.Count.EqualTo(0));
 }
 public void AssertIsInvalid(IValidatable obj, int expectedErrorCount)
 {
     Assert.That(obj.IsValid(), Is.False);
     Assert.That(obj.ValidationResults(), Has.Count.EqualTo(expectedErrorCount));
 }
Beispiel #6
0
 public static bool Validate(this IValidatable validatable)
 {
     return(validatable != null && validatable.IsValid());
 }