public async Task <IActionResult> Get(string name) { var gamertag = User.GetGamerTag(); _appMonitor.LogEvent("Leaderboard", properties: new Dictionary <string, string> { { "Name", name } }); LeaderboardConfig config = _leaderboardProvider.GetByName(name); if (config == null) { return(NotFound()); } LeaderboardType type = config.Type; List <GameScore> scores; switch (type) { case LeaderboardType.AroundMe: if (gamertag == null) { return(this.ValidationFailed(new ErrorDetail("gamertag", "Must be signed in as a player with a gamertag to retrive this leaderboard"))); } scores = await _store.GetScoresAroundMeAsync(gamertag, config.Radius); break; case LeaderboardType.Top: scores = await _store.GetTopHighScoresAsync(config.Top); break; default: scores = await _store.GetAllHighScoresAsync(); break; } GameScore currentPlayer = null; if (config.IncludeCurrentPlayer && gamertag != null) { currentPlayer = (await _store.GetScoresAroundMeAsync(gamertag, 0)).FirstOrDefault(); } // Format response model var resultModel = new LeaderboardGetResponseModel { Entries = scores ?.Select(s => LeaderboardGetResponseModel.LeaderboardEntry.Map(s, gamertag)) ?.ToList(), CurrentPlayer = LeaderboardGetResponseModel.LeaderboardEntry.Map(currentPlayer, null) }; // Return result return(Ok(resultModel)); }
public async Task <IActionResult> Get(string name) { var gamertag = User.GetGamerTag(); LeaderboardConfig config = _leaderboardConfiguration.GetByName(name); if (config == null) { return(NotFound()); } LeaderboardType type = config.Type; List <GameScore> scores; switch (type) { case LeaderboardType.AroundMe: if (gamertag == null) { return(BadRequest()); // need a gamertag to get scores! } scores = await _store.GetScoresAroundMeAsync(gamertag, config.Radius); break; case LeaderboardType.Top: scores = await _store.GetTopHighScoresAsync(config.Top); break; default: scores = await _store.GetAllHighScoresAsync(); break; } GameScore currentPlayer = null; if (config.IncludeCurrentPlayer && gamertag != null) { currentPlayer = (await _store.GetScoresAroundMeAsync(gamertag, 0)).FirstOrDefault(); } // Format response model var resultModel = new LeaderboardGetResponseModel { Entries = scores ?.Select(s => LeaderboardGetResponseModel.LeaderboardEntry.Map(s, gamertag)) ?.ToList(), CurrentPlayer = LeaderboardGetResponseModel.LeaderboardEntry.Map(currentPlayer, null) }; // Return result return(Ok(resultModel)); }
public async Task <ActionResult> Get(string name) { //TODO var gamerTag = User.GetGamerTag(); LeaderboardConfig config = _configuration.GetLeaderboardConfig(name); LeaderboardType type = config.Type; List <GameScore> scores; switch (type) { case LeaderboardType.AroundMe: scores = await _store.GetScoresAroundMeAsync(gamerTag, config.Radius); break; case LeaderboardType.Top: scores = await _store.GetTopHighScoresAsync(config.Top); break; default: scores = await _store.GetAllHighScoresAsync(); break; } // Format response model var resultModel = new LeaderboardGetResponseModel { Entries = scores == null ? null : scores.Select(s => (LeaderboardGetResponseModel.LeaderboardEntry)s).ToList() }; // Return result return(Ok(resultModel)); }