private async Task <IList <WeatherForecast> > CurrentOrPreviousFiveDayWeatherForecast(string zip) { if (string.IsNullOrWhiteSpace(zip)) { return(null); } var utcNow = DateTimeOffset.UtcNow; var weatherForecasts = new List <WeatherForecast>(); var cachedWeather = await ActivityDbContext.CachedWeathers .AsNoTracking() .Include(cachedWeather0 => cachedWeather0.WeatherForecasts) .SingleOrDefaultAsync(cachedWeather0 => cachedWeather0.ZipCode == zip && cachedWeather0.DateCached.LocalDateTime.ToShortDateString() == utcNow.LocalDateTime.ToShortDateString()); if (cachedWeather == null) { weatherForecasts = GetWeather.FiveDayAround1500Forecast(zip).ToList(); cachedWeather = new CachedWeather { ZipCode = zip, DateCached = utcNow, WeatherForecasts = weatherForecasts }; var previousCachedWeathersForZipcodeQuery = ActivityDbContext.CachedWeathers .AsNoTracking() .Where(previousCachedWeather => previousCachedWeather.ZipCode == zip); if (previousCachedWeathersForZipcodeQuery.Count() > 0) { ActivityDbContext.CachedWeathers.RemoveRange(previousCachedWeathersForZipcodeQuery); } ActivityDbContext.CachedWeathers.Add(cachedWeather); await ActivityDbContext.SaveChangesAsync(); return(weatherForecasts); } else { return(cachedWeather.WeatherForecasts); } }
public void FiveDayAround1500Forecast_84037() { GetWeather.FiveDayAround1500Forecast(GetWeather.GetWeatherForecastsForZip("84103")); }
public IEnumerable <WeatherForecast> FiveDayWeatherForecast(double latitude, double longitude) { return(GetWeather.FiveDayAround1500Forecast(latitude, longitude)); }