예제 #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));
        }
        public async Task <IActionResult> Results()
        {
            var interviews = await _interviewService.GetPassedInterviewsAsync();

            var candidates = await _userService.GetCandidatesAsync();

            if (interviews?.Any() != true || candidates?.Any() != true)
            {
                return(RedirectToAction(nameof(HomeController.Error)));
            }

            var viewModels = new List <ResultViewModel>();

            foreach (var interview in interviews)
            {
                var candidate = candidates.FirstOrDefault(e => e.Id == interview.CandidateId);

                if (candidate != null)
                {
                    var exam = await _interviewService.GetExamAsync(interview.ExamId);

                    viewModels.Add(ViewModelBuilder.GetResultViewModels(interview, candidate, exam));
                }
            }

            return(View(viewModels.OrderByDescending(e => e.Score).ToList()));
        }