private void GradeModification(object sender, RoutedEventArgs e) { GradeWindow gw = new GradeWindow { comboBoxCourses = { ItemsSource = _factory.GetRepository().Courses, SelectedIndex = 0 } }; if (gw.ShowDialog() != true) return; //Since the starting index is predetermined, the Course value cannot be null var newGrade = new Grade(gw.comboBoxCourses.SelectionBoxItem as Course, int.Parse(gw.textBoxMark.Text)); try { _factory.GetRepository().AddGrade(newGrade); } catch (ArgumentNullException) { MessageBox.Show("Could not add/edit the grade. Please try again.", "Null error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (ArgumentException) { _factory.GetRepository().EditGrade(newGrade); } }
private void CheckGrade(Grade grade) { if (grade == null) { throw new ArgumentNullException(); } }
private void buttonOK_Click(object sender, RoutedEventArgs e) { try { Grade grade = new Grade((Course)comboBoxCourses.SelectedValue, Convert.ToInt32(textBoxMark.Text)); if (_sender.Name.Equals("buttonAdd")) { _repository.AddGrade(grade); } else { _repository.EditGrade(grade); } DialogResult = true; } catch (ArgumentNullException) { MessageBox.Show(ArgumentNullExceptionMessage, ErrorMessage); } catch (FormatException) { MessageBox.Show(FormatExceptionMessage, ErrorMessage); } catch (ArgumentException) { MessageBox.Show(ArgumentExceptionMessage, ErrorMessage); } catch (Exception) { MessageBox.Show(UnhandledErrorMessage, ErrorMessage); } }
public void EditGrade(Grade grade) { CheckGrade(grade); var tmpIndex = _grades.FindIndex(g => g.Course.Equals(grade.Course)); grade.Id = tmpIndex; _grades[tmpIndex] = grade; Save(); GradesChangedRun(); }
public void EditGrade(Grade grade) { if (grade == null) throw new ArgumentNullException(); foreach (var gradeInList in Grades.Where(gradeInList => gradeInList.Equals(grade))) gradeInList.Mark = grade.Mark; Save(); if (GradesChanged != null) GradesChanged.Invoke(); }
public void AddGrade(Grade grade) { CheckGrade(grade); if (_grades.Any(g => g.Equals(grade))) { throw new ArgumentException(); } grade.Id = _grades.Count; _grades.Add(grade); Save(); GradesChangedRun(); }
public void AddGrade(Grade grade) { if (grade == null) throw new ArgumentNullException(); //Method List<T>.Contains(T obj) uses the overriden Equals methods for objects Grade and Course, therefore it is eligible if (Grades.Contains(grade)) throw new ArgumentException(); grade.Id = _idHolder++; Grades.Add(grade); Save(); if (GradesChanged != null) GradesChanged.Invoke(); }