public PartialViewResult GetWeatherDetails(string countryName, string cityName) { var weatherMap = _weatherMapService.GetWeatherDetails(cityName).Result; var viewModel = new WeatherDetailViewModels(); if (weatherMap != null) { viewModel.Location = string.Format("Lon: {0}, Lat: {1}", weatherMap.coord.lon, weatherMap.coord.lat); viewModel.Time = UnixTimeStampToDateTime(weatherMap.dt).ToString("dd/MM/yyyy HH:mm:ss"); viewModel.Wind = string.Format("Speed: {0} metre/sec, Degree: {1}", weatherMap.wind.speed.ToString(), weatherMap.wind.deg.ToString()); viewModel.Visibility = weatherMap.visibility.ToString(); viewModel.SkyConditions = weatherMap.weather[0].description; viewModel.Temperature = ConvertFromKelvin(weatherMap.main.temp).ToString() + "°C"; viewModel.RelativeHumidity = (weatherMap.main.humidity / 100).ToString("P"); viewModel.Pressure = weatherMap.main.pressure.ToString() + " hPa"; } return(PartialView("_WeatherDetails", viewModel)); }
public HttpResponseMessage Get(HttpRequestMessage request, string cityName) { var weatherMap = _weatherMapService.GetWeatherDetails(cityName).Result; var viewModel = new WeatherDetailViewModels(); if (weatherMap != null) { viewModel.Location = string.Format("Lon: {0}, Lat: {1}", weatherMap.coord.lon, weatherMap.coord.lat); viewModel.Time = UnixTimeStampToDateTime(weatherMap.dt).ToString("dd/MM/yyyy HH:mm:ss"); viewModel.Wind = string.Format("Speed: {0} metre/sec, Degree: {1}", weatherMap.wind.speed.ToString(), weatherMap.wind.deg.ToString()); viewModel.Visibility = weatherMap.visibility.ToString(); viewModel.SkyConditions = weatherMap.weather[0].description; viewModel.Temperature = ConvertFromKelvin(weatherMap.main.temp).ToString() + "°C"; viewModel.RelativeHumidity = (weatherMap.main.humidity / 100).ToString("P"); viewModel.Pressure = weatherMap.main.pressure.ToString() + " hPa"; } var response = request.CreateResponse(HttpStatusCode.OK, viewModel); return(response); }