示例#1
0
        public async Task <ActionResult> Index(string cityName, int countDays)
        {
            try
            {
                WeatherData weatherData = await service.GetWeatherAsync(cityName, countDays);

                await service.AddHistoryObjectAsync(new HistoryWeatherDataObject
                {
                    City                  = cityName,
                    CountDays             = countDays,
                    RequestTime           = DateTime.Now,
                    ReducedForecastPerDay = WeatherDataConverter.GetReducedForecastForFirstDay(weatherData)
                });

                ViewBag.CityList = await service.GetCityListAsync();

                ViewBag.Error = "";
                return(View(weatherData));
            }
            catch (Exception ex)
            {
                ViewBag.CityList = new List <CityName>();
                ViewBag.Error    = ex.Message;
                return(View());
            }
        }