Пример #1
0
        public async Task <ActionResult <IEnumerable <Weather> > > InsertOrUpdateWeatherByCity(int id)
        {
            List <Weather> weathers = new List <Weather>();
            var            cityHref = await _context.Cities.FindAsync(id);

            if (cityHref != null)
            {
                weathers = GisParse.GetWeathers(cityHref.Reference, id);
                if (weathers.Any())
                {
                    foreach (var weather in weathers)
                    {
                        var dataForUpdate = await _context.Weathers.FirstOrDefaultAsync(x => x.CityID.Equals(weather.CityID) && x.Date.Equals(weather.Date) && x.Timeofday.Equals(weather.Timeofday));

                        if (dataForUpdate != null)
                        {
                            dataForUpdate.Temp         = weather.Temp;
                            dataForUpdate.Geomagneticf = weather.Geomagneticf;
                            dataForUpdate.Windspeed    = weather.Windspeed;
                            dataForUpdate.Pressure     = weather.Pressure;
                            dataForUpdate.Humidity     = weather.Humidity;
                        }
                        else
                        {
                            _context.Weathers.Add(weather);
                        }
                        await _context.SaveChangesAsync();
                    }
                }
            }

            return(weathers);
        }
Пример #2
0
        public async Task <ActionResult <IEnumerable <City> > > InsertOrUpdateCity()
        {
            List <City> cities = new List <City>();

            cities = GisParse.GetCitiesFromURL();
            if (cities.Any())
            {
                foreach (var city in cities)
                {
                    var dataForUpdate = await _context.Cities.FirstOrDefaultAsync(x => x.Reference.Equals(city.Reference));

                    if (dataForUpdate == null)
                    {
                        _context.Cities.Add(
                            new City
                        {
                            CityName  = city.CityName,
                            Reference = city.Reference
                        }
                            );
                    }
                    await _context.SaveChangesAsync();
                }
            }

            var citiesFromDB = await _context.Cities.ToListAsync();

            return(citiesFromDB);
        }
Пример #3
0
        public ActionResult <IEnumerable <Weather> > ParseWeatherByCity(string r, int id)
        {
            List <Weather> weathers = new List <Weather>();

            weathers = GisParse.GetWeathers("/" + r + "/", id);

            return(weathers);
        }
Пример #4
0
        public ActionResult <IEnumerable <City> > ParseCities()
        {
            var cities = GisParse.GetCitiesFromURL();

            return(cities);
        }