//Answers public async Task <IActionResult> QuestionAnswers(Guid id, Guid QuizId, string QuestionName) { try { Quiz quiz = await quizRepo.GetQuizForIdAsync(QuizId); if (quiz == null || QuizId == Guid.Empty) { return(RedirectToAction(nameof(Quizzes), new { exc = "Wrong QuizId" })); } Question question = await quizRepo.GetQuestionForIdAsync(id); if (question == null || id == Guid.Empty) { return(RedirectToAction(nameof(Quizzes), new { exc = "Wrong QuestionId" })); } ViewData["QuestionId"] = id; ViewData["QuizId"] = QuizId; IEnumerable <Answer> answers = await quizRepo.GetAllAnswersByQuestionId(id); ViewData["QuestionName"] = QuestionName; return(View(answers)); } catch (Exception exc) { return(RedirectToAction(nameof(Quizzes), new { exc = exc.Message })); } }
public async Task <IActionResult> Quizzes() { QuizController.score = 0; QuizController.currentQuestion = 0; QuizController.potentialScore = 0; QuizController.wrongQuestions = new List <Question>(); IEnumerable <Quiz> quizzes = null; quizzes = await quizRepo.GetAllQuizzesAsync(); foreach (Quiz quiz in quizzes) { foreach (Question question in quiz.Questions) { IEnumerable <Answer> answersEnum = await quizRepo.GetAllAnswersByQuestionId(question.Id); List <Answer> answers = answersEnum.ToList(); question.Answers = answers; } } return(View(quizzes)); }
public async static Task <Question_DTO> ConvertQuestionTo_DTO(Question question, Question_DTO question_DTO, IQuizRepo quizRepo) { question_DTO.Id = question.Id; question_DTO.Description = question.Description; var result = await quizRepo.GetAllAnswersByQuestionId(question.Id); List <Answer_DTO> answer_DTOs = new List <Answer_DTO>(); //Answers foreach (Answer answer in result) { var obj = new Answer_DTO(); answer_DTOs.Add(ConvertAnswerTo_DTO(answer, ref obj)); } question_DTO.Answers = answer_DTOs; return(question_DTO); }