public async Task <ActionResult> Index(int parent = 0, int active = 1, int year = 0)
        {
            var recruits = await _recruitsService.FetchAsync(parent);

            if (active >= 0)
            {
                recruits = recruits.Where(x => x.Active == active.ToBoolean());
            }
            if (year > 0)
            {
                recruits = recruits.Where(x => x.Year == year);
            }

            recruits = recruits.GetOrdered();

            _recruitsService.LoadSubItems(recruits);

            if (parent == 0)
            {
                var subjects = await _subjectsService.FetchAsync();

                _subjectsService.LoadSubItems(subjects);

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

                    foreach (var subItem in recruit.SubItems)
                    {
                        if (subItem.SubjectId > 0)
                        {
                            var subject = subjects.FirstOrDefault(x => x.Id == subItem.SubjectId);
                            subject.GetSubIds();

                            subItem.Subject = subject;

                            var subjectIds = new List <int> {
                                subject.Id
                            };
                            subjectIds.AddRange(subject.SubIds);
                            subItem.SubjectIds = subjectIds;
                        }
                    }
                }
            }


            return(Ok(recruits.MapViewModelList(_mapper)));
        }
Example #2
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));
        }
Example #3
0
        public async Task <ActionResult> StoreYearRecruits(AdminRequest model)
        {
            ValidateRequest(model, _adminSettings);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            int parent   = 0;
            var recruits = await _recruitsService.FetchAsync(parent);

            recruits = recruits.Where(x => x.Active).GetOrdered();

            _recruitsService.LoadSubItems(recruits);

            var recruitViews = recruits.MapViewModelList(_mapper);

            foreach (var yearView in recruitViews)
            {
                foreach (var recruitView in yearView.SubItems)
                {
                    recruitView.QuestionIds = _questionsService.FetchQuestionIdsByRecruit(new Recruit {
                        Id = recruitView.Id
                    }).ToList();

                    foreach (var partView in recruitView.SubItems)
                    {
                        partView.QuestionIds = _questionsService.FetchQuestionIdsByRecruit(new Recruit {
                            Id = partView.Id
                        }).ToList();
                    }
                }
            }


            _dataService.SaveYearRecruits(recruitViews);

            return(Ok());
        }
        async Task LoadOptionsAsync(QuestionsIndexModel model)
        {
            //Subjects
            var subjects = await _subjectsService.FetchAsync();

            subjects = subjects.GetOrdered();

            _subjectsService.LoadSubItems(subjects);
            foreach (var item in subjects)
            {
                item.GetSubIds();
            }

            model.Subjects = subjects.MapViewModelList(_mapper);


            //Recruits
            var recruits = await _recruitsService.FetchAsync();

            recruits = recruits.GetOrdered();

            _recruitsService.LoadSubItems(recruits);
            model.Recruits = recruits.MapViewModelList(_mapper);
        }