コード例 #1
0
        public void UpdateTeamInfo(FootballTeam updatedInfo)
        {
            FootballTeam newTeam = GetFootballTeamById(updatedInfo.Id.ToString());
            FootballTeam oldTeam = newTeam;

            if (updatedInfo.TeamName != null)
            {
                newTeam.TeamName = updatedInfo.TeamName;
            }

            if (updatedInfo.CoachName != null)
            {
                newTeam.CoachName = updatedInfo.CoachName;
            }

            if (updatedInfo.MatchesWon != -1)
            {
                newTeam.MatchesWon = updatedInfo.MatchesWon;
            }

            if (updatedInfo.MatchesLost != -1)
            {
                newTeam.MatchesLost = updatedInfo.MatchesLost;
            }

            if (!TeamsByID.TryUpdate(updatedInfo.Id, newTeam, oldTeam))
            {
                throw new Exception("Error: Unable to update the team information");
            }
        }
コード例 #2
0
        public FootballTeam GetFootballTeamById(string Id)
        {
            FootballTeam team = null;

            TeamsByID.TryGetValue(Guid.Parse(Id), out team);

            return(team);
        }
コード例 #3
0
        private void PerformDeleteOperation(FootballTeam toDelete)
        {
            FootballTeam team;

            if (!TeamsByID.TryRemove(toDelete.Id, out team))
            {
                throw new Exception("Error: Unable to delete team");
            }

            if (!TeamsNameAndCoach.TryRemove(new Tuple <string, string>(toDelete.TeamName, toDelete.CoachName), out team))
            {
                TeamsByID.TryAdd(toDelete.Id, toDelete);
                throw new Exception("Error: Unable to delete team");
            }
        }
コード例 #4
0
        public void CreateTeam(string teamName, string coachName)
        {
            FootballTeam team = new FootballTeam(teamName, coachName);

            team.Id = Guid.NewGuid();

            if (!TeamsByID.TryAdd(team.Id, team))
            {
                throw new Exception("Error: The team was created but it could not be inserted into the Storage");
            }

            if (!TeamsNameAndCoach.TryAdd(new Tuple <string, string>(team.TeamName, team.CoachName), team))
            {
                TeamsByID.TryRemove(team.Id, out team);
                throw new Exception("Error: The team was created but it could not be inserted into the Storage");
            }
        }