private void addCourseButton_Click(object sender, EventArgs e) { Course newCourse = new Course() { Department = courseDepartmentTextBox.Text, Name = courseNameTextBox.Text, Code = courseCodeTextBox.Text, Credits = 3 }; database.Courses.Add(newCourse); // should always try catch when doing database SaveChanges try { database.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); database.Dispose(); database = new RegistrationDatabase(); } UpdateCourseListLabel(); UpdateComboBox(); }
private void buttonAddSection_Click(object sender, EventArgs e) { var course = listBox1.SelectedItem as Course; var faculty = listBoxFaculty.SelectedItem as Faculty; if (course != null && faculty != null) { var newSection = new Section() { Course = course, Faculty = faculty, Term = listBoxTerm.SelectedItem.ToString() }; database.Sections.Add(newSection); // should always try catch when doing database SaveChanges try { database.SaveChanges(); RefreshListBox(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); database.Sections.Remove(newSection); } } }