Example #1
0
        public async Task <Player> CalculateAverageRankForPlayer(int playerId)
        {
            var playerRanksForPlayer = await _playerRankService.GetAllPlayerRanksForPlayer(playerId);

            int sum = 0;

            foreach (var playerRankForPlayer in playerRanksForPlayer)
            {
                sum = sum + playerRankForPlayer.Rank;
            }
            var avgRank = decimal.Divide(sum, playerRanksForPlayer.Count);

            return(await saveAverageRank(playerId, avgRank));
        }
Example #2
0
        public async Task <IActionResult> GetAllPlayerRanksForPlayer(int playerId)
        {
            try
            {
                var players = await _playerRankService.GetAllPlayerRanksForPlayer(playerId);

                _log.LogInformation($"Returning {players.Count} playerRanks for player with id {playerId}");
                return(Ok(players));
            }
            catch (Exception ex)
            {
                _log.LogError($"Something went wrong: {ex}");
                return(StatusCode(500, ex));
            }
        }