Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        // GET: Quiz/Statistics
        public ActionResult Personal(Guid?id)
        {
            var quiz = GetQuiz(id);
            var user = GetCurrentUser();

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

            var myGames = service.GetMyGames();

            var model = new QuizGameStatisticsViewModel();

            model.Quiz = quiz;

            foreach (var game in myGames)
            {
                model.Games.Add(service.GetStatistics(game.Id));
            }


            return(View(model));
        }