private async Task <List <int> > CreateUserAnswersAndGetQuestionIdsSortedByStageAsync(int testId, int userId) { var questionIds = new List <int>(); int stagesCount = (await _questionManager.GetTestStagesByTestIdAsync(testId)).ToList().Count; for (int stage = 1; stage <= stagesCount; stage++) { int questionId = (await _questionManager.GetRandomQuestionInTestByStageAsync(testId, stage)).Id; List <DomainAnswer> answers = (await _answersManager.GetAnswersByQuestionIdAsync(questionId)).ToList(); foreach (DomainAnswer answer in answers) { var userAnswer = new DomainUserAnswer { isValid = false, Text = string.Empty, UserId = userId, AnswerId = answer.Id }; if (!await _answersManager.IsUserAnswerExistsAsync(userId, answer.Id)) { await _answersManager.CreateUserAnswerAsync(userAnswer); } } questionIds.Add(questionId); } return(questionIds); }