Example #1
0
        public async Task <IActionResult> Passing(int testId, int?questionId)
        {
            if (questionId == null)
            {
                await _testsManager.CheckLastQuestion(testId);

                await _testsManager.CheckUserTest(testId, GetUserId());
            }

            if (await _testsManager.CheckUserAnswer(testId, questionId, GetUserId()))
            {
                return(RedirectToAction("Index"));
            }

            var test = await _db.Tests
                       .Include(t => t.TestQuestions)
                       .ThenInclude(tq => tq.TestAnswers)
                       .SingleOrDefaultAsync(t => t.Id == testId);

            if (test == null)
            {
                return(NotFound());
            }

            var testQuestion = questionId == null
                ? test.TestQuestions.First()
                : test.TestQuestions.SingleOrDefault(q => q.Id == questionId);

            if (testQuestion == null)
            {
                return(NotFound());
            }

            ViewBag.QuestionNumber = test.TestQuestions.IndexOf(testQuestion) + 1;
            _testsManager.MixTestAnswers(testQuestion.TestAnswers);

            var userAnswer = new UserAnswer
            {
                TestQuestion   = testQuestion,
                TestQuestionId = testQuestion.Id
            };

            return(View(userAnswer));
        }