public JsonResult Add(CourseOfferingViewModel viewModel) { // Populate VM viewModel = PopulateViewModel(viewModel); // Validate model state if (!ModelState.IsValid) return Json(new { error = true, message = "There were errors in the submission"}); // Attempt to add the offering try { var offering = new CourseOffering() { Course_CourseID = viewModel.SelectedCourseId, Semester = viewModel.Semester.ToString(), Year = viewModel.SelectedYear }; _courseService.AddCourseOffering(offering); } catch (CourseOfferingExistsException) { // If the offering already exists, display error return Json(new { error = true, message = "Course offering already exists" }); } return Json(new { error = false, message = "Course offering successfully created!" }); }
public void AddStudent(Student student, CourseOffering offering) { // Check if the student already exists in the offering if (_studentRepository.StudentExists(offering, student.StudentNum)) throw new StudentExistsException(); // Insert the student into the offering _courseOfferingRepository.InsertStudentIntoCourseOffering(student, offering); }
public bool CourseOfferingExists(CourseOffering offering) { var match = _dbContext.CourseOfferings.Any( o => o.Course_CourseID == offering.Course_CourseID && o.Year == offering.Year && o.Semester == offering.Semester); return match; }
public void AddCourseOffering(CourseOffering offering) { // If a course offering already exists, throw custom exception if (_courseOfferingRepository.CourseOfferingExists(offering)) throw new CourseOfferingExistsException(); // Insert the course offering _courseOfferingRepository.InsertCourseOffering(offering); _courseOfferingRepository.Save(); }
public void InsertStudentIntoCourseOffering(Student student, CourseOffering courseOffering) { // Get the current student from the offering var currentStudent = _dbContext.Students.FirstOrDefault(s => s.StudentNum == student.StudentNum); // Add / Register student courseOffering.Students.Add(currentStudent ?? student); // Persist to the DB Save(); }
public List<Student> GetStudents(CourseOffering offering) => _studentRepository.GetStudents(offering);
public bool StudentExists(CourseOffering offering, string number) { return offering.Students.FirstOrDefault(s => s.StudentNum == number) != null; }
public List<Student> GetStudents(CourseOffering offering) { return offering.Students.ToList(); }
public int CompareTo(CourseOffering other) => other == null ? 1 : Year.CompareTo(other.Year);
public void InsertCourseOffering(CourseOffering courseOffering) { _dbContext.CourseOfferings.Add(courseOffering); }