/// <summary> /// Удалить данные /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteButton_Click(object sender, RoutedEventArgs e) { using (var db = new MedIdeaContext()) { if (treatmentsGrid.SelectedItems.Count > 0) { for (var i = 0; i < treatmentsGrid.SelectedItems.Count; i++) { var treatment = treatmentsGrid.SelectedItems[i] as Treatment; if (treatment != null) { db.Treatments.Remove(treatment); } } } db.SaveChanges(); } UpdateTreatmentsGrid(); }
/// <summary> /// Удалить данные /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteButton_Click(object sender, RoutedEventArgs e) { using (var db = new MedIdeaContext()) { if (usersGrid.SelectedItems.Count > 0) { for (var i = 0; i < usersGrid.SelectedItems.Count; i++) { var user = usersGrid.SelectedItems[i] as User; if (user != null) { db.Users.Remove(user); } } } db.SaveChanges(); } UpdateGrid(); }
/// <summary> /// Сохранить изменения. /// </summary> /// <param name="newUser"> /// <see cref="User" /> /// </param> /// <param name="user"> /// <see cref="User" /> /// </param> private void SaveChanges(User newUser, User user) { using (var db = new MedIdeaContext()) { AddNewDataFromFields(newUser); if (user != null) { db.Update(newUser); AddDataInList(newUser); db.UpdateRange(list); } else { db.Add(newUser); AddDataInList(newUser); db.UpdateRange(list); } db.SaveChanges(); } }
/// <summary> /// Обновить грид /// </summary> private void UpdateTreatmentsGrid() { using var db = new MedIdeaContext(); _treatment = db.Treatments.Where(x => x.User == _user).ToList(); treatmentsGrid.ItemsSource = db.Treatments.Local.ToBindingList(); }
/// <summary> /// Обновить грид /// </summary> private void UpdateGrid() { using var db = new MedIdeaContext(); db.Users.ToList(); usersGrid.ItemsSource = db.Users.Local.ToBindingList(); }