public StoredWeather Create(IWeather weather, string message, WeatherType type, int daysAhead) { var forecast = new StoredWeather(); switch (type) { case WeatherType.Current: CurrentWeather currentWeather = weather as CurrentWeather; forecast.CityId = currentWeather.Id; forecast.QueryDate = DateTime.Now; forecast.RequiredDate = DateTime.Now; forecast.Type = WeatherType.Current; forecast.Message = message; break; case WeatherType.Forecast: WeatherForecast weatherForecast = weather as WeatherForecast; forecast.CityId = weatherForecast.City.Id; forecast.QueryDate = DateTime.Now; forecast.RequiredDate = DateTime.Now.AddDays(daysAhead); forecast.Type = WeatherType.Forecast; forecast.Message = message; break; } return(forecast); }
public void Add(StoredWeather forecast) { _context.CashedForecasts.Add(forecast); _context.SaveChanges(); }