public static void ProcessChanges <T>(DbChangeStatus status, T arg, ObservableCollection <T> collection, TaskFactory sync) { Logger.Log.Info($"Изменения в объекте: {{object: {typeof(T)}, status: {status}}}"); switch (status) { case DbChangeStatus.Add: case DbChangeStatus.Update: int index = collection.IndexOf(arg); if (index > -1) { sync.StartNew(() => { collection.RemoveAt(index); collection.Insert(index, arg); }); } else { sync.StartNew(() => collection.Add(arg)); } break; case DbChangeStatus.Remove: if (collection.Contains(arg)) { sync.StartNew(() => collection.Remove(arg)); } break; default: Logger.Log.Warn($"Необработанное событие изменения: {{type: {typeof(T)}, status: {status}}}"); break; } }
void ProcessChanges <T>(DbChangeStatus status, T arg, ObservableCollection <T> collection) { ProcessChangesHelper.ProcessChanges(status, arg, collection, sync); if (status == DbChangeStatus.Remove && arg is Staff staff) { Clear(Groups, x => x.CuratorId == staff.Id); } }
private void Groups_OnChanged(DbChangeStatus status, Group group) { if (status != DbChangeStatus.Remove) { return; } if (selectedGroup.Id == group.Id) { sync.StartNew(() => GoBack()); } }
private void Students_OnChanged(DbChangeStatus status, Student student) { int index = Items.IndexOf(student); if (index > -1 && student.GroupId != Items[index].GroupId) { sync.StartNew(() => Items.Remove(student)); } if (student.GroupId != selectedGroup.Id) { return; } ProcessChangesHelper.ProcessChanges(status, student, Items, sync); }
private void Users_OnChanged(DbChangeStatus status, User arg) { ProcessChanges(status, arg, Users); }
private void Staff_OnChanged(DbChangeStatus status, Staff arg) { ProcessChanges(status, arg, Staff); }
private void Groups_OnChanged(DbChangeStatus status, Group arg) { ProcessChanges(status, arg, Groups); }