예제 #1
0
        public async Task <ActionResult> Index()
        {
            var subjects = await _subjectsService.FetchExamSubjectsAsync();

            var recruits = await _recruitsService.FetchAsync(parentId : 0);

            var model = new AnalysisIndexModel
            {
                Subjects            = subjects.MapViewModelList(_mapper),
                Recruits            = recruits.MapViewModelList(_mapper),
                RootSubjectSettings = _rootSubjectSettings
            };

            return(Ok(model));
        }
예제 #2
0
        public async Task <ActionResult> RQ(int subject)
        {
            var rootSubject = _subjectsService.GetById(subject);

            if (rootSubject == null)
            {
                return(NotFound());
            }
            if (rootSubject.ParentId > 0)
            {
                ModelState.AddModelError("subject", "錯誤的科目");
                return(BadRequest(ModelState));
            }

            var rootSubjectView = rootSubject.MapViewModel(_mapper);
            var subjectViews    = rootSubject.SubItems.MapViewModelList(_mapper);

            var allTerms = await _termsService.FetchAsync(new TermFilterBySubjectsSpecification(rootSubject.GetSubIds().ToList()));

            var allRecruits = await _recruitsService.GetAllAsync();

            var recruits = allRecruits.Where(x => x.SubjectId == subject).ToList();

            var models = new List <ExamSettingsViewModel>();

            foreach (var recruit in recruits)
            {
                recruit.LoadParent(allRecruits);
                recruit.LoadSubItems(allRecruits);

                //取得一個recruit年度的試題
                var rqModel = await GetRQModelAsync(recruit, rootSubject);

                var model = new ExamSettingsViewModel(rootSubjectView, recruit.MapViewModel(_mapper));
                foreach (var rqPart in rqModel.Parts)
                {
                    var partSettings = new ExamPartSettings()
                    {
                        Order        = rqPart.Order,
                        Title        = rqPart.Title,
                        Points       = rqPart.Points,
                        OptionCount  = rqPart.OptionCount,
                        OptionType   = rqPart.OptionType,
                        MultiAnswers = rqPart.MultiAnswers,

                        Questions = rqPart.Questions.Count
                    };


                    var subjectSettings = new List <ExamSubjectSettings>();
                    foreach (var subjectView in subjectViews)
                    {
                        var terms = allTerms.Where(x => x.SubjectId == subjectView.Id && x.ParentId == 0).GetOrdered();
                        foreach (var term in terms)
                        {
                            term.LoadSubItems(allTerms);
                        }

                        var termViews = terms.MapViewModelList(_mapper);

                        var examSubjectSettings = new ExamSubjectSettings(subjectView, termViews);
                        subjectSettings.Add(examSubjectSettings);
                    }

                    partSettings.Subjects = subjectSettings;

                    foreach (var question in rqPart.Questions)
                    {
                        partSettings.AddQuestion(question);
                    }

                    model.Parts.Add(partSettings);
                }

                models.Add(model);
            }


            var indexModel = new AnalysisIndexModel();

            indexModel.Results  = models;
            indexModel.ViewList = models.MapAnalysisViewList();


            return(Ok(indexModel));
        }