/// <summary> /// Called when the repository content is changed /// </summary> protected void RaiseItemsChanged(object sender, RepositoryChangeEventArgs <TModel> args) { ItemsChanged?.Invoke(this, args); }
/// <summary> /// Updates the collection base on the operation type /// </summary> /// <typeparam name="T"></typeparam> public static void Update <T>(this IList <T> collection, object sender, RepositoryChangeEventArgs <T> args) { collection.Update(args); }
/// <summary> /// Updates the collection base on the operation type /// </summary> /// <typeparam name="T"></typeparam> public static void Update <T>(this IList <T> collection, RepositoryChangeEventArgs <T> args) { collection.Update(args.OperationType, args.Item); }
private static void UpdateCollectionOnRepositoryChange <T, TKey, TTarget>(IList <TTarget> collection, ItemLocator <T, TTarget> locator, RepositoryChangeEventArgs <T> e, TTarget target) where T : IUniqueObject <TKey> { if (e.OperationType == OperationType.Add) { collection.Add(target); } else { var original = locator(e.Item); if (e.OperationType == OperationType.Edit) { collection.Update(target, p => p.Equals(original)); } else if (e.OperationType == OperationType.Delete) { collection.Remove(original); } } }