Exemple #1
0
        public JsonResult Add(StudentViewModel 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 student to the database/course offering
            try
            {
                // Get the created student from the factory
                var studentFactory = new StudentFactory();
                var student = studentFactory.CreateStudent(viewModel.Number.ToString(), viewModel.Name, viewModel.Type);

                // Get the course offering
                var offering = _courseService.GetCourseOffering(viewModel.SelectedYear, viewModel.SelectedSemester, viewModel.SelectedOffering);

                // Add the student
                _courseService.AddStudent(student, offering);
            }
            catch (StudentExistsException)
            {
                return Json(new { error = true, message = "Student already in course offering" });
            }

            return Json(new { error = false, message = "Student successfully added to course offering!" });
        }
Exemple #2
0
        // Populate Student View Model
        public StudentViewModel PopulateViewModel(StudentViewModel viewModel)
        {
            viewModel.CourseOfferings = _courseService.GetAllCourseOfferings();
            viewModel.CourseOfferings.Sort(new CourseOfferingComparer());

            return viewModel;
        }
Exemple #3
0
        public PartialViewResult List(string courseId, string semester, int year)
        {
            // Get the selected course offering
            var offering = _courseService.GetCourseOffering(year, semester, courseId);

            // Get students in offering and sort based out custom comparer
            var students = _courseService.GetStudents(offering);
            students.Sort(StudentComparer.CustomSort);

            // Update view model with students in course offering
            var viewModel = new StudentViewModel()
            {
                Students = students
            };

            return PartialView("_DisplayStudents", viewModel);
        }