public async Task <IActionResult> EditQuestion(Guid id) { Question question = await quizRepo.GetQuestionForIdAsync(id); if (question == null || id == Guid.Empty) { return(RedirectToAction(nameof(Quizzes), new { exc = "Wrong QuestionId" })); } ViewData["QuizId"] = question.QuizId; return(View(question)); }
public async Task <IActionResult> ShowQuestion() { IEnumerable <Question> questions = await quizRepo.GetAllQuestionsByQuizId(QuizController.QuizId); List <Question> questionsList = questions.ToList(); List <Question> wrongQuestions = new List <Question>(); //Antwoorden checken of question inorde is foreach (Question q in questionsList) { IEnumerable <Answer> answers = await quizRepo.GetAllAnswersByQuestionId(q.Id); bool error = false; if (answers.Count() < 2) { error = true; } else { int countTrues = 0; bool onlyDiscriptions = true; bool onlyPhotos = true; foreach (Answer answer in answers) { if (answer.Correct.ToString() == "True") { countTrues = countTrues + 1; } if (answer.Description == null) { onlyDiscriptions = false; } if (answer.FotoURL == null) { onlyPhotos = false; } } if (!onlyDiscriptions && !onlyPhotos) { error = true; } if (countTrues == 0) { error = true; } else if (countTrues > 1) { error = true; } } if (error) { wrongQuestions.Add(q); } } foreach (Question q in wrongQuestions) { questionsList.Remove(q); } double progressPercentage = Math.Floor((double.Parse(QuizController.currentQuestion.ToString()) / float.Parse(questionsList.Count().ToString())) * 100); ViewData["ProgressPercentage"] = progressPercentage; ViewData["PotentialScore"] = QuizController.potentialScore; ViewData["Score"] = QuizController.score; if (QuizController.currentQuestion == questionsList.Count()) { return(RedirectToAction(nameof(EndQuiz))); } Question question = await quizRepo.GetQuestionForIdAsync(questionsList[QuizController.currentQuestion].Id); return(View(question)); }