Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
0
        public ActionResult Add()
        {
            var createModel = new CreateOrEditCourseViewModel();

            var semesterModels = Semesters.GetAllSemesters();

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

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

            return(View(createModel));
        }
Exemplo n.º 3
0
        public ActionResult EditCourse(Guid courseid)
        {
            var domainModel = Courses.GetCourse(courseid);

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

            var viewModel = new CreateOrEditCourseViewModel((CourseDomainModel)domainModel);
            var semesters = Semesters.GetAllSemesters();

            viewModel.Semesters   = GetSemestersForDropDown(semesters);
            viewModel.YearOptions = GetYearDropDownOptions();

            return(View("UpdateCourse", viewModel));
        }