private void LandingSiteCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { LandingSite editedLandingSite = new LandingSite(); switch (e.Action) { case NotifyCollectionChangedAction.Add: { int newIndex = e.NewStartingIndex; editedLandingSite = LandingSiteCollection[newIndex]; LandingSites.Add(editedLandingSite); } break; case NotifyCollectionChangedAction.Remove: { List <LandingSite> tempListOfRemovedItems = e.OldItems.OfType <LandingSite>().ToList(); editedLandingSite = tempListOfRemovedItems[0]; LandingSites.Delete(editedLandingSite.LandingSiteID); } break; case NotifyCollectionChangedAction.Replace: { List <LandingSite> tempListOfLandingSites = e.NewItems.OfType <LandingSite>().ToList(); editedLandingSite = tempListOfLandingSites[0]; LandingSites.Update(editedLandingSite); // As the IDs are unique, only one row will be effected hence first index only } break; } EntityChangedEventArgs args = new EntityChangedEventArgs(editedLandingSite.GetType().Name, editedLandingSite); EntityChanged?.Invoke(this, args); }
private void LandingSiteCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { _editSuccess = false; switch (e.Action) { case NotifyCollectionChangedAction.Add: { int newIndex = e.NewStartingIndex; LandingSite newLandingSite = LandingSiteCollection[newIndex]; if (LandingSites.Add(newLandingSite)) { CurrentEntity = newLandingSite; _editSuccess = true; } } break; case NotifyCollectionChangedAction.Remove: { List <LandingSite> tempListOfRemovedItems = e.OldItems.OfType <LandingSite>().ToList(); if (LandingSites.Delete(tempListOfRemovedItems[0].ID)) { _editSuccess = true; CurrentEntity = null; } } break; case NotifyCollectionChangedAction.Replace: { List <LandingSite> tempList = e.NewItems.OfType <LandingSite>().ToList(); if (LandingSites.Update(tempList[0])) { _editSuccess = true; CurrentEntity = tempList[0]; } } break; } }