void UpdateCollection(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { try { switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: { if (e.NewItems != null && e.NewItems.Count > 0) { foreach (Firmen_Personen item in e.NewItems) { if (fk.Where(k => k.id_Teilnehmer == item.id).Count() == 0) { var k = new Termin_TeilnehmerExtern(); k.id_Teilnehmer = item.id; k.CRMTermine = CurrentTermin; fk.Add(k); db.AddToTermin_TeilnehmerExtern(k); // db.SaveChanges(); } } } break; } case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: { if (e.OldItems != null && e.OldItems.Count > 0) { foreach (Firmen_Personen item in e.OldItems) { if (fk.Where(k => k.id_Teilnehmer == item.id).Count() == 1) { var k = fk.Where(ka => ka.id_Teilnehmer == item.id).SingleOrDefault(); fk.Remove(k); db.DeleteObject(k); // db.SaveChanges(); } } } break; } default: { break; } } } catch (Exception ex) { CommonTools.Tools.ErrorMethods.ShowErrorMessage(ex); } }