private static void AddTeamToLeague(Team team, League league)
 {
     if (league != null)
     {
         if (team.Leagues.Contains(league))
         {
             Console.WriteLine("Existing team in league: {0} belongs to {1}", team.TeamName, league.LeagueName);
         }
         else
         {
             team.Leagues.Add(league);
             Console.WriteLine("Added team to league: {0} to league {1}", team.TeamName, league.LeagueName);
         }
     }
 }
        private static Team GetOrCreateTeam(XElement team, FootballEntities db)
        {
            var teamName = team.Attribute("name").Value;
            string countryName = null;
            if (team.Attribute("country") != null)
            {
                countryName = team.Attribute("country").Value;
            }

            Team currentTeam;
            if (countryName != null)
            {
                currentTeam = db.Teams.FirstOrDefault(t => t.TeamName == teamName && t.Country.CountryName == countryName);
            }
            else
            {
                currentTeam = db.Teams.FirstOrDefault(t => t.TeamName == teamName);
            }

            if (currentTeam == null)
            {
                if (countryName != null)
                {
                    var country = db.Countries.FirstOrDefault(c => c.CountryName == countryName);
                    currentTeam = new Team { TeamName = teamName, Country = country };
                }
                else
                {
                    currentTeam = new Team { TeamName = teamName };
                }

                db.Teams.Add(currentTeam);
                Console.WriteLine("Created team: {0} ({1})",
                    currentTeam.TeamName,
                    currentTeam.Country != null ? currentTeam.Country.CountryName : "no country");
            }
            else
            {
                Console.WriteLine("Existing team: {0} ({1})",
                    currentTeam.TeamName,
                    currentTeam.Country != null ? currentTeam.Country.CountryName : "no country");
            }

            return currentTeam;
        }