コード例 #1
0
        private async Task ProcessFinishedGame(IGame game, string userId, AnswerCallBackViewModel answerCallbackVM)
        {
            var gameResult = game.GetGameResult();

            if (userId != Request.AnonymousID)
            {
                await
                    _userDataAccess.SaveGameResult(long.Parse(userId), game.GameQuestionsCount,
                        game.GetGameResult())
                        .ConfigureAwait(false);
            }
            else
            {
                answerCallbackVM.demoMode = "true";
            }

            answerCallbackVM.hasNextQuestion = false;
            answerCallbackVM.gameResult = new EndGameViewModel
            {
                rightAnswersCount = gameResult,
                allAnswersCount = game.GameQuestionsCount,
                demoMode = userId == HttpContext.Request.AnonymousID,
                answers = game.GetGameAnswers().Select(i => new UserAnswer()
                {
                    answer = i.UserAnswer,
                    rightAnswer = i.RightAnswer,
                    pictureUrl = i.Picture.ImageUrl,
                    isRightAnswer = i.QuestionResult.Value,
                    pictureName = i.Picture.Name,
                    pictureLink = i.Picture.ImageUrl
                }).ToArray()
            };
        }