コード例 #1
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;
        }
コード例 #2
0
 public DetailedCityViewModel(CityViewModel cityVM)
 {
     this.cityVM = cityVM;
 }
コード例 #3
0
        public async void AddCity(CityViewModel city)
        {
            await UpdateCityWeather(city);

            Cities.Add(city);
        }