Last active
August 29, 2015 14:26
-
-
Save ryanvgates/e684b87138c7bbab839e to your computer and use it in GitHub Desktop.
Validation Logic
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 characters
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