public async Task <QuizNextQuestionDto> NextQuestion(long quizId, long personId, QuizQuestionAnswerDto answersToPreviousQuestion) { var quiz = await _context.Quizzes.FirstOrDefaultAsync(q => q.Id == quizId); if (quiz == null) { throw new QuizNotFoundException(quizId); } var person = await _context.People.FirstOrDefaultAsync(p => p.Id == personId); if (person == null) { throw new PersonNotFoundException(quizId); } var answerIds = new HashSet <long>(answersToPreviousQuestion.AnswerIds); var answers = _context.QuizAnswers.Where(a => answerIds.Contains(a.Id)); //Record the person's answer(s) var responseString = _quizManager.QuestionResponse(person, answers); //Get the next question for the person var questions = await _context.QuizQuestions.ToListAsync(); var personAnswers = await _context.PersonAnswers.ToListAsync(); var question = _quizManager.NextQuestion(quiz, person, questions, personAnswers); var questionDto = question.ToDto(_quizManager); return(new QuizNextQuestionDto { NextQuestion = questionDto, PreviousQuestionAnswerResponse = responseString }); }