Пример #1
0
        public ActionResult UpdateCourse(CreateOrEditCourseViewModel updatedCourse)
        {
            if (ModelState.IsValid)
            {
                var domainModel = ConvertToDomainModel(updatedCourse);

                var updatedModel = Courses.UpdateCourse(domainModel);

                if (ReferenceEquals(updatedModel.GetType(), typeof(ErrorDomainModel)))
                {
                    return(GradeTrackerError(updatedModel, updatedCourse));
                }
                else
                {
                    var castedDomainModel = (CourseDomainModel)updatedModel;
                    var viewModel         = new CourseViewModel((CourseDomainModel)updatedModel);
                    var semesterViewModel = Semesters.GetSemester(castedDomainModel.SemesterId);
                    viewModel.Semester = GetSemesterViewModel(semesterViewModel);

                    return(View("CourseUpdated", viewModel));
                }
            }
            else
            {
                return(View("UpdateCourse", updatedCourse));
            }
        }
Пример #2
0
        public ActionResult Create(CreateOrEditCourseViewModel createViewModel)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Identity.GetUserId();

                var createModel = ConvertToDomainModel(createViewModel);

                createModel.StudentId = Guid.Parse(userId);

                var domainIModel = Courses.CreateCourse(createModel);
                var domainModel  = new CourseDomainModel();

                if (domainIModel.GetType() == typeof(ErrorDomainModel))
                {
                    var semesterModels = Semesters.GetAllSemesters();

                    if (semesterModels.Count > 0 && semesterModels.First().GetType() == typeof(ErrorDomainModel))
                    {
                        return(GradeTrackerError(semesterModels.First(), null));
                    }

                    createViewModel.Semesters   = GetSemestersForDropDown(semesterModels);
                    createViewModel.YearOptions = GetYearDropDownOptions();

                    return(GradeTrackerError(domainIModel, createViewModel));
                }
                else
                {
                    domainModel = (CourseDomainModel)domainIModel;
                }

                var newCourseViewModel = new CourseViewModel(domainModel);

                var semesterModel = Semesters.GetSemester(domainModel.SemesterId);

                if (semesterModel.GetType() == typeof(ErrorDomainModel))
                {
                    return(GradeTrackerError(semesterModel, null));
                }

                newCourseViewModel.Semester = GetSemesterViewModel(semesterModel);

                return(View("ViewCourse", newCourseViewModel));
            }
            else
            {
                var semesterModels = Semesters.GetAllSemesters();

                if (semesterModels.Count > 0 && semesterModels.First().GetType() == typeof(ErrorDomainModel))
                {
                    return(GradeTrackerError(semesterModels.First(), null));
                }

                createViewModel.Semesters   = GetSemestersForDropDown(semesterModels);
                createViewModel.YearOptions = GetYearDropDownOptions();

                return(View("Add", createViewModel));
            }
        }
Пример #3
0
        public ActionResult ViewCourse(Guid courseId)
        {
            var courseDomainModel = new CourseDomainModel();
            var iModel            = Courses.GetCourse(courseId);

            if (iModel.GetType() == typeof(ErrorDomainModel))
            {
                return(GradeTrackerError(iModel, null));
            }
            else
            {
                courseDomainModel = (CourseDomainModel)iModel;
            }

            var courseViewModel = new CourseViewModel(courseDomainModel);

            var evaluationDomainModels = Evaluations.GetEvaluationsForCourse(courseId);

            if (evaluationDomainModels.Count > 0 && evaluationDomainModels.First().GetType() == typeof(ErrorDomainModel))
            {
                return(GradeTrackerError(evaluationDomainModels.First(), null));
            }

            var semesterModel = Semesters.GetSemester(courseDomainModel.SemesterId);

            if (semesterModel.GetType() == typeof(ErrorDomainModel))
            {
                return(GradeTrackerError(semesterModel, null));
            }

            courseViewModel.Semester    = GetSemesterViewModel(semesterModel);
            courseViewModel.Evaluations = ConvertToListViewModel(evaluationDomainModels);
            courseViewModel.SetLastModified();

            return(View(courseViewModel));
        }