Example #1
0
        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()));
        }