public ActionResult <ForecastFormatedDTO> GetForecast(string customCode) { CityForecastDTO cityForecastDTO = this._externalCityService.GetCityForecast(customCode); ForecastFormatedDTO forecastFormatedDTO = new ForecastFormatedDTO(cityForecastDTO); return(Ok(forecastFormatedDTO)); }
public ForecastFormatedDTO(CityForecastDTO cityForecastDTO) { this.list = new List <ForecastListFormatedDTO>(); var listCitiesByDate = cityForecastDTO.list.GroupBy(x => x.dt_txt.Split(' ').FirstOrDefault()); foreach (var item in listCitiesByDate) { string dt_txt = item.FirstOrDefault().dt_txt.Split(' ').FirstOrDefault(); double temp_min = item.Min(x => x.main.temp_min); double temp_max = item.Max(x => x.main.temp_max); double wind_speed = item.Max(x => x.wind.speed); double temp = 0; string weather_icon = ""; if (Convert.ToDateTime(item.FirstOrDefault().dt_txt.Split(' ').FirstOrDefault()).Equals(DateTime.Today.Date)) { temp = item.FirstOrDefault().main.temp; weather_icon = item.FirstOrDefault().weather.FirstOrDefault().icon; } else { temp = temp_max; weather_icon = item.OrderByDescending(x => x.main.temp_max).FirstOrDefault().weather.FirstOrDefault().icon; } this.list.Add(new ForecastListFormatedDTO() { dt_txt = dt_txt, temp = temp, temp_min = temp_min, temp_max = temp_max, wind_speed = wind_speed, weather_icon = weather_icon }); } }
public ActionResult <CityForecastDTO> GetForecast(string customCode) { CityForecastDTO cityForecastDTO = this._externalCityService.GetCityForecast(customCode); return(Ok(cityForecastDTO)); }