public async Task <List <Condition> > GetForecastAsync() { WeatherFacade weatherFacade = new WeatherFacade(API.Value); List <Condition> weather = new List <Condition>(); using (appDB){ WeatherRepository repo = new WeatherRepository(appDB); weather = await repo.LatestConditionAsync(true); if (weather.Count > 0) { var con = weather[0]; TimeSpan span = (DateTime.Now - con.timeStamp); if (span.Minutes < 30) { Console.WriteLine("db"); //myList.OrderBy(x => x.Created).ToList(); return(weather.OrderBy(x => x.date).ToList()); } } Console.WriteLine("api"); var w = weatherFacade.GetForecast(); if (w != null) { await repo.InsertAsync(w, true); weather = w; } var wa = weather.Where(c => c.weather.Trim() == "Rain").First(); if (wa != null) { IOT.Models.Action act = new IOT.Models.Action() { Text = "Weather forecast predicts " + wa.description + " on " + wa.date, Act = 0 }; ActionRepository repo2 = new ActionRepository(appDB); await repo2.InsertAsync(act); } } return(weather.OrderBy(x => x.date).ToList());; }