public async Task <ActionResult> Index(int subject = 0, int status = -1, string sortBy = "lastUpdated", bool desc = true, int page = 1, int pageSize = 10)
        {
            var user = await _userManager.FindByIdAsync(CurrentUserId);

            if (user == null)
            {
                throw new UserNotFoundException(CurrentUserId);
            }


            var model = new ExamIndexViewModel();

            if (page < 1)             //初次載入頁面
            {
                model.LoadExamTypeOptions();
                model.LoadRecruitExamTypeOptions();

                var yearRecruits = _dataService.FetchYearRecruits();
                model.YearRecruits = yearRecruits.ToList();


                model.LoadStatusOptions();

                //考試科目
                var examSubjects = await _subjectsService.FetchExamSubjectsAsync();

                model.LoadSubjectOptions(examSubjects, "全部");

                page = 1;
            }

            var exams = await _examsService.FetchAsync(user);


            if (exams.HasItems())
            {
                exams = exams.FilterByStatus(status.ToExamStaus());

                var subjects = await _subjectsService.FetchAsync();

                if (subject > 0)
                {
                    exams = FilterBySubject(exams, subjects, subject);
                }


                foreach (var exam in exams)
                {
                    exam.LoadSubject(subjects);
                }

                exams = exams.GetOrdered(sortBy, desc);
            }

            model.PagedList = exams.GetPagedList(_mapper, page, pageSize, sortBy, desc);

            return(Ok(model));
        }
Example #2
0
        public static void LoadStatusOptions(this ExamIndexViewModel model, string emptyText = "全部")
        {
            var options = GetStatusOptions().ToList();

            if (!String.IsNullOrEmpty(emptyText))
            {
                options.Insert(0, new BaseOption <int>(-1, emptyText));
            }

            model.StatusOptions = options;
        }
Example #3
0
        public static void LoadSubjectOptions(this ExamIndexViewModel model, IEnumerable <Subject> subjects, string emptyText = "")
        {
            var options = subjects.Select(item => item.ToOption()).ToList();

            if (!String.IsNullOrEmpty(emptyText))
            {
                options.Insert(0, new BaseOption <int>(-1, emptyText));
            }

            model.SubjectOptions = options;
        }
        public async Task <ActionResult> Init()
        {
            var model = new ExamIndexViewModel();

            model.LoadExamTypeOptions();
            model.LoadRecruitExamTypeOptions();

            var yearRecruits = _dataService.FetchYearRecruits();

            model.YearRecruits = yearRecruits.ToList();

            //考試科目
            var examSubjects = await _subjectsService.FetchExamSubjectsAsync();

            model.LoadSubjectOptions(examSubjects, "全部");

            return(Ok(model));
        }
Example #5
0
 public static void LoadRecruitExamTypeOptions(this ExamIndexViewModel model)
 => model.RecruitExamTypeOptions = GetRecruitExamTypeOptions();