Exemple #1
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // 3.
            if (_deleteCookie)
            {
                DeleteCookies(context);
                await next();

                return;
            }

            // We don't have any alerts
            if (_alerts.Count == 0)
            {
                await next();

                return;
            }

            // The controller action didn't return a view result so no need to continue execution
            if (!(context.Result is ViewResult result))
            {
                await next();

                return;
            }

            // Check early to ensure we are working with a LayoutViewModel
            if (!(result.Model is LayoutViewModel model))
            {
                await next();

                return;
            }

            // Add alerts to alerts zone within layout view model
            if (context.Controller is Controller controller)
            {
                var updater = await _layoutUpdater.GetLayoutAsync(controller);

                await updater.UpdateLayoutAsync(async layout =>
                {
                    layout.Alerts = await updater.UpdateZoneAsync(layout.Alerts, zone =>
                    {
                        foreach (var alert in _alerts)
                        {
                            zone.Add(new AlertCompiledView(alert));
                        }
                    });
                    return(layout);
                });
            }

            // We've displayed our alert so delete persistence
            // to ensure no further alerts are displayed
            DeleteCookies(context);

            // Finally execute the controller result
            await next();
        }
Exemple #2
0
        public async Task OnActionExecutingAsync(ResultExecutingContext context)
        {
            // Add our trace view to the layout
            // It's important to add this after the layout has rendered
            // This allows all queries to execute before rendering the trace list
            if (context.Controller is Controller controller)
            {
                var updater = await _layoutUpdater.GetLayoutAsync(controller);

                await updater.UpdateLayoutAsync(async layout =>
                {
                    layout.LayoutAfter = await updater.UpdateZoneAsync(layout.LayoutAfter, zone =>
                    {
                        zone.Add(new LayoutZoneView("DbTraceList", new {}).Order(int.MaxValue));
                    });
                    return(layout);
                });
            }
        }