public IErrorInfo ToErrorInfo() => new ErrorInfo { InstanceID = UniqueID, ErrorType = ErrorType, FixType = ToFixType(), Message = MessageType.GetDescription(), FixData = MessagePayload, };
/// <summary> /// This function return the script string of a popup box with just Ok Button /// To use this function, the return value of this must be placed in TempData["Script"] /// in order to insert into ViewData.Script and send it to the view to show. /// </summary> /// <param name="msg">message to show</param> /// <param name="type">Type of popup, message will not show any icon</param> /// <param name="title">title for Popup box</param> /// <param name="okText">you can set it Globally via OkText Property of Notifications Class (default: OK)</param> /// <param name="callbacks">Used when you need a confirm dialog box, you sould write a java script function name or call for every callback you want</param> /// <param name="closeOnConfirm">optional, close when Confirm button clicked or not.</param> /// <param name="addOnDocumentReady">optional,set true to add jquery Document ready to script</param> /// <returns>script string</returns> public static string ShowPopup(string msg, MessageType type, string title, string okText, SweetCallBack callbacks, bool addOnDocumentReady = false, bool addScript = true) { //Swal.fire({ // title: 'Are you sure?', // text: "You won't be able to revert this!", // type: 'warning', // showCancelButton: true, // confirmButtonText: 'Yes, delete it!', // cancelButtonText: 'No, cancel!', // reverseButtons: true //}).then((result) => { // if (result.value) { // Swal.fire( // 'Deleted!', // 'Your file has been deleted.', // 'success' // ) // } else if ( // // Read more about handling dismissals // result.dismiss === Swal.DismissReason.cancel // ) { // Swal.fire( // 'Cancelled', // 'Your imaginary file is safe :)', // 'error' // ) // } //}) var str = new StringBuilder(); if (addScript) { str.Append("<script>"); } if (addOnDocumentReady) { str.Append("$(function() {"); } var typeStr = "null"; // add Type parameter if (type != MessageType.Message) { typeStr = type.GetDescription(); } else { typeStr = "info"; } var buttonColor = "btn-success"; if (type == MessageType.Error) { buttonColor = "btn-danger"; } else if (type == MessageType.Warning) { buttonColor = "btn-warning"; } else if (type == MessageType.Info) { buttonColor = "btn-info"; } else if (type == MessageType.Success) { buttonColor = "btn-success"; } else { buttonColor = "btn-primary"; } title = System.Net.WebUtility.HtmlEncode(title); msg = System.Net.WebUtility.HtmlEncode(msg); var scriptStr = $@"Swal.fire({{ title : '{title}', text : `{msg}`, type : '{typeStr}', showCancelButton : false, confirmButtonClass : '{buttonColor}', confirmButtonText : '{(string.IsNullOrEmpty(okText) ? OkText : okText)}', allowEscapeKey : false, allowOutsideClick: false }})"; if (callbacks != null) { scriptStr += $@".then((result) => {{ if (result.value) {{ {callbacks.Confirm} }} "; if (callbacks.Cancel != null) { scriptStr += $@"else if ( // Read more about handling dismissals result.dismiss === Swal.DismissReason.cancel ) {{ {callbacks.Cancel} }}"; } scriptStr += $"}} )"; } scriptStr += ";"; str.Append(scriptStr); if (addOnDocumentReady) { str.Append("});"); } if (addScript) { str.Append("</script>"); } return(str.ToString()); }
/// <summary> /// This function generates an script string to show a message growl /// </summary> /// <param name="msg">Content of the message</param> /// <param name="type">Type of the message, can be one of {success, warning, info, danger}</param> /// <param name="title">Header message</param> /// <param name="position">The position for Toastr</param> /// <param name="addOnDocumentReady">set true to add jquery Document ready to script</param> /// <returns>string contains script needed to show a message growl</returns> public static string ShowToast(string title, string msg, MessageType type, ToastrPosition position = ToastrPosition.BottomRight, bool addOnDocumentReady = false, bool addScript = true) { // ShowToast(title, msg, position, type) var str = new StringBuilder(); if (addScript) { str.Append("<script>"); } if (addOnDocumentReady) { str.Append("$(function() {"); } if (type == MessageType.Message || type == MessageType.Question) { type = MessageType.Info; } str.Append($"ShowToast('{title}', `{msg}`, '{position.GetDescription()}', '{type.GetDescription()}');"); if (addOnDocumentReady) { str.Append("});"); } if (addScript) { str.Append("</script>"); } return(str.ToString()); }
/// <summary> /// This function return the script string of a popup box /// To use this function, the return value of this must be placed in TempData["Script"] /// in order to insert into ViewData.Script and send it to the view to show. /// </summary> /// <param name="msg">message to show</param> /// <param name="type">Type of popup, message will not show any icon</param> /// <param name="title">title for Popup box</param> /// <param name="okText">you can set it Globally via OkText Property of Notifications Class (default: OK)</param> /// <param name="cancelText">you can set it Globally via OkText Property of Notifications Class (default: Cancel)</param> /// <param name="imageUrl">Adds a custom image in place of icon</param> /// <param name="callbacks">Used when you need a confirm dialog box, you sould write a java script function name or call for every callback you want</param> /// <param name="showLoaderOnConfirm">optional, shows Loader if user clicked confirm button, used when you run an ajax request in confirm callback.</param> /// <param name="addOnDocumentReady">optional,set true to add jquery Document ready to script</param> /// <returns>script string</returns> public static string ShowPopup(string msg, MessageType type, string title, string okText, string cancelText, string imageUrl, SweetCallBack callbacks, bool showLoaderOnConfirm = false, bool addOnDocumentReady = false, bool addScript = true) { //ShowSweetPopup(title, msg, type, buttons, callbacks, imageUrl, showLoaderOnConfirm) var str = new StringBuilder(); if (addScript) { str.Append("<script>"); } if (addOnDocumentReady) { str.Append("$(function() {"); } title = System.Net.WebUtility.HtmlEncode(title); msg = System.Net.WebUtility.HtmlEncode(msg); str.Append($"ShowSweetPopup('{title}',`{msg}`"); // add Type parameter if (type != MessageType.Message) { str.Append($",'{type.GetDescription()}'"); } else { str.Append($", 'info'"); } // Add buttons parameter var oktext = string.IsNullOrEmpty(okText) ? OkText : okText; var canceltext = string.IsNullOrEmpty(cancelText) ? CancelText : cancelText; str.Append($", {{okText : '{oktext}', cancelText: '{canceltext}'}}"); // Add Callbacks if (callbacks != null) { str.Append($", {{confirm: {AddFunctionPhrase(callbacks.Confirm)}"); if (callbacks.Cancel != null) { str.Append($", cancel: {AddFunctionPhrase(callbacks.Cancel)}"); } str.Append($"}}"); } else { str.Append($", undefined"); } // Add ImageUrl str.Append($", '{imageUrl}'"); // Add showLoaderOnConfirm str.Append($", {showLoaderOnConfirm.ToString().ToLower()}"); str.Append(");"); if (addOnDocumentReady) { str.Append("});"); } if (addScript) { str.Append("</script>"); } return(str.ToString()); }