Exemple #1
0
        public GameStatistics GetBestGame()
        {
            GameStatistics bestStatistics = null;

            foreach (var game in games)
            {
                var statistics = GetStatistics(game.Id);
                if (bestStatistics == null ||
                    bestStatistics.CorrectAnswerCount < statistics.CorrectAnswerCount)
                {
                    bestStatistics = statistics;
                }
            }

            return(bestStatistics);
        }
Exemple #2
0
        public GameStatistics GetStatistics(Guid gameId, string userId)
        {
            var game = quizDb.QuizGames.SingleOrDefault(x => x.Id == gameId);

            if (game == null)
            {
                return(null);
            }


            var statistics = new GameStatistics();

            statistics.Game = game;
            statistics.TotalQuestionCount = GetQuestions().Count;
            statistics.CorrectAnswerCount = quizDb.GameLogs.Count(x => x.Game.Id == gameId &&
                                                                  x.Player.UserId.Equals(userId) &&
                                                                  x.Answer.IsCorrect);
            statistics.AnswerCount = quizDb.GameLogs.Count(x => x.Game.Id == gameId &&
                                                           x.Player.UserId.Equals(userId));

            statistics.ItIsMe = userId.Equals(_userId);

            return(statistics);
        }