/// <summary> /// Converts a DTO object to entity. /// </summary> /// <param name="forecastDTO">Model converted from JSON string.</param> /// <returns>List of forecast entites to store in a database.</returns> public List <ForecastEntity> ConvertModel(Forecast forecastDTO) { List <ForecastEntity> entities = new List <ForecastEntity>(); ForecastEntity entity = new ForecastEntity(); foreach (var weather in forecastDTO.List) { entity = new ForecastEntity { CityServiceId = (int)forecastDTO.City.Id, Clouds = new Common.Models.Clouds() }; entity.Clouds.All = weather.Clouds.All; entity.PredictionDate = new PredictionDate { Time = weather.DtTxt.DateTime }; entity.WeatherMain = new WeatherMain { Humidity = (int)weather.Main.Humidity, Pressure = (int)weather.Main.Pressure, Temperature = weather.Main.Temp - KelvinToCelciusDifference, TemperatureMax = weather.Main.TempMax - KelvinToCelciusDifference, TemperatureMin = weather.Main.TempMin - KelvinToCelciusDifference }; entity.Wind = new Common.Models.Wind { Direction = weather.Wind.Deg, Speed = weather.Wind.Speed }; entities.Add(entity); } return(entities); }
public static string ToJson(this Forecast self) { return(JsonConvert.SerializeObject(self, OpenWeatherMap.DTO.Converter.Settings)); }