public ActionResult Index() { WeatherModel model = new WeatherModel(); WeatherResultModel weatherResult = WeatherModel.LoadWeatherInfo(); return(View("Index", weatherResult)); }
public static async Task <WeatherResultModel> load(string cityName) { using (HttpResponseMessage response = await ApiHelper.init().GetAsync($"weather?q={cityName}&appid=1bcc6336317cecebc65a7d48e06b236d")) { if (response.IsSuccessStatusCode) { WeatherResultModel result = await response.Content.ReadAsAsync <WeatherResultModel>(); return(result); } else { throw new Exception(response.ReasonPhrase); } } }
WeatherResultModel loadWeather() { //try //{ // var jsonResult = ApiHelper.GetJsonFromApi(PathHelper.HTTP_SERVER_PATH + @"/api/weatherapi/getcurrentweatherinfo"); // if (jsonResult != null) // { // var weatherResult = JsonConvert.DeserializeObject<WeatherModel>(jsonResult); // _currentWeather = new WeatherResultModel() // { // Daily = new List<DailyWeatherInfoResultModel>(), // IsCorrect = weatherResult.IsCorrect, // LastUpdateDate = weatherResult.LastUpdateDate // }; // foreach (var day in weatherResult.Daily) // { // _currentWeather.Daily.Add(new DailyWeatherInfoResultModel() // { // FullImage = day.FullImage.AsImage(), // IconImage = day.IconImage.AsImage(), // IconUrl = day.IconUrl, // Info = day.Info, // Tempature = day.Tempature // }); // } // } //} //catch (Exception) //{ //} var apiResult = _apiService.Get(PathHelper.HTTP_SERVER_PATH + @"/api/weatherapi/getcurrentweatherinfo"); if (apiResult.IsSuccess) { var weatherResult = apiResult.Result; _currentWeather = new WeatherResultModel() { Daily = new List <DailyWeatherInfoResultModel>(), IsCorrect = weatherResult.IsCorrect, LastUpdateDate = weatherResult.LastUpdateDate }; foreach (var day in weatherResult.Daily) { _currentWeather.Daily.Add(new DailyWeatherInfoResultModel() { FullImage = day.FullImage.AsImage(), IconImage = day.IconImage.AsImage(), IconUrl = day.IconUrl, Info = day.Info, Tempature = day.Tempature }); } } return(_currentWeather); }
public override void Dispose(bool disposing) { _currentWeather = null; }