private void button_leases_modify_Click(object sender, RoutedEventArgs e) { if (dataGrid_leases.SelectedIndex == -1) { return; } BoolHelper bh = new BoolHelper(); LeaseAdd la = new LeaseAdd(Flats.ToList(), Users.ToList(), bh); Lease l = Leases[dataGrid_leases.SelectedIndex]; Lease lcf = l.ShallowCopy(); la.DataContext = l; la.ShowDialog(); if (bh.BoolHelp) { try { dbContext.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { l = lcf.ShallowCopy(); dbContext.Leases.AddOrUpdate(l); dbContext.SaveChanges(); } dataGrid_leases.ItemsSource = null; dataGrid_leases.ItemsSource = Leases; }