Exemplo n.º 1
0
        public ActionResult Total(Guid?id)
        {
            var quiz = GetQuiz(id);
            var user = GetCurrentUser();

            var service = new GameStatisticsService(quiz.Id, user.Id);

            var myGames = service.GetTotalGames();

            var model = new QuizGameStatisticsViewModel();

            model.Quiz = quiz;

            foreach (var game in myGames)
            {
                if (game.Players.Any())
                {
                    var stat = service.GetStatistics(game.Id, game.Players.First().UserId);
                    if (stat != null)
                    {
                        model.Games.Add(stat);
                    }
                }
            }


            return(View(model));
        }
Exemplo n.º 2
0
        public IHttpActionResult GetGameList(string userId)
        {
            var model = new GameList();

            model.Games = new List <GameSummary>();

            var quizzes = quizDb.Quizzes.Where(x => x.IsPubslished).ToList();

            foreach (var quiz in quizzes)
            {
                var statisticsService = new GameStatisticsService(quiz.Id, userId);

                // TODO: Liste auswerten
                var gameModel = new GameSummary();

                gameModel.Name           = quiz.Name;
                gameModel.QuizId         = quiz.Id;
                gameModel.QuestionCount  = statisticsService.GetQuestions().Count;
                gameModel.MyGameCount    = statisticsService.GetMyGames().Count;        // wie oft habe ich gespielt
                gameModel.TotalGameCount = statisticsService.GetTotalGames().Count;

                var bestGame = statisticsService.GetBestGame();
                if (bestGame != null)
                {
                    gameModel.BestGame = new GameApproach
                    {
                        PlayDateTime = bestGame.Game.CreatedAt,
                        Rank         = 0,
                        Score        = bestGame.CorrectAnswerCount
                    };
                }

                var lastGame = statisticsService.GetLastGame();
                if (lastGame != null)
                {
                    gameModel.LastGame = new GameApproach
                    {
                        PlayDateTime = lastGame.Game.CreatedAt,
                        Rank         = 0,
                        Score        = lastGame.CorrectAnswerCount
                    };
                }

                model.Games.Add(gameModel);
            }



            return(Ok(model));
        }