/// <summary> /// Notify /// </summary> /// <param name="notify"></param> /// <param name="showCloseButton"></param> /// <param name="htmlAttributes"></param> /// <returns></returns> public MvcHtmlString Notify(Thunder.Notify notify, bool showCloseButton, object htmlAttributes) { if (_helper.ViewContext.HttpContext.Session != null && _helper.ViewContext.HttpContext.Session[Constants.ViewData.Notify] != null) { _helper.ViewContext.HttpContext.Session.Remove(Constants.ViewData.Notify); } return(new NotifyBuilder().Builder(notify, showCloseButton, htmlAttributes)); }
/// <summary> /// Builder /// </summary> /// <param name="notify"></param> /// <param name="showCloseButton"></param> /// <param name="htmlAttributes"></param> /// <returns></returns> public MvcHtmlString Builder(Thunder.Notify notify, bool showCloseButton, object htmlAttributes) { if (!notify.Messages.Any()) { return(MvcHtmlString.Empty); } var tagBuilder = new TagBuilder("div"); var attributes = HtmlAttributesUtility.ObjectToHtmlAttributesDictionary(htmlAttributes); var content = string.Empty; if (showCloseButton) { var closeButton = new TagBuilder("button") { InnerHtml = "×" }; closeButton.Attributes.Add("type", "button"); closeButton.Attributes.Add("class", "close"); closeButton.Attributes.Add("data-dismiss", "alert"); closeButton.Attributes.Add("aria-hidden", "true"); content += closeButton.ToString(); } if (notify.Messages.Count > 0) { if (notify.Messages.Count == 1) { content += notify.Messages[0]; } else { var ul = new TagBuilder("ul"); foreach (var li in notify.Messages.Select(message => new TagBuilder("li") { InnerHtml = message })) { ul.InnerHtml += li.ToString(); } content += ul.ToString(); } } attributes.AddCssClass("alert{0}".With(CssClass(notify.Type))); tagBuilder.InnerHtml = content; tagBuilder.MergeAttributes(attributes); return(MvcHtmlString.Create(tagBuilder.ToString())); }
/// <summary> /// Notify /// </summary> /// <param name="notify"></param> /// <param name="showCloseButton"></param> /// <returns></returns> public MvcHtmlString Notify(Thunder.Notify notify, bool showCloseButton) { return(Notify(notify, showCloseButton, null)); }