Created
August 5, 2022 18:05
-
-
Save flpinheiro/de28c53d103ca00c24393746a4b9fbb1 to your computer and use it in GitHub Desktop.
Revisions
-
flpinheiro revised this gist
Aug 5, 2022 . No changes.There are no files selected for viewing
-
flpinheiro created this gist
Aug 5, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ [AttributeUsage(AttributeTargets.Property)] public class DateLimitValidationAttribute : RequiredAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { base.IsValid(value, validationContext); if (value == null) return ValidationResult.Success; var date = Convert.ToDateTime(value); var ageOfDateInDays = DateTime.Today.Subtract(date).Days; if (ageOfDateInDays > 90) { return new ValidationResult("Select Date can not be older than 90 days, or 3 months."); } else { return ValidationResult.Success; } } }