Ejemplo n.º 1
0
        public override string Execute()
        {
            string toReturn = default(string);

            try
            {
                string teamName = this.CommandTokens[0];

                // Check if team exists
                IFootballTeam team = this.FootballTeamCollection.Teams.FirstOrDefault(n => n.Name == teamName);

                if (team == null)
                {
                    throw new MissingTeamException(this.CommandTokens[0]);
                }

                // Check if team has player
                string  playerToRemove = this.CommandTokens[1];
                IPlayer player         = team.Players.FirstOrDefault(n => n.Name == playerToRemove);

                if (player == null)
                {
                    throw new MissingPlayerException(playerToRemove, teamName);
                }

                // Remove player
                team.Players.Remove(player);
            }
            catch (Exception e)
            {
                toReturn = e.Message;
            }

            return(toReturn);
        }
        public override string Execute()
        {
            string toReturn = default(string);

            try
            {
                string teamName = this.CommandTokens[0];

                // Check if team exists
                IFootballTeam team = this.FootballTeamCollection.Teams.FirstOrDefault(n => n.Name == teamName);

                if (team == null)
                {
                    throw new MissingTeamException(this.CommandTokens[0]);
                }

                // Calculate rating
                var rating = team.Players.Select(s => s.Stats.Average(p => p.Value)).DefaultIfEmpty().First();

                toReturn = $"{team.Name} - {(int)Math.Round(rating)}";
            }
            catch (Exception e)
            {
                toReturn = e.Message;
            }

            return(toReturn);
        }
        public override string Execute()
        {
            string toReturn = default(string);

            try
            {
                IFootballTeam team = this.FootballTeamCollection.Teams.FirstOrDefault(n => n.Name == this.CommandTokens[0]);

                if (team == null)
                {
                    throw new MissingTeamException(this.CommandTokens[0]);
                }

                string playerName = this.CommandTokens[1];

                // Create all stats
                IList <IStats> stats = new List <IStats>();

                for (int i = 2, j = 0; i < this.CommandTokens.Length; i++, j++)
                {
                    IStats stat = new Stats(Constants.Stats[j], int.Parse(this.CommandTokens[i]));
                    stats.Add(stat);
                }

                // Create player
                IPlayer player = new Player(playerName, stats);

                // Add to team
                team.Players.Add(player);
            }
            catch (Exception e)
            {
                toReturn = e.Message;
            }

            return(toReturn);
        }