public IActionResult Dashboard(SearchWeather search) { WeatherResponse weatherResponse = _weatherService.GetWeatherData(search).Result; DashboardViewModel viewModel = new DashboardViewModel(); viewModel.Search = search; viewModel.Weather = weatherResponse; return(View(viewModel)); }
public async Task <WeatherResponse> GetWeatherData(SearchWeather search) { WeatherResponse weatherData = null; string openweatherApiKey = _configuration.GetSection("OpenWeatherAPIKey").Value; try { var response = await _client.GetAsync($"http://api.openweathermap.org/data/2.5/forecast?q={search.City},{search.Country}&cnt={search.numberDays}&units=metric&APPID={openweatherApiKey}"); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); weatherData = JsonConvert.DeserializeObject <WeatherResponse>(content); } } catch (Exception ex) { throw (ex); } return(weatherData); }