private void buttonModifySubject_Click(object sender, EventArgs e) { try { this.labelError.Visible = false; string name; int code; Subject newSubject = new Subject(); Subject originalSubject = (Subject)this.comboBoxSelectSubjectToModify.SelectedItem; if (int.TryParse(this.textBoxCodeModifySubject.Text, out code)) { if (!string.IsNullOrWhiteSpace(this.textBoxNameModifySubject.Text)) { newSubject.Code = code; name = this.textBoxNameModifySubject.Text; newSubject.Name = name; List <Teacher> teachers = this.listBoxSubjectTeachers.Items.Cast <Teacher>().ToList(); newSubject.SetTeachers(teachers); List <Student> students = this.listBoxSubjectStudents.Items.Cast <Student>().ToList(); newSubject.SetStudents(students); ISubjectLogic subjectOperations = Provider.GetInstance.GetSubjectOperations(); subjectOperations.ModifySubjectByCode(originalSubject.Code, newSubject); this.labelSuccess.Text = "Subject was succesfully modified."; this.labelSuccess.Visible = true; } else { this.labelError.Visible = true; this.labelError.Text = "Subject's name must be a not empty string"; } } else { this.labelError.Visible = true; this.labelError.Text = "Subject's code must be a number"; } } catch (CoreException ex) { this.labelError.Visible = true; this.labelError.Text = ex.Message; } catch (Exception ex) { this.labelError.Visible = true; this.labelError.Text = ex.Message; } this.ReloadComboBoxSelectSubjectToModify(); this.CleanFields(); }
public void ModifySubject() { ISubjectLogic subjectOperations = DummyProvider.GetInstance.GetSubjectOperations(); int subjectCode = 1; Subject subject = new Subject(subjectCode, "Logic"); subjectOperations.AddSubject(subject); subject.SetName("LogicModified"); subjectOperations.ModifySubjectByCode(subjectCode, subject); Subject modifiedSubject = subjectOperations.GetSubjectByCode(subjectCode); Assert.AreEqual(modifiedSubject.GetName(), "LogicModified"); }