Beispiel #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));
        }
Beispiel #2
0
        public PartialViewResult NextQuestion()
        {
            var gameState = Session["GameState"] as GamePlayState;


            var question = gameState.QuestionsLeft.FirstOrDefault();

            if (question != null)
            {
                var model = new QuestionViewModel();
                model.Question = question;
                model.Answers  = question.Answers.ToList();
                model.Answers.Shuffle();
                model.Total = gameState.QuestionTotalCount;
                model.Index = gameState.QuestionTotalCount - gameState.QuestionsLeft.Count + 1;

                gameState.CurrentQuestion = model;

                return(PartialView("_Question", model));
            }


            var game   = QuizDb.QuizGames.SingleOrDefault(x => x.Id == gameState.Game.Id);
            var player = QuizDb.GamePlayers.SingleOrDefault(x => x.Id == gameState.Player.Id);

            var statisticsService = new GameStatisticsService(gameState.Quiz.Id, player.UserId);

            var statistics = statisticsService.GetStatistics(game.Id);

            return(PartialView("_EndGame", statistics));
        }
Beispiel #3
0
        public IHttpActionResult GetQuizGameResult(Guid?gameId, Guid?playerId)
        {
            var QuizDb = new QuestDbContext();

            var result = new QuizGameResult();

            if (gameId.HasValue && playerId.HasValue)
            {
                var game   = QuizDb.QuizGames.SingleOrDefault(x => x.Id == gameId.Value);
                var player = QuizDb.GamePlayers.SingleOrDefault(x => x.Id == playerId.Value);

                // Die Antwort

                if (game != null && player != null)
                {
                    result.GameId   = game.Id;
                    result.PlayerId = player.Id;
                    result.QuizId   = game.Levels.First().Quiz.Id;

                    var service = new GameStatisticsService(result.QuizId, player.UserId);

                    var statistics = service.GetStatistics(game.Id);
                    result.QuestionCount      = statistics.TotalQuestionCount;
                    result.CorrectAnswerCount = statistics.CorrectAnswerCount;
                    result.PersonalRank       = service.GetPersonalRank(result.CorrectAnswerCount);
                    result.TotalRank          = service.GetTotalRank(result.CorrectAnswerCount);

                    result.Message = "OK";
                }
                else
                {
                    var sb = new StringBuilder();
                    if (game == null)
                    {
                        sb.Append("Spiel fehlt");
                    }
                    if (player == null)
                    {
                        sb.Append("Spieler fehlt");
                    }
                    result.Message = sb.ToString();
                }
            }
            else
            {
                result.Message = "Falsche Parameter";
            }

            return(Ok(result));
        }
Beispiel #4
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));
        }