Exemple #1
0
        public async Task <List <TeamPlayer> > SplitTeams(List <int> playerIds, int teamAId, int teamBId)
        {
            foreach (var playerId in playerIds)
            {
                await _playerService.CalculateAverageRankForPlayer(playerId);
            }
            var     players = new List <Player>();
            decimal sum     = 0;

            foreach (var playerId in playerIds)
            {
                var player = await _playerRepository.GetPlayerById(playerId);

                players.Add(player);
                if (player.AverageRank != null)
                {
                    sum = sum + player.AverageRank.Value;
                }
            }
            //Teams are ok
            var teamsPlayers = CalculateEqualTeams(players, teamAId, teamBId);
            await _matchRepository.CreateMatch(new Match()
            {
                TeamA = await _repository.GetTeamById(teamAId),
                TeamB = await _repository.GetTeamById(teamBId)
            });

            return(await SaveTeamPlayers(teamsPlayers));
        }
        public async Task <IActionResult> CalculateAverageRankForPlayer(int playerId)
        {
            try
            {
                var averageRank = await _playerService.CalculateAverageRankForPlayer(playerId);

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