Beispiel #1
0
        public async Task <string> GetWeatherMessage(string zip)
        {
            var currentWeatherTask = _weatherApiClient.GetCurrentWeatherByZip(zip);
            var forecastTask       = _weatherApiClient.GetForecastByZip(zip);

            var sb = new StringBuilder();

            await Task.WhenAll(currentWeatherTask, forecastTask);

            sb.Append($"Right now the weather in {currentWeatherTask.Result.name} is {currentWeatherTask.Result.main.temp} degrees with {currentWeatherTask.Result.weather.First().description}. ");

            var laterWeather = forecastTask.Result.List.Skip(2).First();

            sb.Append(GetForecastInstanceMsg("At", GetWeatherChangePhrase(currentWeatherTask.Result.main.temp, laterWeather.Main.Temp), laterWeather));

            var lastWeather = forecastTask.Result.List.Skip(4).First();

            sb.Append(GetForecastInstanceMsg("By", GetWeatherChangePhrase(laterWeather.Main.Temp, lastWeather.Main.Temp), lastWeather));

            return(sb.ToString());
        }
Beispiel #2
0
        public async Task <object> GetForecast([FromQuery] string zip = "92117")
        {
            var forecast = await _weatherApiClient.GetForecastByZip(zip);

            return(forecast);
        }