private void ProjectSettings_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { ProjectSetting editedEntity = new ProjectSetting(); switch (e.Action) { case NotifyCollectionChangedAction.Add: { int newIndex = e.NewStartingIndex; editedEntity = ProjectSettingCollection[newIndex]; if (ProjectSettings.Add(editedEntity)) { EditedEntity = new EditedEntity(EditAction.Add, editedEntity); } } break; case NotifyCollectionChangedAction.Remove: { List <ProjectSetting> tempListOfRemovedItems = e.OldItems.OfType <ProjectSetting>().ToList(); editedEntity = tempListOfRemovedItems[0]; if (ProjectSettings.Delete(editedEntity.ProjectID)) { EditedEntity = new EditedEntity(EditAction.Delete, editedEntity); } } break; case NotifyCollectionChangedAction.Replace: { List <ProjectSetting> tempListOfProjectSettings = e.NewItems.OfType <ProjectSetting>().ToList(); editedEntity = tempListOfProjectSettings[0]; if (ProjectSettings.Update(tempListOfProjectSettings[0])) // As the IDs are unique, only one row will be effected hence first index only { EditedEntity = new EditedEntity(EditAction.Update, editedEntity); } } break; } EntityChangedEventArgs args = new EntityChangedEventArgs(editedEntity.GetType().Name, editedEntity); EntityChanged?.Invoke(this, args); }
private void SamplingCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: { int newIndex = e.NewStartingIndex; Sampling editedEntity = SamplingCollection[newIndex]; if (Samplings.Add(editedEntity)) { EditedEntity = new EditedEntity(EditAction.Add, editedEntity); } } break; case NotifyCollectionChangedAction.Remove: { List <Sampling> tempListOfRemovedItems = e.OldItems.OfType <Sampling>().ToList(); Sampling editedEntity = tempListOfRemovedItems[0]; if (Samplings.Delete(editedEntity.RowID)) { EditedEntity = new EditedEntity(EditAction.Delete, editedEntity); } } break; case NotifyCollectionChangedAction.Replace: { List <Sampling> tempListOfSamplings = e.NewItems.OfType <Sampling>().ToList(); Sampling editedEntity = tempListOfSamplings[0]; if (Samplings.Update(editedEntity)) // As the IDs are unique, only one row will be effected hence first index only { EditedEntity = new EditedEntity(EditAction.Update, editedEntity); } } break; } }