public async Task <Condition> GetCurrentAsync() { WeatherFacade weatherFacade = new WeatherFacade(API.Value); Condition weather = null; using (appDB){ WeatherRepository repo = new WeatherRepository(appDB); var cons = await repo.LatestConditionAsync(); if (cons.Count > 0) { weather = cons[0]; TimeSpan span = (DateTime.Now - weather.timeStamp); if (span.Minutes < 10) { Console.WriteLine("db"); return(weather); } } Console.WriteLine("api"); var w = weatherFacade.GetCurrentWeatherDetail(); if (w != null) { await repo.InsertAsync(w); weather = w; } } return(weather); }
private CityViewModel GetDetails(int cityId, DateTime date, IEnumerable <Provider> providers) { var result = new CityViewModel { Id = cityId, LastSevenDays = WeatherFacade.GetLastSevenDays(cityId, date, providers), WeatherData = Mapper.Map <IEnumerable <WeatherDataAggregateViewModel> >(WeatherFacade.GetWeatherData(cityId, date, providers)) }; return(result); }
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());; }
// // GET: /World/ public ActionResult Index() { var worlds = WeatherFacade.GetWorlds(); return(View(Mapper.Map <IEnumerable <WorldViewModel> >(worlds))); }
// // GET: /Region/ public ActionResult Index(int countryId) { var regiones = WeatherFacade.GetRegiones(countryId); return(View(Mapper.Map <IEnumerable <RegionViewModel> >(regiones))); }
// // GET: /Country/ public ActionResult Index(int worldId) { var countries = WeatherFacade.GetCountries(worldId); return(View(Mapper.Map <IEnumerable <CountryViewModel> >(countries))); }
public ActionResult Index(int regionId) { var cities = WeatherFacade.GetCities(regionId); return(View(Mapper.Map <IEnumerable <CityViewModel> >(cities))); }