Beispiel #1
0
        public WeatherInfo GetWeatherInfo(string value)
        {
            var dbContext   = new WeatherInfoDbContext();
            var weatherInfo = dbContext.WeatherInfo.Where(x => x.City == value).FirstOrDefault();

            return(weatherInfo != null? new WeatherInfo()
            {
                City = weatherInfo.City, Temperature = weatherInfo.Temperature, Forecast = weatherInfo.Forecast
            }
                                     :weatherInfo);
        }
Beispiel #2
0
 public void InsertWeatherInfo(WeatherInfo weather)
 {
     try
     {
         var dbContext = new WeatherInfoDbContext();
         dbContext.WeatherInfo.Add(weather);
         dbContext.SaveChanges();
     }
     catch (Exception e)
     {
         throw new Exception($"Error while saving data. See details, Cannot insert duplicate records.");
     }
 }