public WeatherViewModel WeatherInfo(AddressViewModel addressViewModel, bool extendHourly) { WeatherViewModel weatherViewModel = null; ForecastIOResponse currentWeather = GetWeatherInfo(addressViewModel.Address, extendHourly); if (currentWeather != null) { // Get address info Address addressInfo = GetGeoInfo(addressViewModel.Address); // Get weather info for previous week List<ForecastIOResponse> previousWeekWeather = new List<ForecastIOResponse>(); for (int i = 7; i > 0; i--) { ForecastIOResponse previousWeather = GetWeatherInfo(addressViewModel.Address, DateTime.Now.AddDays(-i)); previousWeekWeather.Add(previousWeather); } // Setup return view model weatherViewModel = new WeatherViewModel() { CurrentWeather = currentWeather, PreviousWeekWeather = previousWeekWeather, AddressInfo = addressInfo }; } return weatherViewModel; }
public ActionResult Index(AddressViewModel addressViewModel) { if (addressViewModel.Address != null) { WeatherViewModel weatherViewModel = _weatherInfoService.WeatherInfo(addressViewModel, true); if (weatherViewModel != null) return View("SearchResults", weatherViewModel); } this.ModelState.AddModelError("", "No weather information could be provided for the given address. Please try another address."); return View(addressViewModel); }