internal static void EditSubject(ApplicationDbContext context, CollegeSubject collegeSubject) { var collegeSubjectToUpdate = context.CollegeSubjects.Where(c => c.Id == collegeSubject.Id).FirstOrDefault(); collegeSubjectToUpdate.SubjectName = collegeSubject.SubjectName; collegeSubjectToUpdate.SubjectAlias = collegeSubject.SubjectAlias; collegeSubjectToUpdate.CollegeId = collegeSubject.CollegeId; context.SaveChanges(); }
public CollegeSubjectDialog(CollegeSubject collegeSubject = null) { InitializeComponent(); this.CollegeSubject = collegeSubject ?? new CollegeSubject(); GridFormCollegeSubject.DataContext = CollegeSubject; collegesCombo.ItemsSource = _db.Colleges.ToList(); collegesCombo.DisplayMemberPath = "CollegeName"; collegesCombo.SelectedValuePath = "Id"; mayClose = false; }
public static CollegeSubject AddCollegeSubject(ApplicationDbContext context, CollegeSubject subject) { try { context.CollegeSubjects.Add(subject); context.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Curso não criado.", "Erro"); } MessageBox.Show("Curso criado com sucesso.", "Sucesso"); return(subject); }
private void ButtonEdit_Click(object sender, RoutedEventArgs e) { CollegeSubject employeeEdit = subjectGrd.SelectedItem as CollegeSubject; if (employeeEdit == null) { return; } CollegeSubjectDialog collegeSubjectDialog = new CollegeSubjectDialog(new CollegeSubject(employeeEdit)) { Title = "Editar Curso" }; if (collegeSubjectDialog.ShowDialog() == true) { DbContextHelper.EditSubject(_db, collegeSubjectDialog.CollegeSubject); subjectGrd.Items.Refresh(); } }