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); }
public ActionResult <IEnumerable <Weather> > ParseWeatherByCity(string r, int id) { List <Weather> weathers = new List <Weather>(); weathers = GisParse.GetWeathers("/" + r + "/", id); return(weathers); }