Skip to content

Instantly share code, notes, and snippets.

@ryanvgates
Last active August 29, 2015 14:26
Show Gist options
  • Save ryanvgates/e684b87138c7bbab839e to your computer and use it in GitHub Desktop.
Save ryanvgates/e684b87138c7bbab839e to your computer and use it in GitHub Desktop.
Validation Logic
public override IEnumerable<RuleViolation> GetRuleViolations(int orgID)
{
if (string.IsNullOrEmpty(FirstName))
yield return new RuleViolation("First Name required", "FirstName");
if (string.IsNullOrEmpty(LastName))
yield return new RuleViolation("Last Name required", "LastName");
if (string.IsNullOrEmpty(Name))
yield return new RuleViolation("Name required", "Name");
if (string.IsNullOrEmpty(Phone))
yield return new RuleViolation("Phone required", "Phone");
}
public static void AddRuleViolations(this ModelStateDictionary modelState, IEnumerable<RuleViolation> errors)
{
if (errors != null)
{
foreach (RuleViolation issue in errors)
{
modelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment