// This is here to compare the above pattern to a more traditional, // less-abstracted pattern. Food for thought... // // Note: Not tested, don't use. // private AggregateResult <ExamplePerson> SetEmailAddress2(string emailAddress) { AggregateResult <ExamplePerson> result; var notifications = new NotificationList(); if (emailAddress == null) { throw new ArgumentNullException(nameof(emailAddress)); } if (!RegexUtilities.IsValidEmail(emailAddress)) { notifications.AddNotification(nameof(EmailAddress), "A valid email address is required."); } if (notifications.HasNotifications) { result = AggregateResult <ExamplePerson> .Fail(notifications); } else { _emailAddress = emailAddress.Trim(); result = AggregateResult <ExamplePerson> .Success(this); } return(result); }
public static CommandResult ToCommandResult(this IdentityResult identityResult) { var notifications = new NotificationList(); foreach (var error in identityResult.Errors) { notifications.AddNotification(error.Code, error.Description); } return(CommandResult.Fail(notifications)); }
public static NotificationList CheckRequirements(List <AggregateRequirement> requirements) { var notifications = new NotificationList(); foreach (var requirement in requirements) { bool success = requirement.Test.Invoke(); if (!success) { if (requirement.Exception != null) { throw requirement.Exception; } notifications.AddNotification( requirement.ParamName, requirement.FailureMessage); } } return(notifications); }