Exemplo n.º 1
0
        public async void getCityDetails()
        {
            City city = cityVM.getCity();

            using (HttpClient client = new HttpClient())
                try
                {
                    HttpResponseMessage response = await client.GetAsync(API.getForecastURL(city));

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Forecast apiForecast = JsonConvert.DeserializeObject <Forecast>(
                            await response.Content.ReadAsStringAsync()
                            );

                        city.UpdateForecast(apiForecast);
                        if (view != null)
                        {
                            view.UpdateChart(); // Updating chart since it does not work with binds
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.Error.Write(ex.StackTrace);
                }
        }
Exemplo n.º 2
0
        public async Task UpdateCityWeather(CityViewModel cityVM)
        {
            City city = cityVM.getCity();

            using (HttpClient client = new HttpClient())
                try
                {
                    HttpResponseMessage response = await client.GetAsync(API.getWeatherURL(city));

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Weather apiWeather = JsonConvert.DeserializeObject <Weather>(
                            await response.Content.ReadAsStringAsync()
                            );

                        city.UpdateWeather(apiWeather);
                    }
                }
                catch (Exception ex)
                {
                    Console.Error.Write(ex.StackTrace);
                }
            return;
        }