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)); }
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)); }