public void BuyPlayer(int playerId, int teamId) { Player player = playerStorage.GetPlayerById(playerId); TeamDataLogic teamDataLogic = new TeamDataLogic(); TeamData teamData = teamDataLogic.GetTeamData(teamId); int playersNumber = teamData.PlayersNumber; if (playersNumber == 11) { throw new Exception("Команда полностью укомплектована"); } TeamPlayerLogic teamPlayerLogic = new TeamPlayerLogic(); int budget = teamData.Budget; if (budget < player.Price) { throw new Exception("Недостаточно денежных средств"); } TeamPlayer teamPlayer = new TeamPlayer { Age = player.Age, Name = player.Name, Position = player.Position, Atack = player.Atack, Defence = player.Defence, Price = player.Price, TeamId = teamId, Number = playersNumber + 1 }; teamPlayerLogic.AddTeamPlayer(teamId, teamPlayer); teamDataLogic.UpdateBudget(budget - player.Price, teamId); teamDataLogic.UpdatePlayerNumber(teamId); }
public void BuyPlayer(int playerId, int teamId) { Player player = playerStorage.GetPlayerById(playerId); TeamDataLogic teamDataLogic = new TeamDataLogic(); TeamData teamData = teamDataLogic.GetTeamData(teamId); int playersNumber = teamData.PlayersNumber; if (playersNumber == 11) throw new Exception("Команда полностью укомплектована"); TeamPlayerLogic teamPlayerLogic = new TeamPlayerLogic(); int budget = teamData.Budget; if (budget < player.Price) throw new Exception("Недостаточно денежных средств"); TeamPlayer teamPlayer = new TeamPlayer { Age = player.Age, Name = player.Name, Position = player.Position, Atack = player.Atack, Defence = player.Defence, Price = player.Price, TeamId = teamId, Number = playersNumber + 1 }; teamPlayerLogic.AddTeamPlayer(teamId, teamPlayer); teamDataLogic.UpdateBudget(budget - player.Price, teamId); teamDataLogic.UpdatePlayerNumber(teamId); }
public void UpdateDefence(int playerId) { TeamPlayer teamPlayer = teamPlayerStorage.GetPlayerById(playerId); TeamDataLogic dataLogic = new TeamDataLogic(); int currentBudget = dataLogic.GetTeamData(teamPlayer.TeamId).Budget; if (teamPlayer == null) throw new Exception("Такого футболиста нет"); if (currentBudget < 1000) throw new Exception("Недостаточно средств"); teamPlayer.Defence++; dataLogic.UpdateBudget(currentBudget - 1000, teamPlayer.TeamId); teamPlayerStorage.UpdatePlayer(playerId, teamPlayer); }
public void UpdateDefence(int playerId) { TeamPlayer teamPlayer = teamPlayerStorage.GetPlayerById(playerId); TeamDataLogic dataLogic = new TeamDataLogic(); int currentBudget = dataLogic.GetTeamData(teamPlayer.TeamId).Budget; if (teamPlayer == null) { throw new Exception("Такого футболиста нет"); } if (currentBudget < 1000) { throw new Exception("Недостаточно средств"); } teamPlayer.Defence++; dataLogic.UpdateBudget(currentBudget - 1000, teamPlayer.TeamId); teamPlayerStorage.UpdatePlayer(playerId, teamPlayer); }