private void buttonDeleteSubject_Click(object sender, EventArgs e) { try { if (UserConfirmsThatWantToDeleteSubject()) { var selectedSubject = this.comboBoxSelectSubjectToDelete.SelectedItem as Subject; ISubjectLogic subjectOperations = Provider.GetInstance.GetSubjectOperations(); subjectOperations.DeleteSubjectByCode(selectedSubject.Code); this.labelActionResult.Text = "Subject " + selectedSubject + " was succesfully deleted."; this.labelActionResult.Visible = true; this.ReloadComboBoxSelectSubjectToDelete(); } } catch (CoreException ex) { this.labelActionResult.Text = ex.Message; this.labelActionResult.Visible = true; } catch (Exception ex) { this.labelActionResult.Text = ex.Message; this.labelActionResult.Visible = true; } }
private List <Subject> GetSubjectsThatAreNotInTeacher(List <Subject> teacherSubjects) { ISubjectLogic subjectsOperations = Provider.GetInstance.GetSubjectOperations(); List <Subject> systemSubjects = subjectsOperations.GetSubjects(); return(systemSubjects?.Where(systemSubject => !teacherSubjects.Any(teacherSubject => systemSubject.Equals(teacherSubject))).ToList()); }
private Subject FindSubjectOnSystem(int code) { ISubjectLogic subjectOperations = DummyProvider.GetInstance.GetSubjectOperations(); List <Subject> subjects = subjectOperations.GetSubjects(); return(subjects.Find(x => x.GetCode() == code)); }
public void AddSubjectToSystem() { ISubjectLogic subjectOperations = DummyProvider.GetInstance.GetSubjectOperations(); Subject newSubject = new Subject(1, "Logic"); subjectOperations.AddSubject(newSubject); Assert.IsNotNull(this.FindSubjectOnSystem(newSubject.GetCode())); }
private Provider() { this.teachersLogic = new TeacherLogic(new TeacherPersistance()); this.studentsLogic = new StudentLogic(new StudentPersistance()); this.subjectsLogic = new SubjectLogic(new SubjectPersistance()); this.vehiclesLogic = new VehicleLogic(new VehiclePersistance()); this.activitiesLogic = new ActivityLogic(new ActivityPersistance()); this.paymentsLogic = new PaymentLogic(new PaymentPersistence()); }
public void DeleteSubject() { ISubjectLogic subjectOperations = DummyProvider.GetInstance.GetSubjectOperations(); Subject subject = new Subject(1000, "Logic"); subjectOperations.AddSubject(subject); subjectOperations.DeleteSubjectByCode(1000); Assert.IsNull(this.FindSubjectOnSystem(1000)); }
private void LoadFormData() { ISubjectLogic subjectOperations = Provider.GetInstance.GetSubjectOperations(); List <Subject> subjects = subjectOperations.GetSubjects(); foreach (Subject subject in subjects) { this.listBoxSystemSubjects.Items.Add(subject); } }
private void CheckIfIsThereAnySubjectInSystem() { ISubjectLogic subjectOperations = Provider.GetInstance.GetSubjectOperations(); List <Subject> subjects = subjectOperations.GetSubjects(); if (subjects.Count().Equals(0)) { this.labelError.Text = "Currently there is not any subject in the system."; this.labelError.Visible = true; } }
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(); }
private void FillSubjectStudentsListBox(int subjectCode) { ISubjectLogic subjectOperations = Provider.GetInstance.GetSubjectOperations(); Subject subject = subjectOperations.GetSubjectByCode(subjectCode); var studentsOnThisSubject = subject.Students; for (int index = 0; index < studentsOnThisSubject?.Count; index++) { this.listBoxSubjectStudents.Items.Add(studentsOnThisSubject.ElementAt(index)); } }
private void FillSubjectsComboBox() { ISubjectLogic subjectOperations = Provider.GetInstance.GetSubjectOperations(); List <Subject> subjects = subjectOperations.GetSubjects(); for (int index = 0; index < subjects?.Count(); index++) { this.comboBoxSelectSubjectToModify.Items.Add(subjects[index]); } this.comboBoxSelectSubjectToModify.DropDownStyle = ComboBoxStyle.DropDownList; }
public void AfterDeleteSubjectCodeIsAvailableToCreateNewSubject() { ISubjectLogic subjectOperations = DummyProvider.GetInstance.GetSubjectOperations(); Subject subject = new Subject(1000, "Logic"); subjectOperations.AddSubject(subject); subjectOperations.DeleteSubjectByCode(subject.GetCode()); Subject anotherSubject = new Subject(1000, "Logic"); subjectOperations.AddSubject(anotherSubject); Assert.IsNotNull(this.FindSubjectOnSystem(anotherSubject.GetCode())); }
private void FillSubjectTeachersListBox(int subjectCode) { ISubjectLogic subjectOperations = Provider.GetInstance.GetSubjectOperations(); Subject subject = subjectOperations.GetSubjectByCode(subjectCode); var teachersThatTeachThisSubject = subject.Teachers; for (int index = 0; index < teachersThatTeachThisSubject.Count; index++) { this.listBoxSubjectTeachers.Items.Add(teachersThatTeachThisSubject.ElementAt(index)); } }
private void LoadFormInitialData() { IStudentLogic studentOperations = Provider.GetInstance.GetStudentOperations(); this.textBoxStudentNumber.Text = studentOperations.GetNextStudentNumber().ToString(); ISubjectLogic subjectOperations = Provider.GetInstance.GetSubjectOperations(); List <Subject> subjects = subjectOperations.GetSubjects(); foreach (Subject subject in subjects) { this.listBoxSystemSubjects.Items.Add(subject); } }
private void FillSystemStudentsListBox(int subjectCode) { IStudentLogic studentOperations = Provider.GetInstance.GetStudentOperations(); ISubjectLogic subjectOperations = Provider.GetInstance.GetSubjectOperations(); List <Student> systemStudents = studentOperations.GetStudents(); var subject = subjectOperations.GetSubjectByCode(subjectCode); var studentsOfThisSubject = subject.Students; var studentsToAddToListBox = systemStudents.Where(t => !studentsOfThisSubject.Any(st => st.Document == t.Document)).ToList(); for (int index = 0; index < studentsToAddToListBox?.Count(); index++) { this.listBoxSystemStudents.Items.Add(studentsToAddToListBox[index]); } }
private void FillSystemTeachersListBox(int subjectCode) { ITeacherLogic teacherOperations = Provider.GetInstance.GetTeacherOperations(); ISubjectLogic subjectOperations = Provider.GetInstance.GetSubjectOperations(); List <Teacher> systemTeachers = teacherOperations.GetTeachers(); var subject = subjectOperations.GetSubjectByCode(subjectCode); var teachersOfThisSubject = subject.Teachers; var teachersToAddToListBox = systemTeachers.Where(t => !teachersOfThisSubject.Any(st => st.Document == t.Document)).ToList(); for (int index = 0; index < teachersToAddToListBox.Count(); index++) { this.listBoxSystemTeachers.Items.Add(teachersToAddToListBox[index]); } }
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"); }
private void buttonAdd_Click(object sender, EventArgs e) { this.labelOk.Visible = false; this.labelError.Visible = false; try { this.labelError.Visible = false; string name; int code; Subject subject = new Subject(); if (int.TryParse(this.textBoxSubjectCode.Text, out code)) { if (!string.IsNullOrWhiteSpace(this.textBoxSubjectName.Text)) { subject.Code = code; name = this.textBoxSubjectName.Text; subject.Name = name; ISubjectLogic subjectsOperations = Provider.GetInstance.GetSubjectOperations(); subjectsOperations.AddSubject(subject); this.ClearAddSubjectForm(); this.ShowCorrectlyAddedSubjectMessage(code, name); } 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.Text = ex.Message; this.labelError.Visible = true; } catch (Exception ex) { this.labelError.Text = ex.Message; this.labelError.Visible = true; } }
public void AddSubjectToStudent() { IStudentLogic studentOperations = DummyProvider.GetInstance.GetStudentOperations(); ISubjectLogic subjectOperations = DummyProvider.GetInstance.GetSubjectOperations(); List <Subject> systemSubjects = SystemDummyData.GetInstance.GetSubjects(); Subject aSubject = new Subject(123456, "Math"); systemSubjects.Add(aSubject); Student newStudent = Utility.CreateRandomStudent(); Subject subjectToBeAdded = subjectOperations.GetSubjectByCode(123456); newStudent.AddSubjectToStudent(subjectToBeAdded); Assert.IsTrue(newStudent.GetSubjects().Count > 0); }
public void AddSubjectToTeacher() { ITeacherLogic teacherOperations = DummyProvider.GetInstance.GetTeacherOperations(); ISubjectLogic subjectOperations = DummyProvider.GetInstance.GetSubjectOperations(); List <Subject> systemSubjects = SystemDummyData.GetInstance.GetSubjects(); Subject aSubject = new Subject(123456, "Math"); systemSubjects.Add(aSubject); Teacher newTeacher = this.CreateRandomTeacher(); Subject subjectToBeAdded = subjectOperations.GetSubjectByCode(123456); newTeacher.AddSubjectToTeach(subjectToBeAdded); Assert.IsTrue(newTeacher.GetSubjects().Count > 0); }
public void TryToAddSubjectThatAlreadyExistsToSystem() { try { ISubjectLogic subjectOperations = DummyProvider.GetInstance.GetSubjectOperations(); Subject firstTeacher = new Subject(1, "Logic"); Subject secondTeacher = new Subject(1, "Logic"); subjectOperations.AddSubject(firstTeacher); subjectOperations.AddSubject(secondTeacher); Assert.Fail(); } catch (CoreException ex) { Assert.IsTrue(ex.Message.Equals("Subject already exists.")); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void RemoveSubjectFromTeacher() { ITeacherLogic teacherOperations = DummyProvider.GetInstance.GetTeacherOperations(); ISubjectLogic subjectOperations = DummyProvider.GetInstance.GetSubjectOperations(); List <Subject> systemSubjects = SystemDummyData.GetInstance.GetSubjects(); Subject subject1 = new Subject(123456, "Math"); Subject subject2 = new Subject(654321, "Physics"); systemSubjects.Add(subject1); systemSubjects.Add(subject2); Teacher newTeacher = this.CreateRandomTeacher(); Subject subjectToBeAdded1 = subjectOperations.GetSubjectByCode(123456); Subject subjectToBeAdded2 = subjectOperations.GetSubjectByCode(654321); newTeacher.AddSubjectToTeach(subjectToBeAdded1); newTeacher.AddSubjectToTeach(subjectToBeAdded2); newTeacher.RemoveSubject(subjectToBeAdded1); List <Subject> teacherSubjects = newTeacher.GetSubjects(); Assert.IsFalse(teacherSubjects.Exists(item => item.Equals(subjectToBeAdded1))); }
public SubjectController(ISubjectLogic subjectLogic) { _subjectLogic = subjectLogic; }