Exemplo n.º 1
0
        public static void Do()
        {
            var countries = CountryRecord.Retrieve();

            using (var context = new ClimateContext())
            {
                context.Countries.RemoveRange(context.Countries.ToList());
                foreach (var country in countries.OrderByDescending(x => x.population))
                {
                    var dbCountry = new Domain.Country
                    {
                        Name       = country.name,
                        Population = country.population
                    };
                    context.Countries.Add(dbCountry);

                    var capital = new Domain.City
                    {
                        IsCapital = true,
                        Country   = dbCountry,
                        Name      = country.capital
                    };
                    context.Cities.Add(capital);
                    Console.WriteLine("{0} - done", country.name);
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static void Do()
        {
            var converter = new ModelsConverter();

            using (var context = new ClimateContext())
            {
                var cities = context.Cities.Include(x => x.Country).ToList().Select(converter.ToDto).ToArray();
                var path   = "../../../../shared/data.json";
                File.WriteAllText(path, JsonConvert.SerializeObject(cities));
            }
        }
Exemplo n.º 3
0
 public static void Do()
 {
     using (var context = new ClimateContext())
     {
         var capitals = context.Cities.OrderByDescending(x => x.Country.Population).ToList();
         var index    = 0;
         foreach (var capital in capitals)
         {
             var itsClimate = capital.Climates.ToList();
             if (!itsClimate.Any() && !string.IsNullOrEmpty(capital.Name))
             {
                 var capitalClimate = data.Retrieve(capital.Name);
                 try
                 {
                     var records = capitalClimate.ClimateAverages[0].month.Select(m => new CityClimateRecord
                     {
                         AbsMax     = m.absMaxTemp,
                         AbsMaxFahr = m.absMaxTemp_F,
                         AvgMin     = m.avgMinTemp,
                         AvgMinFahr = m.avgMinTemp_F,
                         Month      = m.name,
                         MonthIndex = m.index
                     }).ToList();
                     var climate = new CityClimate
                     {
                         TargetCity = capital,
                         Records    = new List <CityClimateRecord>(records)
                     };
                     context.CityClimates.Add(climate);
                     context.CityClimateRecords.AddRange(records);
                     context.SaveChanges();
                     Console.WriteLine("{0} - processed, {1}/{2} to do", capital.Name, capitals.Count - ++index,
                                       capitals.Count);
                 }
                 catch (Exception)
                 {
                     Console.WriteLine("{0} - failed, {1}/{2} to do", capital.Name, capitals.Count - ++index,
                                       capitals.Count);
                 }
                 Thread.Sleep(2000);
             }
             else
             {
                 Console.WriteLine("{0} - skipped, {1}/{2} to do", capital.Name, capitals.Count - ++index, capitals.Count);
             }
         }
     }
     Console.ReadLine();
 }
Exemplo n.º 4
0
        public static void Do()
        {
            var countries = CountryRecord.Retrieve();

            using (var context = new ClimateContext())
            {
                var dbCountries = context.Countries.Include(x => x.Cities).ToList();
                var joined      = countries.Join(dbCountries, x => x.name, x => x.Name, (dto, db) => new { dto, db });
                foreach (var pair in joined)
                {
                    if (pair.dto.latlng != null && pair.dto.latlng.Length == 2)
                    {
                        foreach (var city in pair.db.Cities)
                        {
                            city.Lat = pair.dto.latlng[0];
                            city.Lon = pair.dto.latlng[1];
                        }
                    }
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 5
0
 public ClimatesController(ClimateContext context)
 {
     _context = context;
 }
Exemplo n.º 6
0
 public RepositoryBase()
 {
     Context = new ClimateContext();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Climate controller constructor
 /// </summary>
 /// <param name="climateContext">Climate context</param>
 public ClimateController(ClimateContext climateContext)
 {
     _climateContext = climateContext;
 }