Example #1
0
        public IActionResult ViewQuestion(int testSessionId, int questionIndex, QuestionFormVM viewModel, string submit)
        {
            var hasTimeLeft = repository.EditSessionAnswers(testSessionId, questionIndex, viewModel.SelectedAnswers, viewModel.Comment);

            if (string.Equals("previous", submit, StringComparison.OrdinalIgnoreCase))
            {
                questionIndex--;
            }
            else if (string.Equals("next", submit, StringComparison.OrdinalIgnoreCase))
            {
                questionIndex++;
            }
            else if (string.Equals("submit", submit, StringComparison.OrdinalIgnoreCase))
            {
                repository.SubmitTestSession(testSessionId);
                return(RedirectToAction(nameof(SessionCompleted),
                                        new { TestSessionId = testSessionId, completedReason = (int)SessionCompletedReason.Completed }));
            }
            else
            {
                throw new Exception("Unknown submit value");
            }

            if (hasTimeLeft)
            {
                //var session = repository.GetTestSessionById(testSessionId);
                //session.SecondsLeft = secondsLeft;

                return(RedirectToAction(nameof(ViewQuestion),
                                        new { TestSessionId = testSessionId, QuestionIndex = questionIndex }));
            }
            else
            {
                return(RedirectToAction(nameof(SessionCompleted),
                                        new { TestSessionId = testSessionId, completedReason = (int)SessionCompletedReason.TimedOut }));
            }
        }