private void Modify_btn_Click(object sender, RoutedEventArgs e) { MotoGPTeam modified = (MotoGPTeam)Teams_dgw.SelectedItem; //if nothing selected, do not respond if (modified == null) { return; } AddOrModify addOrModify = new AddOrModify(modified, true); addOrModify.ShowDialog(); //Clicked OK (validated) if (addOrModify.DialogResult.HasValue && addOrModify.DialogResult.Value) { //Upserting value using (MotoGPContext db = new MotoGPContext()) { db.Teams.AddOrUpdate(modified); db.SaveChanges(); teams = db.Teams.ToList(); Teams_dgw.ItemsSource = teams; } } }
private void Delete_btn_Click(object sender, RoutedEventArgs e) { MotoGPTeam modified = (MotoGPTeam)Teams_dgw.SelectedItem; //if nothing selected, do not respond if (modified == null) { return; } Delete delete = new Delete(); delete.ShowDialog(); //Clicked OK if (delete.DialogResult.HasValue && delete.DialogResult.Value) { //Upserting value using (MotoGPContext db = new MotoGPContext()) { db.Teams.Remove(db.Teams.Find(modified.Name)); db.SaveChanges(); teams = db.Teams.ToList(); Teams_dgw.ItemsSource = teams; } } }
private void Add_btn_Click(object sender, RoutedEventArgs e) { MotoGPTeam modified = new MotoGPTeam(); AddOrModify addOrModify = new AddOrModify(modified, false); addOrModify.ShowDialog(); //Clicked OK (validated) if (addOrModify.DialogResult.HasValue && addOrModify.DialogResult.Value) { //Upserting value using (MotoGPContext db = new MotoGPContext()) { db.Teams.AddOrUpdate(modified); db.SaveChanges(); teams = db.Teams.ToList(); Teams_dgw.ItemsSource = teams; } } }