/// <summary> /// Sets the temporary data message and state /// </summary> /// <param name="tempData">Temporary data dictionary to use</param> /// <param name="state">State to set</param> /// <param name="message">Message to set</param> public static void SetTemporaryMessage(ITempDataDictionary tempData, MessageState state, string message) { if (tempData == null) { throw new ArgumentNullException(nameof(tempData)); } if (tempData.ContainsKey("MessageState")) { tempData["MessageState"] = state; } else { tempData.Add("MessageState", state); } if (tempData.ContainsKey("Message")) { tempData["Message"] = message; } else { tempData.Add("Message", message); } }
public static Cart FILLTEMPDATA(WebshopDbContext context, string user, ITempDataDictionary TempData, bool filltemp) { Cart cart = context.Carts.Include(x => x.Items).ThenInclude(x => x.Product).FirstOrDefault(x => x.Buyer == user); if (cart == null) { cart = new Cart(); cart.Buyer = user; context.Carts.Add(cart); } if (filltemp) { int price = cart.Items.Sum(x => x.Count * x.Product.Price); int count = cart.Items.Sum(x => x.Count); if (TempData.ContainsKey("Count")) { TempData["Count"] = count; TempData["CartPrice"] = price; } else { TempData.Add("Count", count); TempData.Add("CartPrice", price); } } return(cart); }
protected void CreateNotification(NotificationHelpers.AlertType type, ITempDataDictionary tempData, string message, string title = "") { var toast = new NotificationHelpers.Alert { Type = type, Message = message, Title = title }; var alerts = new List <NotificationHelpers.Alert>(); if (tempData.ContainsKey(NotificationHelpers.NotificationKey)) { alerts = JsonConvert.DeserializeObject <List <NotificationHelpers.Alert> >(tempData[NotificationHelpers.NotificationKey].ToString()); tempData.Remove(NotificationHelpers.NotificationKey); } alerts.Add(toast); var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; var alertJson = JsonConvert.SerializeObject(alerts, settings); tempData.Add(NotificationHelpers.NotificationKey, alertJson); }
private static void AddMessage(ITempDataDictionary data, string type, string message) { if (!data.ContainsKey(NotificationData)) { data.Add(NotificationData, $"{type}|{message}"); } }
public static void Set <T>(this ITempDataDictionary tempData, string key, T value) { tempData.Remove(key); string json = JsonConvert.SerializeObject(value); tempData.Add(key, json); }
public void ShowBanner(Banner banner) { var bannerContents = JsonSerializer.Serialize(banner); _tempData.Remove(BannerKey); _tempData.Add(BannerKey, bannerContents); }
// ModelStateを追加 public static void AddModelState(this ITempDataDictionary tempData, ModelStateDictionary modelState) { // TempDataがシリアライズできるのは単純データのみ // JSON文字列をTempDataに格納する var json = ModelStateDictionaryJsonSerializer.Serialize(modelState); tempData.Add(_modelStateKey, json); }
public static void AddOrUpdate(this ITempDataDictionary tempData, string key, string value) { if (tempData.Keys.Contains(key)) { tempData.Remove(key); } tempData.Add(key, value); }
private void Message(Enumerations.Enumerations.AjaxFlashMessageType type, string message) { if (_tempData.ContainsKey(Key)) { _tempData.Remove(Key); } _tempData.Add(Key, string.Format(AlertTemplate, type.ToString().ToLower(), message)); }
public static void SetSuccessMessage(this ITempDataDictionary tempData, string message) { tempData.Remove(AlertCss.Success); if (string.IsNullOrEmpty(message)) { return; } tempData.Add(AlertCss.Success, message); }
// Adds a new alert to the temp data dictionary public static void AddAlert(this ITempDataDictionary tempData, string key, Alert alert) { var alerts = tempData.GetAlerts(key); alerts.Add(alert); tempData.Remove(key); tempData.Add(key, JsonSerializer.Serialize(alerts)); }
/// <summary> /// Creates error message which is sent with redirect /// </summary> /// <param name="tempData"></param> /// <param name="message"></param> public static void AddErrorMessage(this ITempDataDictionary tempData, string message) { if (tempData.ContainsKey("ErrorMessage")) { tempData["ErrorMessage"] = message; } else { tempData.Add("ErrorMessage", message); } }
public static void AddMessage(this ITempDataDictionary tempData, string format, params object[] args) { List <Message> messages = GetMessages(tempData); messages.Add(new Message { Text = string.Format(format, args) }); tempData.Add(Static.KeyMessages, JsonConvert.SerializeObject(messages)); }
// TODO [GM]: Maybe support collections? public static void AddSerialized <T>(this ITempDataDictionary dictionary, string key, T item) { var serializedObject = JObject.FromObject(item); serializedObject["Type"] = item.GetType().FullName; if (dictionary.ContainsKey(key)) { dictionary.Remove(key); } dictionary.Add(key, serializedObject.ToString()); }
public static void AddResult(this ITempDataDictionary tempData, Utility.ServiceResult result) { tempData.Add("Success", result.Success); tempData.Add("Message", result.Message); }
public static void AddResult(this ITempDataDictionary tempData, ServiceResult result) { tempData.Clear(); tempData.Add("result.Messages", result.Message); tempData.Add("result.Succeed", result.Succeed); }
public static void Set <T>(this ITempDataDictionary tempData, string key, AlertModel obj) { string jsonData = JsonConvert.SerializeObject(obj); tempData.Add(key, jsonData); }
// ModelStateを追加 public static void AddModelState(this ITempDataDictionary tempData, ModelStateDictionary modelState) { var json = JsonConvertHelper.SerializeModelState(modelState); tempData.Add(_modelStateKey, json); }
public static void SetErrorMessage(this ITempDataDictionary tempData, Exception exception) { tempData.Remove(AlertCss.Error); tempData.Add(AlertCss.Error, exception.Message); }
public static void SetErrorMessage(this ITempDataDictionary tempData, string message) { tempData.Remove(AlertCss.Error); tempData.Add(AlertCss.Error, message); }
public static void Add(this ITempDataDictionary data, string key, string value) { data.Add(key, value); }