public Question GetNextQuestion(int questionId, int answerId, int sessionId) { var hasInteractions = _myRepository.ValidateUserAndCheckAnyInteractions(sessionId); if (!hasInteractions) { var isFirstQuestionOfQuestionnaire = _myRepository.CheckFirstQuestionOfQuestionnaire(questionId, answerId); if (!isFirstQuestionOfQuestionnaire) { throw new Exception("Answer is not to the first question."); } } else { var isCorrectSequenceOfQuestions = _myRepository.CheckIsCorrectSequenceOfQuestions(questionId, answerId, sessionId); if (!isCorrectSequenceOfQuestions) { throw new Exception("Wrong sequence of questions."); } } _myRepository.SubmitAnswer(questionId, answerId, sessionId); var nextQuestion = _myRepository.GetNextQuestion(answerId); return(nextQuestion); }