Exemple #1
0
        public async Task <IActionResult> EndQuiz()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            Quiz quiz = await quizRepo.GetQuizForIdAsync(QuizController.QuizId);

            Result result = new Result()
            {
                Id     = Guid.NewGuid(),
                Score  = QuizController.score,
                QuizId = QuizController.QuizId,
                Quiz   = quiz
            };
            string personId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            Person person   = await userManager.FindByIdAsync(personId);

            result.Person              = person;
            ViewData["MaxScore"]       = QuizController.potentialScore;
            ViewData["PersonName"]     = person.Name;
            ViewData["QuizName"]       = quiz.Subject;
            ViewData["WrongQuestions"] = QuizController.wrongQuestions;
            var created = await quizRepo.AddResult(result);

            if (created == null)
            {
                throw new Exception("Invalid Entry");
            }
            return(View(result));
        }