Ejemplo n.º 1
0
        async Task <RQViewModel> GetRQModelAsync(Recruit recruit, Subject subject)
        {
            var model = new RQViewModel();

            var parts = recruit.SubItems;

            if (parts.HasItems())
            {
                foreach (var part in parts)
                {
                    var questions = await _questionsService.FetchByRecruitAsync(part, subject);

                    var partView = new RQPartViewModel
                    {
                        Points       = part.Points,
                        Order        = part.Order,
                        MultiAnswers = part.MultiAnswers,
                        OptionCount  = part.OptionCount,
                        OptionType   = part.OptionType.ToString(),
                        Title        = part.Title
                    };
                    partView.Questions = questions.MapViewModelList(_mapper);
                    model.Parts.Add(partView);
                }
            }
            else
            {
                var questions = await _questionsService.FetchByRecruitAsync(recruit, subject);

                var partView = new RQPartViewModel
                {
                    Points       = recruit.Points,
                    MultiAnswers = recruit.MultiAnswers,
                    OptionCount  = recruit.OptionCount,
                    OptionType   = recruit.OptionType.ToString(),
                    Title        = recruit.Title
                };
                partView.Questions = questions.MapViewModelList(_mapper);
                model.Parts.Add(partView);
            }

            model.Recruit = recruit.MapViewModel(_mapper);
            model.LoadTitle();

            return(model);
        }
Ejemplo n.º 2
0
        public static RecruitQuestionAnalysisView MapViewModel(this RecruitQuestionAnalysisView model,
                                                               Recruit recruit, ICollection <Subject> subjects, IMapper mapper)
        {
            model.Recruit = recruit.MapViewModel(mapper);
            model.Subject = subjects.FirstOrDefault(x => x.Id == model.SubjectId).MapViewModel(mapper);

            var subjectIds       = model.SummaryList.Select(item => item.SubjectId).ToList();
            var selectedSubjects = subjects.Where(x => subjectIds.Contains(x.Id));

            var subjectViews = selectedSubjects.MapViewModelList(mapper);

            foreach (var summary in model.SummaryList)
            {
                summary.Subject = subjectViews.FirstOrDefault(x => x.Id == summary.SubjectId);
            }

            return(model);
        }