Esempio n. 1
0
        public async Task <IActionResult> Post([FromBody] ScorePostRequestModel request)
        {
            //TODO: Make validation more sophisticated, perhaps some games want/need negative scores
            // Validate input
            if (request.Score < 0)
            {
                _logger.LogError("score is negative ({0})", request.Score);
                return(this.ValidationFailed(new ErrorDetail("score", "Score cannot be negative")));
            }

            //TODO: Handle exceptions and retries
            var gamertag = User.GetGamerTag();

            if (string.IsNullOrWhiteSpace(gamertag))
            {
                _logger.LogError("user has no gamertag: '{0}'", User.GetId());
                return(this.ValidationFailed(new ErrorDetail("gamertag", "The user doesn't have a gamertag")));
            }

            // Save score and call analytics in parallel
            await Task.WhenAll(
                _store.SaveScoreAsync(new GameScore
            {
                Gamertag  = gamertag,
                Country   = request.Country,
                CustomTag = request.CustomTag,
                Score     = request.Score
            }),
                SendScoreEventAndLogErrors(request));

            // Return result
            return(Ok());
        }
Esempio n. 2
0
        public async Task <ActionResult> Post([FromBody] LeaderboardPostRequestModel request)
        {
            //TODO: Make validation more sophisticated, perhaps some games want/need negative scores
            // Validate input
            if (request.Score < 0)
            {
                _log.LogError("score is negative ({0})", request.Score);
                return(BadRequest()); //TODO: return error info in body
            }

            //TODO: Handle exceptions and retries
            var gamertag = User.GetGamerTag();

            if (string.IsNullOrWhiteSpace(gamertag))
            {
                _log.LogError("user has no gamertag: '{0}'", User.GetId());
                return(BadRequest()); //TODO: return error info in body
            }

            // Save score and call analytics in parallel
            await Task.WhenAll(
                _store.SaveScoreAsync(new GameScore
            {
                GamerTag  = gamertag,
                Country   = request.Country,
                CustomTag = request.CustomTag,
                Score     = request.Score
            }),
                _analyticsIntegrationClient.SendGameEventAsync(new ScoreEvent()
            {
                //GamerTag = gamertag,
                ClientUtcTime = DateTime.UtcNow,
                GameSessionId = "unknowngamesession",
                Score         = request.Score
            }));

            // Return result
            return(Ok());
        }