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