Ejemplo n.º 1
0
        public async Task <IActionResult> Exam(int id)
        {
            var interview = await _interviewService.GetInterviewAsync(id);

            var exam = await _interviewService.GetExamAsync(interview.ExamId);

            var candidate = await _userService.GetCandidateAsync(interview.CandidateId);

            if (exam == null || candidate == null)
            {
                return(RedirectToAction(nameof(HomeController.Error)));
            }

            var answers       = new List <Answer>();
            var examQuestions = await _interviewService.GetQuestionsForExamAsync(interview.ExamId);

            if (examQuestions?.Any() == true)
            {
                foreach (var question in examQuestions)
                {
                    var questionAnswers = await _interviewService.GetAnswersForQuestionAsync(question.Id);

                    if (questionAnswers?.Any() == true)
                    {
                        answers.AddRange(questionAnswers);
                    }
                }
            }

            var viewModel = ViewModelBuilder.GetExamViewModel(interview, exam, candidate, examQuestions, answers);

            return(View(viewModel));
        }