public async Task InvokeAsync(HttpContext context) { ITempDataDictionaryFactory factory = context.RequestServices.GetService(typeof(ITempDataDictionaryFactory)) as ITempDataDictionaryFactory; TempDataDictionary TempData = factory.GetTempData(context) as TempDataDictionary; if (TempData != null && TempData.Remove(Action + "_Errors" + "_old") == true) { TempData.Remove(Action + "_Errors"); } await Next.Invoke(context); }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1" /> that can be used to iterate through the collection. /// </returns> public IEnumerator <FlashMessage> GetEnumerator() { try { return(_messageList.GetEnumerator()); } finally { _tempData.Remove(typeof(MessageManager).FullName); } }
public static void SigningEmailAddress(this TempDataDictionary tempData, string emailAddress) { if (tempData == null) { return; } if (string.IsNullOrWhiteSpace(emailAddress)) { tempData.Remove(SigningEmailAddressKey); } else { tempData[SigningEmailAddressKey] = emailAddress; } }
public static void EmailConfirmationTicket(this TempDataDictionary tempData, string ticket) { if (tempData == null) { return; } if (string.IsNullOrWhiteSpace(ticket)) { tempData.Remove(EmailConfirmationTicketKey); } else { tempData[EmailConfirmationTicketKey] = ticket; } }
public static string SigningEmailAddress(this TempDataDictionary tempData, bool keep = true) { if (tempData == null || !tempData.ContainsKey(SigningEmailAddressKey)) { return(null); } var value = tempData[SigningEmailAddressKey]; if (keep) { tempData.Keep(SigningEmailAddressKey); } else { tempData.Remove(SigningEmailAddressKey); } return(value != null?value.ToString() : null); }
/// <summary> /// Перед выполнением действия внедряем сохраненные параметры. /// </summary> public override void OnActionExecuting(ActionExecutingContext filter_context) { base.OnActionExecuting(filter_context); ModelStateKey = ModelStateKeyPrefix + filter_context.ActionDescriptor.ActionName + filter_context.ActionDescriptor.ControllerDescriptor.ControllerName; if (ParametersHook) { // Формируем ключи для доступа к данных... PRGParametersKey = PRGParametersKeyPrefix + filter_context.ActionDescriptor.ActionName + filter_context.ActionDescriptor.ControllerDescriptor.ControllerName; TempDataDictionary temp_data = filter_context.Controller.TempData; // если в хранилище есть данные... if (temp_data.ContainsKey(PRGParametersKey) && temp_data[PRGParametersKey] != null) { // забираем данные как тип... var prg_parameters = temp_data[PRGParametersKey] as IList <PRGParameter>; // если данные нужного типа... if (prg_parameters != null) { // берем список параметров метода... ParameterDescriptor[] parameter_descriptors = filter_context.ActionDescriptor.GetParameters(); // перебираем их... foreach (ParameterDescriptor parameter_descriptor in parameter_descriptors) { PRGParameter prg_parameter = prg_parameters.Where(p => p.Name == parameter_descriptor.ParameterName).FirstOrDefault(); if (prg_parameter != null) { filter_context.ActionParameters[parameter_descriptor.ParameterName] = prg_parameter.Value; } } } } temp_data.Remove(PRGParametersKey); } }
public void TempDataIsADictionary() { // Arrange TempDataDictionary tempData = new TempDataDictionary(); // Act tempData["Key1"] = "Value1"; tempData.Add("Key2", "Value2"); ((ICollection<KeyValuePair<string, object>>)tempData).Add(new KeyValuePair<string,object>("Key3", "Value3")); // Assert (IDictionary) Assert.AreEqual(3, tempData.Count, "tempData should contain 3 items"); Assert.IsTrue(tempData.Remove("Key1"), "The key should be present"); Assert.IsFalse(tempData.Remove("Key4"), "The key should not be present"); Assert.IsTrue(tempData.ContainsValue("Value2"), "The value should be present"); Assert.IsFalse(tempData.ContainsValue("Value1"), "The value should not be present"); Assert.IsNull(tempData["Key6"], "The key should not be present"); IEnumerator tempDataEnumerator = tempData.GetEnumerator(); tempDataEnumerator.Reset(); while (tempDataEnumerator.MoveNext()) { KeyValuePair<string, object> pair = (KeyValuePair<string, object>)tempDataEnumerator.Current; Assert.IsTrue(((ICollection<KeyValuePair<string, object>>)tempData).Contains(pair), "The key/value pair should be present"); } // Assert (ICollection) foreach (string key in tempData.Keys) { Assert.IsTrue(((ICollection<KeyValuePair<string, object>>)tempData).Contains(new KeyValuePair<string, object>(key, tempData[key])), "The key/value pair should be present"); } foreach (string value in tempData.Values) { Assert.IsTrue(tempData.ContainsValue(value)); } foreach (string key in ((IDictionary<string, object>)tempData).Keys) { Assert.IsTrue(tempData.ContainsKey(key), "The key should be present"); } foreach (string value in ((IDictionary<string, object>)tempData).Values) { Assert.IsTrue(tempData.ContainsValue(value)); } KeyValuePair<string, object>[] keyValuePairArray = new KeyValuePair<string, object>[tempData.Count]; ((ICollection<KeyValuePair<string, object>>)tempData).CopyTo(keyValuePairArray, 0); Assert.IsFalse(((ICollection<KeyValuePair<string, object>>)tempData).IsReadOnly, "The dictionary should not be read-only."); Assert.IsFalse(((ICollection<KeyValuePair<string, object>>)tempData).Remove(new KeyValuePair<string, object>("Key5", "Value5")), "The key/value pair should not be present"); IEnumerator<KeyValuePair<string, object>> keyValuePairEnumerator = ((ICollection<KeyValuePair<string, object>>)tempData).GetEnumerator(); keyValuePairEnumerator.Reset(); while (keyValuePairEnumerator.MoveNext()) { KeyValuePair<string, object> pair = keyValuePairEnumerator.Current; Assert.IsTrue(((ICollection<KeyValuePair<string, object>>)tempData).Contains(pair), "The key/value pair should be present"); } // Act tempData.Clear(); // Assert Assert.AreEqual(0, tempData.Count, "tempData should not contain any items"); IEnumerator y = ((IEnumerable)tempData).GetEnumerator(); while (y.MoveNext()) { Assert.Fail("There should not be any elements in tempData"); } }
private static void RemoveMessage(string index, TempDataDictionary tempData) { tempData.Remove(index); }
public void TempDataIsADictionary() { // Arrange TempDataDictionary tempData = new TempDataDictionary(); // Act tempData["Key1"] = "Value1"; tempData.Add("Key2", "Value2"); ((ICollection <KeyValuePair <string, object> >)tempData).Add(new KeyValuePair <string, object>("Key3", "Value3")); // Assert (IDictionary) Assert.Equal(3, tempData.Count); Assert.True(tempData.Remove("Key1")); Assert.False(tempData.Remove("Key4")); Assert.True(tempData.ContainsValue("Value2")); Assert.False(tempData.ContainsValue("Value1")); Assert.Null(tempData["Key6"]); IEnumerator tempDataEnumerator = tempData.GetEnumerator(); tempDataEnumerator.Reset(); while (tempDataEnumerator.MoveNext()) { KeyValuePair <string, object> pair = (KeyValuePair <string, object>)tempDataEnumerator.Current; Assert.True(((ICollection <KeyValuePair <string, object> >)tempData).Contains(pair)); } // Assert (ICollection) foreach (string key in tempData.Keys) { Assert.True(((ICollection <KeyValuePair <string, object> >)tempData).Contains(new KeyValuePair <string, object>(key, tempData[key]))); } foreach (string value in tempData.Values) { Assert.True(tempData.ContainsValue(value)); } foreach (string key in ((IDictionary <string, object>)tempData).Keys) { Assert.True(tempData.ContainsKey(key)); } foreach (string value in ((IDictionary <string, object>)tempData).Values) { Assert.True(tempData.ContainsValue(value)); } KeyValuePair <string, object>[] keyValuePairArray = new KeyValuePair <string, object> [tempData.Count]; ((ICollection <KeyValuePair <string, object> >)tempData).CopyTo(keyValuePairArray, 0); Assert.False(((ICollection <KeyValuePair <string, object> >)tempData).IsReadOnly); Assert.False(((ICollection <KeyValuePair <string, object> >)tempData).Remove(new KeyValuePair <string, object>("Key5", "Value5"))); IEnumerator <KeyValuePair <string, object> > keyValuePairEnumerator = ((ICollection <KeyValuePair <string, object> >)tempData).GetEnumerator(); keyValuePairEnumerator.Reset(); while (keyValuePairEnumerator.MoveNext()) { KeyValuePair <string, object> pair = keyValuePairEnumerator.Current; Assert.True(((ICollection <KeyValuePair <string, object> >)tempData).Contains(pair)); } // Act tempData.Clear(); // Assert Assert.Empty(tempData); }
public void TempDataIsADictionary() { // Arrange TempDataDictionary tempData = new TempDataDictionary(); // Act tempData["Key1"] = "Value1"; tempData.Add("Key2", "Value2"); ((ICollection<KeyValuePair<string, object>>)tempData).Add(new KeyValuePair<string, object>("Key3", "Value3")); // Assert (IDictionary) Assert.Equal(3, tempData.Count); Assert.True(tempData.Remove("Key1")); Assert.False(tempData.Remove("Key4")); Assert.True(tempData.ContainsValue("Value2")); Assert.False(tempData.ContainsValue("Value1")); Assert.Null(tempData["Key6"]); IEnumerator tempDataEnumerator = tempData.GetEnumerator(); tempDataEnumerator.Reset(); while (tempDataEnumerator.MoveNext()) { KeyValuePair<string, object> pair = (KeyValuePair<string, object>)tempDataEnumerator.Current; Assert.True(((ICollection<KeyValuePair<string, object>>)tempData).Contains(pair)); } // Assert (ICollection) foreach (string key in tempData.Keys) { Assert.True(((ICollection<KeyValuePair<string, object>>)tempData).Contains(new KeyValuePair<string, object>(key, tempData[key]))); } foreach (string value in tempData.Values) { Assert.True(tempData.ContainsValue(value)); } foreach (string key in ((IDictionary<string, object>)tempData).Keys) { Assert.True(tempData.ContainsKey(key)); } foreach (string value in ((IDictionary<string, object>)tempData).Values) { Assert.True(tempData.ContainsValue(value)); } KeyValuePair<string, object>[] keyValuePairArray = new KeyValuePair<string, object>[tempData.Count]; ((ICollection<KeyValuePair<string, object>>)tempData).CopyTo(keyValuePairArray, 0); Assert.False(((ICollection<KeyValuePair<string, object>>)tempData).IsReadOnly); Assert.False(((ICollection<KeyValuePair<string, object>>)tempData).Remove(new KeyValuePair<string, object>("Key5", "Value5"))); IEnumerator<KeyValuePair<string, object>> keyValuePairEnumerator = ((ICollection<KeyValuePair<string, object>>)tempData).GetEnumerator(); keyValuePairEnumerator.Reset(); while (keyValuePairEnumerator.MoveNext()) { KeyValuePair<string, object> pair = keyValuePairEnumerator.Current; Assert.True(((ICollection<KeyValuePair<string, object>>)tempData).Contains(pair)); } // Act tempData.Clear(); // Assert Assert.Empty(tempData); }
public static void RemovePreferencePointModel(this TempDataDictionary tempData, int personId) { tempData.Remove(PrefPointKey + personId); }
public static void RemoveAhpModel(this TempDataDictionary tempData, int personId) { tempData.Remove(AhpKey + personId); }
public static void ClearGroupDietsResultViewModel(this TempDataDictionary tempData) { tempData.Remove(GroupDietsResultViewModeltKey); }
public void TempDataIsADictionary() { // Arrange TempDataDictionary tempData = new TempDataDictionary(); // Act tempData["Key1"] = "Value1"; tempData.Add("Key2", "Value2"); ((ICollection <KeyValuePair <string, object> >)tempData).Add(new KeyValuePair <string, object>("Key3", "Value3")); // Assert (IDictionary) Assert.AreEqual(3, tempData.Count, "tempData should contain 3 items"); Assert.IsTrue(tempData.Remove("Key1"), "The key should be present"); Assert.IsFalse(tempData.Remove("Key4"), "The key should not be present"); Assert.IsTrue(tempData.ContainsValue("Value2"), "The value should be present"); Assert.IsFalse(tempData.ContainsValue("Value1"), "The value should not be present"); Assert.IsNull(tempData["Key6"], "The key should not be present"); IEnumerator tempDataEnumerator = tempData.GetEnumerator(); tempDataEnumerator.Reset(); while (tempDataEnumerator.MoveNext()) { KeyValuePair <string, object> pair = (KeyValuePair <string, object>)tempDataEnumerator.Current; Assert.IsTrue(((ICollection <KeyValuePair <string, object> >)tempData).Contains(pair), "The key/value pair should be present"); } // Assert (ICollection) foreach (string key in tempData.Keys) { Assert.IsTrue(((ICollection <KeyValuePair <string, object> >)tempData).Contains(new KeyValuePair <string, object>(key, tempData[key])), "The key/value pair should be present"); } foreach (string value in tempData.Values) { Assert.IsTrue(tempData.ContainsValue(value)); } foreach (string key in ((IDictionary <string, object>)tempData).Keys) { Assert.IsTrue(tempData.ContainsKey(key), "The key should be present"); } foreach (string value in ((IDictionary <string, object>)tempData).Values) { Assert.IsTrue(tempData.ContainsValue(value)); } KeyValuePair <string, object>[] keyValuePairArray = new KeyValuePair <string, object> [tempData.Count]; ((ICollection <KeyValuePair <string, object> >)tempData).CopyTo(keyValuePairArray, 0); Assert.IsFalse(((ICollection <KeyValuePair <string, object> >)tempData).IsReadOnly, "The dictionary should not be read-only."); Assert.IsFalse(((ICollection <KeyValuePair <string, object> >)tempData).Remove(new KeyValuePair <string, object>("Key5", "Value5")), "The key/value pair should not be present"); IEnumerator <KeyValuePair <string, object> > keyValuePairEnumerator = ((ICollection <KeyValuePair <string, object> >)tempData).GetEnumerator(); keyValuePairEnumerator.Reset(); while (keyValuePairEnumerator.MoveNext()) { KeyValuePair <string, object> pair = keyValuePairEnumerator.Current; Assert.IsTrue(((ICollection <KeyValuePair <string, object> >)tempData).Contains(pair), "The key/value pair should be present"); } // Act tempData.Clear(); // Assert Assert.AreEqual(0, tempData.Count, "tempData should not contain any items"); IEnumerator y = ((IEnumerable)tempData).GetEnumerator(); while (y.MoveNext()) { Assert.Fail("There should not be any elements in tempData"); } }
public void Excluir(string key) { _tempData.Remove(key); }
public static void ResetFlash(this TempDataDictionary data) { data.Remove("FlashMessage"); }