//add players public void AddPlayer(Players player) { if (CheckIfPlayerExists(player)) { throw new ArgumentException("Player with that name already exists for the current team"); } this.players.Add(player); }
private static void AddPlayerToTeam(string firstName, string lastName, DateTime birthDate, decimal salary, string teamAsString) { if (League.Teams.All(p => p.Name != teamAsString)) { throw new ArgumentException("This team does not compete in the current League"); } Teams newPLayerTeam = League.Teams.First(team => team.Name == teamAsString); Players newPlayer = new Players(firstName, lastName, birthDate, salary, newPLayerTeam); newPLayerTeam.AddPlayer(newPlayer); Console.WriteLine($"Player {newPlayer.FirstName} {newPlayer.LastName} added to team to" + $" {newPLayerTeam.Name}"); }
private bool CheckIfPlayerExists(Players player) { return this.players.Any(p => p.FirstName == player.FirstName && p.LastName == player.LastName); }