Exemplo n.º 1
0
 static void Main()
 {
     var db = new FootballEntities();
     var temNames = db.Teams.Select(t => t.TeamName).ToList();
     foreach (var temName in temNames)
     {
         Console.WriteLine(temName);
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var context = new FootballEntities();
            var internationalMatches = context.InternationalMatches
            .OrderBy(i => i.MatchDate)
            .ThenBy(i => i.CountryHome.CountryName)
            .ThenBy(i => i.CountryAway.CountryName)
            .Select(i => new
            {
                homeCountry = i.CountryHome.CountryName,        
                awayCountry = i.CountryAway.CountryName,        
                homeCountryCode = i.CountryHome.CountryCode,        
                awayCountryCode = i.CountryAway.CountryCode,
                league = i.League.LeagueName,
                matchDate = i.MatchDate,
                homeScore = i.HomeGoals,
                awayScore = i.AwayGoals
            }).ToList();

            var root = new XElement("matches");
            foreach (var internationalMatch in internationalMatches)
            {
                var matchNode = new XElement("match");
                if (internationalMatch.matchDate != null)
                {
                    if (internationalMatch.matchDate.Value.TimeOfDay.TotalSeconds == 0)
                    {
                        var date = internationalMatch.matchDate.Value.ToString("dd-MMM-yyyy");
                        matchNode.Add(new XAttribute("date", date));
                    }
                    else
                    {
                        var date = internationalMatch.matchDate.Value.ToString("dd-MMM-yyyy hh:mm");
                        matchNode.Add(new XAttribute("date-time", date));
                    }
                }
               
                matchNode.Add(new XElement("home-country", internationalMatch.homeCountry, new XAttribute("code", internationalMatch.homeCountryCode)));
                matchNode.Add(new XElement("away-country", internationalMatch.awayCountry, new XAttribute("code", internationalMatch.awayCountryCode)));
                if (internationalMatch.league != null)
                {
                    matchNode.Add(new XElement("league", internationalMatch.league));
                }
                if (internationalMatch.homeScore != null && internationalMatch.awayScore != null)
                {
                    matchNode.Add(new XElement("score", internationalMatch.homeScore + "-" + internationalMatch.awayScore));
                }
                root.Add(matchNode);
            }

            var xmlDoc = new XDocument(root);
            xmlDoc.Save("../../international-matches.xml");
        }
Exemplo n.º 3
0
        static void Main()
        {
            var context = new FootballEntities();
            var leagues = context.Leagues
            .OrderBy(l => l.LeagueName)
            .Select(l => new
            {
                leagueName = l.LeagueName,
                teams = l.Teams.OrderBy(t => t.TeamName).Select(t => t.TeamName)
            }).ToList();

            var initializer = new JavaScriptSerializer();
            var json = initializer.Serialize(leagues);
            File.WriteAllText("../../leagues-and-teams.json", json);
        }
Exemplo n.º 4
0
        static void Main()
        {
            var context = new FootballEntities();
            var xmlDoc = XDocument.Load("../../leagues-and-teams.xml");
            var node = xmlDoc.XPathSelectElements("/leagues-and-teams/league");
            var processing = 1;
            foreach (var element in node)
            {
                Console.WriteLine("Processing league #{0}...", processing++);
                var league = new League();
                if (element.Element("league-name") != null)
                {
                    var leagueName = element.Element("league-name").Value;
                    if (!context.Leagues.Any(l => l.LeagueName == leagueName))
                    {
                        league = new League()
                        {
                            LeagueName = leagueName
                        };

                        context.Leagues.Add(league);
                        Console.WriteLine("Created league: " + leagueName);
                    }
                    else
                    {
                        Console.WriteLine("Existing league: " + leagueName);
                    }
                }
                var teams = element.XPathSelectElements("teams/team");
                foreach (var team in teams)
                {
                    if (team.Attribute("name") != null)
                    {
                        var currTeam = new Team();
                        var teamName = team.Attribute("name").Value;
                        string countryName = null;
                        if (team.Attribute("country") != null)
                        {
                            countryName = team.Attribute("country").Value;
                        }
                        if (!context.Teams.Any(l => l.TeamName == teamName))
                        {
                            currTeam = new Team()
                            {
                                TeamName = teamName,
                                Country = context.Countries.FirstOrDefault(c => c.CountryName == countryName)
                            };
                            context.Teams.Add(currTeam);

                            Console.WriteLine("Created team: New {0} ({1})", teamName, countryName??"no country");
                        }
                        else
                        {
                            Console.WriteLine("Existing team: {0} ({1})", teamName, countryName);
                        }

                        if (league != null)
                        {
                            if (currTeam.Leagues.Contains(league))
                            {
                                Console.WriteLine("Existing team in league: {0} to {1}", teamName, league.LeagueName);
                            }
                            else
                            {
                                Console.WriteLine("Added team to league: {0} to {1}", teamName, league.LeagueName);
                            }
                        }
                    }
                }
                Console.WriteLine();
            }
        }