Esempio n. 1
0
        protected async Task <Guid> ProcessTeam(string lookupId, string teamName, Guid?countryGuid)
        {
            var lookupTeamSearch = await Provider.GetLookupTeam(ImportSite, lookupId);

            if (lookupTeamSearch != null)
            {
                return(lookupTeamSearch.TeamGuid);
            }
            else
            {
                var teamGuid = Guid.NewGuid();

                Provider.Add(new Team()
                {
                    PrimaryKey = teamGuid
                });

                var teamV = TeamV.CreateNew <TeamV>(User.GetUserId());
                teamV.HeaderKey     = teamGuid;
                teamV.CountryGuid   = countryGuid;
                teamV.EffectiveFrom = Date.LowDate;
                teamV.EffectiveTo   = Date.HighDate;

                teamV.TeamNames = new List <TeamName>();
                teamV.TeamNames.Add(new TeamName()
                {
                    PrimaryKey   = Guid.NewGuid(),
                    TeamVKey     = teamV.PrimaryKey,
                    TeamNameType = TeamNameType.Primary,
                    LanguageType = LanguageType.Native,
                    Description  = teamName
                });

                Provider.Add(teamV);

                Provider.Add(new LookupTeam()
                {
                    PrimaryKey = Guid.NewGuid(),
                    ImportSite = ImportSite,
                    TeamGuid   = teamGuid,
                    LookupId   = lookupId
                });

                Provider.SaveChanges();

                return(teamGuid);
            }
        }
Esempio n. 2
0
        private Guid?AddNewTeam(string teamLookupId, Guid?countryKey)
        {
            // http://www.soccerbase.com/teams/team.sd?team_id=485
            var uri      = new Uri(string.Format("http://www.soccerbase.com/teams/team.sd?team_id={0}", teamLookupId));
            var document = GetHtmlDocument(uri);

            var table    = document.DocumentNode.Descendants("table").FirstOrDefault(t => t.Attributes.Contains("class") && t.Attributes["class"].Value == "imageHead");
            var header1  = table.Descendants("h1").FirstOrDefault();
            var teamName = header1.InnerText.GetTextBefore("Club details").Replace("/n", string.Empty).Trim();

            var venueName     = string.Empty;
            int?venueCapacity = null;

            table = document.DocumentNode.Descendants("table").FirstOrDefault(t => t.Attributes.Contains("class") && t.Attributes["class"].Value == "clubInfo");

            foreach (var tr in table.Descendants("tr"))
            {
                var th = tr.Descendants("th").FirstOrDefault();

                if (th == null)
                {
                    continue;
                }

                switch (th.InnerText)
                {
                case "Ground":
                    var venueNode = tr.Descendants("strong").FirstOrDefault();

                    if (venueNode != null)
                    {
                        venueName = venueNode.InnerText.Trim();
                    }

                    var groundList = tr.Descendants("li").FirstOrDefault(l => l.Attributes.Contains("class") && l.Attributes["class"].Value == "alt");

                    if (groundList != null)
                    {
                        var capacityNode = groundList.Descendants("strong").FirstOrDefault();

                        if (capacityNode != null)
                        {
                            venueCapacity = capacityNode.InnerText.Replace("/n", string.Empty).Replace(",", string.Empty).Trim().ToNullableInt();
                        }
                    }

                    break;
                }
            }

            Guid?venueKey = null;

            if (!string.IsNullOrWhiteSpace(venueName) && countryKey != null)
            {
                venueKey = Guid.NewGuid();
                var venue = new Venue()
                {
                    PrimaryKey = (Guid)venueKey
                };
                Provider.Add(venue);

                var venueV = VenueV.CreateNew <VenueV>(User.GetUserId());
                venueV.HeaderKey     = venue.PrimaryKey;
                venueV.VenueName     = venueName;
                venueV.CountryGuid   = (Guid)countryKey;
                venueV.Capacity      = venueCapacity;
                venueV.EffectiveFrom = Date.LowDate;
                venueV.EffectiveTo   = Date.HighDate;

                Provider.Add(venueV);
            }

            Guid?teamGuid = null;

            if (!string.IsNullOrEmpty(teamName))
            {
                teamGuid = Guid.NewGuid();
                var team = new Team()
                {
                    PrimaryKey = (Guid)teamGuid
                };
                Provider.Add(team);

                var teamV = TeamV.CreateNew <TeamV>(User.GetUserId());
                teamV.HeaderKey     = team.PrimaryKey;
                teamV.HomeVenueGuid = venueKey;
                teamV.CountryGuid   = countryKey;
                teamV.EffectiveFrom = Date.LowDate;
                teamV.EffectiveTo   = Date.HighDate;

                teamV.TeamNames = new List <TeamName>();

                teamV.TeamNames.Add(new TeamName()
                {
                    PrimaryKey   = Guid.NewGuid(),
                    TeamVKey     = teamV.PrimaryKey,
                    TeamNameType = TeamNameType.Primary,
                    LanguageType = LanguageType.Native,
                    Description  = teamName
                });

                Provider.Add(teamV);

                Provider.Add(new LookupTeam()
                {
                    PrimaryKey = Guid.NewGuid(),
                    ImportSite = this.ImportSite,
                    TeamGuid   = (Guid)teamGuid,
                    LookupId   = teamLookupId
                });
            }

            Provider.SaveChanges();

            return(teamGuid);
        }