Last active
May 31, 2020 03:39
-
-
Save wellingtonjhn/427bf809fd05b0703927bbdb6808f452 to your computer and use it in GitHub Desktop.
Domain Notification Structures Sample
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 class Notification | |
| { | |
| public string Key { get; } | |
| public string Message { get; } | |
| public Notification(string key, string message) | |
| { | |
| Key = key; | |
| Message = message; | |
| } | |
| } |
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 class NotificationContext | |
| { | |
| private readonly List<Notification> _notifications; | |
| public IReadOnlyCollection<Notification> Notifications => _notifications; | |
| public bool HasNotifications => _notifications.Any(); | |
| public NotificationContext() | |
| { | |
| _notifications = new List<Notification>(); | |
| } | |
| public void AddNotification(string key, string message) | |
| { | |
| _notifications.Add(new Notification(key, message)); | |
| } | |
| public void AddNotification(Notification notification) | |
| { | |
| _notifications.Add(notification); | |
| } | |
| public void AddNotifications(IReadOnlyCollection<Notification> notifications) | |
| { | |
| _notifications.AddRange(notifications); | |
| } | |
| public void AddNotifications(IList<Notification> notifications) | |
| { | |
| _notifications.AddRange(notifications); | |
| } | |
| public void AddNotifications(ICollection<Notification> notifications) | |
| { | |
| _notifications.AddRange(notifications); | |
| } | |
| public void AddNotifications(ValidationResult validationResult) | |
| { | |
| foreach (var error in validationResult.Errors) | |
| { | |
| AddNotification(error.ErrorCode, error.ErrorMessage); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment