Ejemplo n.º 1
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                var viewData = filterContext.Controller.ViewData;
                var response = filterContext.HttpContext.Response;

                foreach (var messageType in Enum.GetNames(typeof(NotificationMessageType)))
                {
                    var mt = messageType + "Resources";

                    var message = viewData.ContainsKey(messageType)
                                                                        ? viewData[messageType]
                                                                        : null;

                    var messageResources = viewData.ContainsKey(mt)
                                    ? viewData[mt]
                                    : null;

                    if (message != null)                     // We store only one message in the http header. First message that comes wins.
                    {
                        if ((messageResources as string).IsNullOrEmpty() == false)
                        {
                            message = Errors.ResourceManager.GetString((string)messageResources);
                        }

                        NotificationMvcHelper.AjaxMessage(response, messageType, message.ToString());
                        viewData[mt] = null;

                        return;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void IsAjaxRequest(string message, bool isRedirect)
        {
            _isRedirect = isRedirect;

            _filterContext.Result = new JsonResult
            {
                Data = new { success = false, error = message },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            NotificationMvcHelper.AjaxMessage(_filterContext.RequestContext.HttpContext.Response,
                                              NotificationMessageType.Error.ToString(), message);
        }