Guest User

Untitled

a guest
Jun 25th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. public class ClassicMovieAttribute : ValidationAttribute, IClientModelValidator
  2. {
  3. private int _year;
  4.  
  5. public ClassicMovieAttribute(int Year)
  6. {
  7. _year = Year;
  8. }
  9.  
  10. protected override ValidationResult IsValid(object value, ValidationContext validationContext)
  11. {
  12. Movie movie = (Movie)validationContext.ObjectInstance;
  13.  
  14. if (movie.Genre == Genre.Classic && movie.ReleaseDate.Year > _year)
  15. {
  16. return new ValidationResult(GetErrorMessage());
  17. }
  18.  
  19. return ValidationResult.Success;
  20. }
Add Comment
Please, Sign In to add comment