public async Task UpdateCurrentWeatherAsync() { var newWeathers = await _apiClient.GetWeatherAsync(); var oldWeathers = _context.Weathers.ToList(); foreach (var newWeather in newWeathers) { var oldWeather = oldWeathers.SingleOrDefault(w => w.CityId == newWeather.CityId); if (oldWeather != null) { oldWeather.Humidity = newWeather.Humidity; oldWeather.Temperature = newWeather.Temperature; oldWeather.Name = newWeather.Name; } else { _context.Weathers.Add(newWeather); } } _context.SaveChanges(); // save changes has its own transaction }
public async Task <WeatherRootObject> GetForecast(string id) { return(await _client.GetWeatherAsync(id)); }