Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dannylloyd/add19fc0a0eb29e684dde5a7e2671329 to your computer and use it in GitHub Desktop.
Save dannylloyd/add19fc0a0eb29e684dde5a7e2671329 to your computer and use it in GitHub Desktop.
private bool DateWithinSqlParameters(Event model, DateTime? date, PropertyValidatorContext context)
{
var maxDate = DateTime.Today.AddYears(30);
context.Rule.MessageBuilder = c=> $"Invalid date entered for {context.PropertyDescription}. Must be between 1/1/2000 - {maxDate.ToString("M/d/yyyy")}";
return !date.HasValue || (date.Value >= new DateTime(2000,1,1) && date.Value <= maxDate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment