private void UsunBtn_Click(object sender, RoutedEventArgs e) { StudentsDBEntities SDE = new StudentsDBEntities(); var rowAssessment = (AssessmentsTable)OcenyDg.SelectedItem; MessageBoxResult question = MessageBox.Show("Czy chcesz usunąć tę ocenę?", "Usuwanie oceny", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (question == MessageBoxResult.Yes) { var UsunOceneStudenta = SDE.AssessmentsTable.Where(w => w.Id == rowAssessment.Id).FirstOrDefault(); SDE.AssessmentsTable.Remove(UsunOceneStudenta); SDE.SaveChanges(); ListaStudentowDg_SelectionChanged(null, null); } }
private void UsunStudenta_Click(object sender, RoutedEventArgs e) { var rowStudent = (StudentsTable)ListaStudentowDg.SelectedItem; StudentsDBEntities SDE = new StudentsDBEntities(); MessageBoxResult question = MessageBox.Show("Czy chcesz usunąć studenta: " + rowStudent.StudentName + " " + rowStudent.StudentSurname + "?", "Usuwanie studenta", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (question == MessageBoxResult.Yes) { var UsunStudenta = SDE.StudentsTable.Where(w => w.Id == rowStudent.Id).FirstOrDefault(); SDE.StudentsTable.Remove(UsunStudenta); SDE.AssessmentsTable.RemoveRange(SDE.AssessmentsTable.Where(w => w.IndeksID == rowStudent.Id)); SDE.SaveChanges(); WyszykajTb_KeyUp(null, null); ListaStudentowDg_SelectionChanged(null, null); } }