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.") },
private static void Answer(Answer command, GeneralQuestionSagaEntity generalQuestionSagaEntity) { generalQuestionSagaEntity.Answer = command.Value; generalQuestionSagaEntity.Result = null; }