コード例 #1
0
        public IViewComponentResult Invoke()
        {
            var model = new NotyfViewModel
            {
                Configuration = _options.ToJson(),
                Notifications = _service.ReadAllNotifications()
            };

            return(View("Default", model));
        }
コード例 #2
0
        private Task Callback(object context)
        {
            var httpContext = (HttpContext)context;

            if (httpContext.Request.IsNotyfAjaxRequest())
            {
                var messages = new NotyfViewModel
                {
                    Configuration = _options.ToJson(),
                    Notifications = _toastNotification.ReadAllNotifications()
                };
                if (messages.Notifications != null && messages.Notifications.Any())
                {
                    var accessControlExposeHeaders = $"{GetControlExposeHeaders(httpContext.Response.Headers)}";
                    httpContext.Response.Headers.Add(AccessControlExposeHeadersKey, accessControlExposeHeaders);

                    var notificationsJson = messages.Notifications.ToJson();
                    httpContext.Response.Headers.Add(Constants.NotyfResponseHeaderKey, WebUtility.UrlEncode(notificationsJson));
                }
            }
            return(Task.FromResult(0));
        }