Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ClassicMovieAttribute : ValidationAttribute, IClientModelValidator
- {
- private int _year;
- public ClassicMovieAttribute(int Year)
- {
- _year = Year;
- }
- protected override ValidationResult IsValid(object value, ValidationContext validationContext)
- {
- Movie movie = (Movie)validationContext.ObjectInstance;
- if (movie.Genre == Genre.Classic && movie.ReleaseDate.Year > _year)
- {
- return new ValidationResult(GetErrorMessage());
- }
- return ValidationResult.Success;
- }
Add Comment
Please, Sign In to add comment