Skip to content

Instantly share code, notes, and snippets.

@wellingtonjhn
Last active September 24, 2019 21:42
Show Gist options
  • Select an option

  • Save wellingtonjhn/5d2598eb835964571769a6b06956c01f to your computer and use it in GitHub Desktop.

Select an option

Save wellingtonjhn/5d2598eb835964571769a6b06956c01f to your computer and use it in GitHub Desktop.
Notification Filter
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