private static void Answer(Answer command, SelectQuestionSagaEntity selectQuestionSagaEntity,
                                   QuestionSagaEntity currentQuestion)
        {
            selectQuestionSagaEntity.SelectedOptions = command.Values.Select(value =>
                                                                             ((SelectQuestionEntity)currentQuestion.Question)
                                                                             .Options
                                                                             .Single(option => option.Id == value))
                                                       .ToList();

            selectQuestionSagaEntity.Result = selectQuestionSagaEntity
                                              .SelectedOptions
                                              .All(option => option.IsCorrect);
        }
Exemple #2
0
        public async Task Handle(StartInterview request)
        {
            var interview = await _interviewRepository.Get(request.InterviewId.Value);

            var vacancy = await _vacancyRepository.Get(interview.VacancyId);

            interview.Status         = InterviewStatusEntity.Started;
            interview.FormSagaEntity = new FormSagaEntity
            {
                Questions = vacancy.Form.Questions
                            .Select(question =>
                {
                    QuestionSagaEntity saga;
                    switch (question)
                    {
                    case InputQuestionEntity input:
                        saga = new InputQuestionSagaEntity();
                        break;

                    case SelectQuestionEntity select:
                        saga = new SelectQuestionSagaEntity();
                        break;

                    case GeneralQuestionEntity general:
                        saga = new GeneralQuestionSagaEntity();
                        break;

                    default:
                        throw new InvalidOperationException($"Can't convert '{question.GetType().FullName}'");
                    }

                    saga.QuestionId = question.Id;
                    saga.Status     = QuestionSagaStatusEntity.NotStarted;

                    return(saga);
                })
                            .ToList()
            };

            await _unitOfWork.SaveChangesAsync();
        }
    }
        public async Task <GetInterviewResult> Handle(GetInterview query)
        {
            var interview = await _interviewRepository.Get(query.InterviewId.Value);

            return(new GetInterviewResult
            {
                JobPositionTitle = interview.Vacancy.JobPosition.Title,
                TeamTitle = interview.Vacancy.Team.Title,
                FullName = interview.Candidate.FirstName + " " + interview.Candidate.LastName,
                CorrectAnswersCount = interview.Result.CorrectAnswersCount,
                IncorrectAnswersCount = interview.Result.IncorrectAnswersCount,
                Email = interview.Candidate.Email,
                CityTitle = interview.Vacancy.Team.City.Name,
                Phone = interview.Candidate.Phone,
                Questions = interview.GetQuestions()
                            .Select(q => new Question
                {
                    Title = q.Question.Title,
                    Answer = q switch {
                        SelectQuestionSagaEntity select => string.Join(", ", select.SelectedOptions.Select(o => o.Title)),
                        InputQuestionSagaEntity input => input.Answer,
                        GeneralQuestionSagaEntity general => general.Answer,
                        _ => throw new InvalidOperationException($"Can't get answer for '{q.GetType().Name}' question.")
                    },