public async Task <ActionResult> Scoreboard() { var scores = await gameRepo.GetAllFinishedGamesAsync(); List <Scoreboard_VM> scoreboard = new List <Scoreboard_VM>(); foreach (Game score in scores) { QuizClass quiz = await quizRepo.GetQuizByIdAsync(score.QuizId); if (quiz != null) { User user = await userMgr.FindByIdAsync(score.UserId); var questions = await quizRepo.GetQuizQuestionsAsync(score.QuizId); Scoreboard_VM vm = new Scoreboard_VM() { GameId = score.GameId, QuizName = quiz.Name, UserEmail = user.Email, UserName = user.Name, correctanswers = score.CorrectAnswers, maxquestions = questions.Count(), completetime = score.TimeFinished.Value.Subtract(score.TimeStarted) }; scoreboard.Add(vm); } } return(View(scoreboard.OrderByDescending(e => e.correctanswers / e.maxquestions).ThenBy(e => e.completetime).ToList())); }
public async Task <IActionResult> GetQuiz(Guid?id) { if (id == null) { return(BadRequest("This enpoind requires a valid QuizId")); } return(Ok(await quizRepo.GetQuizByIdAsync(id ?? Guid.Empty))); //Ok()) = OkObjectResult() }
public async Task <ActionResult> EditAsync(Guid id) { if (id == null) { return(Redirect("/Error/400")); } var quiz = await quizRepo.GetQuizByIdAsync(id); if (quiz == null) { ModelState.AddModelError(String.Empty, "Not Found."); } return(View(quiz)); }
public async Task <ActionResult> Questions(Guid?id) { if (id == null) { return(Redirect("/Error/400")); } //controleren of de quiz we lbestaat QuizClass quiz = await quizRepo.GetQuizByIdAsync(id ?? Guid.Empty); if (quiz == null) { return(Redirect("/Error/0")); } var result = await quizRepo.GetQuizQuestionsAsync(id ?? Guid.Empty); ViewBag.quizId = id; return(View(result)); }
// GET: Question/Create public async Task <ActionResult> Create(Guid Id) { Quiz quiz = await quizRepo.GetQuizByIdAsync(Id); ViewBag.Quiz = quiz; AddQuestion_VM vm = new AddQuestion_VM(); vm.QuizId = quiz.QuizID; return(View(vm)); }
// GET: Play public async Task <ActionResult> IndexAsync(string Id) { if (Id == null) { return(RedirectToAction("Index")); } try { ////get quiz var quiz = await quizRepo.GetQuizByIdAsync(Guid.Parse(Id)); var EvalVm = new EvaluationVM(); EvalVm.QuizId = quiz.QuizID.ToString(); EvalVm.QuizName = quiz.QuizName; ////vragen ophalen var questions = await questionRepo.GetQuestionsByQuizAsync(quiz.QuizID); foreach (var question in questions) { //antwoord ophalen Answer answer = await answerRepo.GetAnswerByQuestionAsync(question.QuestionId); var q = new QuestionVM() { QuestionID = question.QuestionId.ToString(), QuestionText = question.QuestionText, }; q.Answers.Add(answer); //choices toevoegen IEnumerable <Choice> choices = await choiceRepo.GetChoicesAsync(question.QuestionId); List <Choice> ListChoices = choices.ToList(); //overlopen choices foreach (var c in ListChoices) { Answer choice = new Answer() { AnswerID = c.ChoiceID, AnswerText = c.ChoiceText, QuestionID = c.QuestionID }; q.Answers.Add(choice); q.Answers = q.Answers.OrderBy(m => m.AnswerText).ToList(); } EvalVm.Questions.Add(q); } return(View(EvalVm)); } catch (Exception) { throw; } }
public async Task <ActionResult> EditQuizAsync(Guid Id) { try { if (Id == null) { return(RedirectToAction("Quizzes")); } Quiz quiz = await quizRepo.GetQuizByIdAsync(Id); var subjects = await subjectRepo.GetSubjectsAsync(); AddQuiz_VM vm = new AddQuiz_VM() { ImgUrl = quiz.ImgUrl, QuizID = quiz.QuizID, Description = quiz.Description, Difficulty = quiz.Difficulty, QuizName = quiz.QuizName, SubjectId = quiz.SubjectId, Subjects = new List <Subject>(), }; foreach (var item in subjects) { vm.Subjects.Add(item); } return(View(vm)); } catch (Exception ex) { Debug.WriteLine($"update error. {ex.Message}"); ModelState.AddModelError("", "Update actie mislukt." + ex.InnerException.Message); return(RedirectToAction(nameof(Quizzes))); } }