Пример #1
0
        private static void SaveHorse(RacingPostRacesEntities db, RootObject result)
        {
            Console.Write(string.Format("Downlaod horse {0} name {1} \n", result.profile.horseUid, result.profile.horseName));
            RPHorse rpHorse = new RPHorse();

            rpHorse.Name     = result.profile.horseName;
            rpHorse.RPId     = result.profile.horseUid;
            rpHorse.Country  = result.profile.horseCountryOriginCode;
            rpHorse.Colour   = result.profile.horseColour;
            rpHorse.Sex      = result.profile.horseSexCode;
            rpHorse.SireId   = result.profile.sireUid;
            rpHorse.DamId    = result.profile.damUid;
            rpHorse.FoalYear = Convert.ToDateTime(result.profile.horseDateOfBirth).Year;
            if (rpHorse.FoalYear > 1)
            {
                rpHorse.FoalDate = Convert.ToDateTime(result.profile.horseDateOfBirth);
            }
            else
            {
                rpHorse.FoalDate = Convert.ToDateTime("1/1/1753");
            }
            rpHorse.PostTemplate = true;
            db.RPHorses.Add(rpHorse);
            db.SaveChanges();
        }
Пример #2
0
        static void HorseScrape(string[] args)
        {
            List <int> horseIds = new List <int>();

            RPHorse rpHorse;

            using (StreamReader file = File.OpenText(@"C:\Users\MuhammadZubair\Documents\BELData\horse(Feb)(2).json"))
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    JObject        o2         = (JObject)JToken.ReadFrom(reader);
                    JsonSerializer serializer = new JsonSerializer();
                    //var aa= JsonConvert.DeserializeObject<RPData>(text);
                    var rpHorses = o2.ToObject <RPHorses>();//.Deserialize<RPData>(reader);
                    Cleaner.GetBaseData();
                    // Cleaner.GetFooter();
                    int raceCount = 1;
                    using (RacingPostRacesEntities db = new RacingPostRacesEntities())
                    {
                        foreach (var item in rpHorses.Horses)
                        {
                            HorseCleaning.PrcessHorse(item);
                            HorseCleaning.PrcessHeader(item);
                            raceCount++;

                            rpHorse              = new RPHorse();
                            rpHorse.Name         = item.Name;
                            rpHorse.RPId         = item.Id;
                            rpHorse.Country      = item.Country;
                            rpHorse.Colour       = item.Color;
                            rpHorse.Sex          = item.Sex;
                            rpHorse.SireId       = item.SireId;
                            rpHorse.DamId        = item.DamId;
                            rpHorse.FoalDate     = item.DOB;
                            rpHorse.FoalYear     = item.DOB.Year;
                            rpHorse.PostTemplate = true;

                            db.RPHorses.Add(rpHorse);
                        }
                        db.SaveChanges();
                    }

                    //horseIds = horseIds.Distinct().ToList();
                    //foreach (var item in horseIds)
                    //{
                    //    System.Diagnostics.Trace.Write(item + " ,\n");
                    //}

                    // Cleaner.ProcessClass(rpData.AllRaces[20]);//  "(Class 4) | (4yo+) (2m5f82y)| | 2m5&frac12;f Heavy 10 hdles 1 omitted");
                }
        }
Пример #3
0
 public static void SaveHorse(Horse horse)
 {
     if (horse.Id == 0)
     {
         throw new ArgumentNullException();
     }
     using (RacingPostRacesEntities db = new RacingPostRacesEntities())
     {
         if (db.RPHorses.FirstOrDefault(h => h.RPId == horse.Id) == null)
         {
             RPHorse rpHorse = new RPHorse();
             rpHorse.RPId     = horse.Id;
             rpHorse.Name     = horse.Name;
             rpHorse.FoalDate = Convert.ToDateTime(horse.DOB);
             rpHorse.Country  = horse.Country;
             rpHorse.Colour   = horse.Color;
             rpHorse.Sex      = horse.Sex;
             rpHorse.SireId   = horse.SireId;
             rpHorse.DamId    = horse.DamId;
             db.RPHorses.Add(rpHorse);
             // db.SaveChanges();
         }
     }
 }