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.GetNotifications());
                await context.HttpContext.Response.WriteAsync(notifications);

                return;
            }

            await next();
        }
Esempio n. 2
0
        protected new IActionResult Response(object result = null)
        {
            if (IsValidOperation())
            {
                return(Ok(new
                {
                    success = true,
                    data = result
                }));
            }

            return(BadRequest(new
            {
                success = false,
                errors = _notifications.GetNotifications().Select(n => n.Message)
            }));
        }