public async Task <ActionResult <string> > UpdateWeatherForAirportMethod(int airport_id) { Airport FoundAirport; try{ FoundAirport = dbQuery.FindAirportWithForecastById(airport_id); }catch { JsonResponse r = new JsonResponse("Invalid Airport Id"); return(StatusCode(400, r)); } if (FoundAirport.WeatherForecast.Count > 0) //verify weather cache //check if less than 1 hour since last update { if (FoundAirport.WeatherForecast[0].UpdatedAt.AddHours(1) > DateTime.Now) { //don't update cache return("cache ok"); } } WeatherInformation weather_information = new WeatherInformation(client); WeatherForecast airport_forecast = await weather_information.GetWeatherForLocation(FoundAirport.Latitude, FoundAirport.Longitude); airport_forecast.AirportId = FoundAirport.AirportId; dbQuery.AddWeatherForecast(airport_forecast); return("cache updated"); }
public async Task <ActionResult <WeatherForecast> > RunTest() { WeatherInformation weather_api = new WeatherInformation(client); return(await weather_api.GetWeatherForLocation(25, 30)); }