Example #1
0
        private static async Task GetAPIResult(Stadt stadt)
        {
            try
            {
                stadt.Temperatur = null;
                HttpClient client     = new HttpClient();
                var        jsonString = await client.GetStringAsync($"https://api.openweathermap.org/data/2.5/weather?q={stadt.Name}&units=metric&appid=84d84c7b399d88e7f4e4688facc2498e");

                await Task.Delay(1000);

                var result = JsonConvert.DeserializeObject <WetterAPIResult>(jsonString);
                stadt.Temperatur   = result.main.temp;
                stadt.IconURL      = $"http://openweathermap.org/img/w/{result.weather[0].icon}.png";
                stadt.ErrorMessage = null;
            }
            catch (Exception exp)
            {
                stadt.ErrorMessage = exp.Message;
                stadt.Temperatur   = 0;
            }
        }