예제 #1
0
        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!" });
        }
예제 #2
0
        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);
        }
예제 #3
0
 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;
 }
예제 #4
0
        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();
        }
예제 #5
0
        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();
        }
예제 #6
0
 public List<Student> GetStudents(CourseOffering offering) => _studentRepository.GetStudents(offering);
예제 #7
0
 public bool StudentExists(CourseOffering offering, string number)
 {
     return offering.Students.FirstOrDefault(s => s.StudentNum == number) != null;
 }
예제 #8
0
 public List<Student> GetStudents(CourseOffering offering)
 {
     return offering.Students.ToList();
 }
예제 #9
0
 public int CompareTo(CourseOffering other) => other == null ? 1 : Year.CompareTo(other.Year);
예제 #10
0
 public void InsertCourseOffering(CourseOffering courseOffering)
 {
     _dbContext.CourseOfferings.Add(courseOffering);
 }