Пример #1
0
        public IActionResult PassTestQuestion(int id, int questionOrderId = 0)
        {
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            string userId            = userIdenityManager.GetUserId(currentUser);
            bool   isNotAccessDenied = testResultManager.CheckIfTestForUserId(id, userId);

            if (!isNotAccessDenied)
            {
                return(View("AccessDenied"));
            }

            bool toFinishTest = testResultManager.CheckTestResultIsClosed(id);

            if (toFinishTest)
            {
                testResultManager.FinishTestResult(id);
                return(RedirectToAction("ShowResult", new { @id = id }));
            }

            GivenQuestionDTO model = testResultManager.GetGivenQuestionByTestIdAndQuestionOrderId(id, questionOrderId);
            int questionsCount     = testResultManager.GetByID(model.TestResultId).Questions.Count;

            PrepareQuestionTextAndAnswers(model.Question);

            TestQuestionViewModel testQuestion = new TestQuestionViewModel
            {
                Question             = model,
                CurrentQuestionOrder = questionOrderId,
                QuestionsCount       = questionsCount,
                GivenAnswers         = testResultManager.GetGivenAnswers(id),
                MaxTimeEnd           = testResultManager.GetMaxTimeEnd(id)
            };

            return(View(testQuestion));
        }
Пример #2
0
        public GivenQuestionDTO GetGivenQuestionByTestIdAndQuestionOrderId(int id, int questionOrderId)
        {
            var entity          = uOw.TestResultRepo.GetByID(id);
            var firstQuestionId = entity.Questions.FirstOrDefault().Id;
            var targetQuestion  = entity.Questions.FirstOrDefault(x => x.Id == (questionOrderId + firstQuestionId));

            return(GivenQuestionDTO.ConvertFromEntity(targetQuestion));
        }