Exemplo n.º 1
0
        /// <summary>
        /// Enables processing of the result of an action method by a custom type that inherits from the <see cref="T:System.Web.Mvc.ActionResult"/> class.
        /// </summary>
        /// <param name="context">The context in which the result is executed. The context information includes the controller, HTTP content, request context, and route data.</param>
        public override void ExecuteResult([NotNull] ControllerContext context)
        {
            Invariant.IsNotNull(context, "context");

            FlashStorage storage = new FlashStorage(context.Controller.TempData);

            foreach (KeyValuePair <string, string> pair in FlashMessages)
            {
                storage.Add(pair.Key, pair.Value);
            }

            WrappingResult.ExecuteResult(context);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Flashes the specified instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="tagName">Name of the tag.</param>
        /// <param name="encoded">if set to <c>true</c> [encoded].</param>
        /// <returns></returns>
        public static IHtmlString Flash([NotNull] this HtmlHelper instance, string tagName = "p", bool encoded = true)
        {
            Invariant.IsNotNull(instance, "instance");

            Func<string, XNode> content = message => encoded ? new XText(message) : XElement.Parse(message) as XNode;

            IList<KeyValuePair<string, string>> messages = new FlashStorage(instance.ViewContext.TempData).Messages.ToList();

            IEnumerable<XElement> elements = messages.Select(pair => new XElement(tagName ?? "p", new XAttribute("class", "flash" + " " + pair.Key), content(pair.Value)));
            string html = string.Join(Environment.NewLine, elements.Select(e => e.ToString()));

            return instance.Raw(html);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Flashes the specified instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="tagName">Name of the tag.</param>
        /// <param name="encoded">if set to <c>true</c> [encoded].</param>
        /// <returns></returns>
        public static IHtmlString Flash([NotNull] this HtmlHelper instance, string tagName = "p", bool encoded = true)
        {
            Invariant.IsNotNull(instance, "instance");

            Func <string, XNode> content = message => encoded ? new XText(message) : XElement.Parse(message) as XNode;

            IList <KeyValuePair <string, string> > messages = new FlashStorage(instance.ViewContext.TempData).Messages.ToList();

            IEnumerable <XElement> elements = messages.Select(pair => new XElement(tagName ?? "p", new XAttribute("class", "flash" + " " + pair.Key), content(pair.Value)));
            string html = string.Join(Environment.NewLine, elements.Select(e => e.ToString()));

            return(instance.Raw(html));
        }
Exemplo n.º 4
0
        private static void InjectFlashMessages([NotNull] ResponderContext context)
        {
            if (!context.FlashMessages.Any())
            {
                return;
            }

            FlashStorage flashStorage = new FlashStorage(context.ControllerContext.Controller.TempData);

            foreach (KeyValuePair <string, string> pair in context.FlashMessages)
            {
                flashStorage.Add(pair.Key, pair.Value);
            }
        }
Exemplo n.º 5
0
        private static void InjectFlashMessages(ResponderContext context)
        {
            if (!context.FlashMessages.Any())
            {
                return;
            }

            FlashStorage flashStorage = new FlashStorage(context.ControllerContext.Controller.TempData);

            foreach (KeyValuePair<string, string> pair in context.FlashMessages)
            {
                flashStorage.Add(pair.Key, pair.Value);
            }
        }