Last active
September 24, 2019 21:42
-
-
Save wellingtonjhn/5d2598eb835964571769a6b06956c01f to your computer and use it in GitHub Desktop.
Notification Filter
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 NotificationFilter : IAsyncResultFilter | |
| { | |
| private readonly NotificationContext _notificationContext; | |
| public NotificationFilter(NotificationContext notificationContext) | |
| { | |
| _notificationContext = notificationContext; | |
| } | |
| public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) | |
| { | |
| if (_notificationContext.HasNotifications) | |
| { | |
| context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; | |
| context.HttpContext.Response.ContentType = "application/json"; | |
| var notifications = JsonConvert.SerializeObject(_notificationContext.Notifications); | |
| await context.HttpContext.Response.WriteAsync(notifications); | |
| return; | |
| } | |
| await next(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment