private void OnRegisterClick(object sender, RoutedEventArgs e) { User newUser = new User { Name = NameTextBox.Text, Surname = SurnameTextBox.Text, MiddleName = MiddleNameTextBox.Text, Position = PositionTextBox.Text }; using (CarServiceContext db = new CarServiceContext()) { db.Users.Add(newUser); db.SaveChanges(); } Close(); }
private void OnDeleteClick(object sender, RoutedEventArgs e) { int selectedIndex = tabControl1.SelectedIndex; switch (selectedIndex) { case 0: break; case 1: Client deleteClient = clientsGrid.SelectedItems[0] as Client; db.Cars.RemoveRange(deleteClient.Cars); db.Clients.Remove(deleteClient); break; case 2: Car deleteCar = carGrid.SelectedItems[0] as Car; db.Cars.Remove(deleteCar); break; } db.SaveChanges(); }