public async Task <ActionResult <Quiz_DTO> > Get(Guid id) { var result = await quizRepo.GetQuizForIdAsync(id); if (result == null) { return(BadRequest("Quiz not found")); } var obj = new Quiz_DTO(); var model = QuizMapper.ConvertQuizTo_DTO(result, ref obj, quizRepo); return(Ok(model)); }
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)); }
public async Task <IActionResult> EditQuiz(Guid id) { try { Quiz quiz = null; quiz = await quizRepo.GetQuizForIdAsync(id); if (quiz == null || id == Guid.Empty) { return(RedirectToAction(nameof(Quizzes), new { exc = "Wrong quiz Id" })); } ViewData["DifficultyId"] = quiz.DifficultyId; IEnumerable <Difficulty> difficulties = null; difficulties = await quizRepo.GetAllDifficultiesAsync(); ViewData["Difficulties"] = difficulties; return(View(quiz)); } catch (Exception exc) { return(RedirectToAction(nameof(Quizzes), new { exc = exc.Message })); } }