public static void AddFlashMessage(HttpResponseBase response, FlashMessageType flashMessageType, string title, string body) { response.Cookies.Add(new HttpCookie("FlashMessage", JsonConvert.SerializeObject(new[] { flashMessageType.ToString().ToLower(), title, body })) { Path = "/" }); }
/// <summary> /// Generate one time show only message (even redirected). /// This flash message compatible with Twitter Bootstrap alert. /// This will clear all message. /// Call it in view using <code>@Html.Flash()</code> /// </summary> /// <param name="controller">Extension hook ke controller</param> /// <param name="message">message content</param> /// <param name="messageType">flash message type</param> public static void SetFlash(this Controller controller, string message, FlashMessageType messageType = FlashMessageType.Info) { //jika tidak sesuai dengan yang ada, maka defaultnya adalah tipe pertama messageType = !System.Enum.IsDefined(typeof(FlashMessageType), messageType) ? FlashMessageType.Info : messageType; string type = messageType.ToString().ToLower(); controller.TempData[FLASH_MESSAGE + type] = message; }
/// <summary> /// Add additional flash message. Call this function after <see cref="SetFlash(Controller,string,FlashMessageType)"/> /// </summary> /// <param name="controller">Extension hook ke controller</param> /// <param name="message">message content</param> /// <param name="messageType">flash message type</param> public static void AppendFlash(this Controller controller, string message, FlashMessageType messageType) { if (!System.Enum.IsDefined(typeof(FlashMessageType), messageType)) { string[] types = System.Enum.GetNames(typeof(FlashMessageType)); throw new OpenLibraryException("Message cannot be empty when using this method: " + string.Join(", ", types), OpenLibraryErrorType.ArgumentNotValidError); } string type = messageType.ToString().ToLower(); string lastMessage = !string.IsNullOrEmpty(controller.TempData[FLASH_MESSAGE + type].ToString()) ? controller.TempData[FLASH_MESSAGE + type].ToString() : string.Empty; lastMessage += message; controller.TempData[FLASH_MESSAGE + type] = lastMessage; }
public string this[FlashMessageType type] { get { return(this[type.ToString()]); } set { this[type.ToString()] = value; } }
public static void SetMessage(this Controller controller, FlashMessageType messageType, string message) { controller.TempData[messageType.ToString()] = message; }
public static bool HasMessage(TempDataDictionary tempData, FlashMessageType messageType) { var result = tempData[messageType.ToString()]; return result != null ? result.ToString().Length > 0 : false; }
public static string GetMessage(TempDataDictionary tempData, FlashMessageType messageType) { return tempData[messageType.ToString()].ToString(); }
/// <summary> /// Generate one time show only message (even redirected). /// This flash message compatible with Twitter Bootstrap alert. /// Get html generated directly. /// </summary> /// <param name="controller">Extension ke controller</param> /// <param name="message">message content</param> /// <param name="messageType">flash message type</param> public static string Flash(this Controller controller, string message, FlashMessageType messageType = FlashMessageType.Info) { return(RenderFlashMessage(message, messageType.ToString().ToLower())); }
public static bool HasMessage(TempDataDictionary tempData, FlashMessageType messageType) { var result = tempData[messageType.ToString()]; return(result != null?result.ToString().Length > 0 : false); }
public static string GetMessage(TempDataDictionary tempData, FlashMessageType messageType) { return(tempData[messageType.ToString()].ToString()); }