protected async Task <Guid> ProcessPerson(string lookupId, string forenames, string surname, DateTime?dateOfBirth, DateTime?dateOfDeath, Guid?countryGuid) { var lookupPerson = await Provider.GetLookupPerson(ImportSite, lookupId); if (lookupPerson != null) { return(lookupPerson.PersonGuid); } else { var personGuid = Guid.NewGuid(); Provider.Add(new Person() { PrimaryKey = personGuid }); var personV = PersonV.CreateNew <PersonV>(User.GetUserId()); personV.HeaderKey = personGuid; personV.Forenames = forenames; personV.Surname = surname; personV.SearchText = personV.SetSearchText(); personV.DateOfBirth = dateOfBirth; personV.DateOfDeath = dateOfDeath; personV.CountryGuid = countryGuid; personV.EffectiveFrom = Date.LowDate; personV.EffectiveTo = Date.HighDate; Provider.Add(personV); Provider.Add(new LookupPerson() { PrimaryKey = Guid.NewGuid(), ImportSite = ImportSite, PersonGuid = personGuid, LookupId = lookupId }); Provider.SaveChanges(); return(personGuid); } }
private async Task <Guid?> ProcessPlayer(string lookupId) { var personGuid = await LookupPerson(lookupId); if (personGuid != null) { return(personGuid); } // http://www.soccerbase.com/players/player.sd?player_id=46629 var uri = new Uri(string.Format("http://www.soccerbase.com/players/player.sd?player_id={0}", lookupId)); var document = GetHtmlDocument(uri); var playerDiv = document.DocumentNode.Descendants("div").FirstOrDefault(d => d.Attributes.Contains("class") && d.Attributes["class"].Value == "soccerContent"); if (playerDiv == null) { return(null); } string forenames = string.Empty; string surname = string.Empty; DateTime?dob = null; double? height = null; Guid? countryKey = null; foreach (var tr in playerDiv.Descendants("tr")) { var th = tr.Descendants("th").FirstOrDefault(); if (th == null) { continue; } switch (th.InnerText) { case "Real name": var fullName = tr.Descendants("strong").First().InnerText; ResolvePersonNames(fullName, out forenames, out surname); if (string.IsNullOrWhiteSpace(forenames) && string.IsNullOrWhiteSpace(surname)) { return(null); } break; case "Age": var dobString = tr.Descendants("td").First().InnerText.GetTextBetween("(Born ", ")"); dob = !string.IsNullOrWhiteSpace(dobString) ? (DateTime?)DateTime.Parse(dobString) : null; break; case "Height": var heightString = tr.Descendants("strong").First().InnerText.GetTextBetween("(", "m)"); if (!string.IsNullOrWhiteSpace(heightString)) { height = Convert.ToDouble(heightString) * 100; } break; case "Nationality": var nationalityString = tr.Descendants("strong").First().InnerText.Trim(); countryKey = await GetCountryKeyByName(nationalityString); break; } } var person = Person.Create <Person>(); person.PrimaryKey = Guid.NewGuid(); var personV = PersonV.CreateNew <PersonV>(User.GetUserId()); personV.HeaderKey = person.PrimaryKey; personV.EffectiveFrom = Date.LowDate; personV.EffectiveTo = Date.HighDate; personV.Forenames = forenames; personV.Surname = surname; personV.SearchText = personV.SetSearchText(); personV.CountryGuid = countryKey; personV.DateOfBirth = dob; personV.Height = Convert.ToInt32(height); Provider.Add(person); Provider.Add(personV); Provider.Add(new LookupPerson() { PrimaryKey = Guid.NewGuid(), ImportSite = this.ImportSite, LookupId = lookupId, PersonGuid = person.PrimaryKey }); Provider.SaveChanges(); return(person.PrimaryKey); }
public void Add(PersonV personV) { PersonVRepository.Add(personV); }
public void Remove(PersonV personV) { PersonVRepository.Remove(personV); }
public static void PersonBreadcrumb(this IList<BreadcrumbViewModel> breadcrumbViewModels, PersonV personV, DateTime viewDate) { var personViewModel = personV.ToViewModel(viewDate); var matchEventVs = personViewModel.VersionEntity.Person.MatchEvents.OrderByDescending(m => m.MatchV.MatchDate).Take(1); if (matchEventVs.Any()) breadcrumbViewModels.TeamBreadcrumb(matchEventVs.FirstOrDefault().Team.GetApprovedVersion<TeamV>(viewDate), viewDate); breadcrumbViewModels.Add(AreaType.Ppl, personViewModel.HeaderKey, personViewModel.ToString(), string.Empty); }