Exemplo n.º 1
0
 protected override ValidationResult IsValid(object value, ValidationContext validationContext)
 {
     if (value != null)
     {
         var date = (DateTime)value;
         if (date < _startDate)
         {
             return(new ValidationResult(ErrorMessage));
         }
         if (date > DateTime.Today)
         {
             return(new ValidationResult(ValidationMessages.TodayOrEarlier(validationContext.DisplayName)));
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(null);
            }

            var date     = (DateTime)value;
            var isLegacy = ((ModelBase)validationContext.ObjectInstance).IsLegacy;

            if (date < _startDate && isLegacy == false)
            {
                return(new ValidationResult(ErrorMessage));
            }
            if (date > DateTime.Today)
            {
                return(new ValidationResult(ValidationMessages.TodayOrEarlier(validationContext.DisplayName)));
            }
            return(null);
        }