/// <summary> /// Set an item into recent history storage. /// </summary> /// <param name="historyType">The type of history.</param> /// <param name="values">The values necessary for loading the object as a dictionary of key value pairs.</param> /// <param name="displayName">The object's display name.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="values"/> is <c>null</c> or empty.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="displayName"/> is <c>null</c> or empty.</exception> public void Set(HistoryType historyType, IDictionary <string, object> values, string displayName) { if (values == null || !values.Any()) { throw new ArgumentNullException("values"); } if (string.IsNullOrEmpty(displayName)) { throw new ArgumentNullException("displayName"); } var key = new KeyModel("History").Add(historyType); values.ForEach(v => key.Add(v.Key.ToLower()).Add(v.Value)); var model = new HistoryModel { HistoryType = historyType, Values = values, DisplayName = displayName, DateAccessed = UserService.DateTime, IsPinned = false, Username = UserService.Username }; UserService.Session.Set(key, model); }
/// <summary> /// Removes the specified recent history item. /// </summary> /// <param name="historyType">The history type.</param> /// <param name="values">The values necessary for loading the object as a dictionary of key value pairs.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="values"/> is <c>null</c> or empty.</exception> public void Remove(HistoryType historyType, IDictionary <string, object> values) { if (values == null || !values.Any()) { throw new ArgumentNullException("values"); } var key = new KeyModel("History").Add(historyType); values.ForEach(v => key.Add(v.Key.ToLower()).Add(v.Value)); UserService.Session.Remove(key); }
/// <summary> /// Gets the recent history item for a specified history type and object ID /// </summary> /// <param name="historyType">The history type.</param> /// <param name="values">The values necessary for loading the object as a dictionary of key value pairs.</param> /// <returns>Returns <see cref="IEnumerable{HistoryModel}"/> for a single matching recent history record. If no matching record found returns null.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="values"/> is <c>null</c> or empty.</exception> public HistoryModel Get(HistoryType historyType, IDictionary <string, object> values) { if (values == null || !values.Any()) { throw new ArgumentNullException("values"); } var key = new KeyModel("History").Add(historyType); values.ForEach(v => key.Add(v.Key.ToLower()).Add(v.Value)); HistoryModel model; return((UserService.Session.TryGet(key, out model)) ? model : null); }
public void ClearTest() { const string key = "Key"; IList <object> values = new List <object>(); var target = new KeyModel(key); Assert.IsNotNull(target); string value = "Value"; KeyModel actual = target.Add(value); Assert.IsNotNull(actual); Assert.IsTrue(actual.Values.Any()); target.Clear(); Assert.IsFalse(target.Values.Any()); }
public void AddTest() { const string key = "Key"; IList <object> values = new List <object>(); var target = new KeyModel(key); Assert.IsNotNull(target); string value = "Value"; KeyModel actual = target.Add(value); Assert.AreEqual(key, actual.Key); Assert.IsNotNull(actual.Values); var s = (string)actual.Values[0]; Assert.AreEqual(value, s); }
/// <summary> /// Unpins the specified recent history record. /// </summary> /// <param name="historyType">The history type.</param> /// <param name="values">The values necessary for loading the object as a dictionary of key value pairs.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="values" /> is <c>null</c> or empty.</exception> public void Unpin(HistoryType historyType, IDictionary <string, object> values) { if (values == null || !values.Any()) { throw new ArgumentNullException("values"); } var key = new KeyModel("History").Add(historyType); values.ForEach(v => key.Add(v.Key.ToLower()).Add(v.Value)); HistoryModel model; if (UserService.Session.TryGet(key, out model)) { model.IsPinned = false; UserService.Session.Set(key, model); } }