Beispiel #1
0
        public Domain.Models.CityWeatherInfo Get(int id)
        {
            try
            {
                using (var context = new CityWeatherInfoContext())
                {
                    var c = context.Cities.Find(id);
                    if (c == null)
                    {
                        return(null);
                    }

                    return(new Domain.Models.CityWeatherInfo
                    {
                        CityId = c.CityId,
                        Name = c.Name,
                        TempDay = c.TempDay,
                        TempNight = c.TempNight,
                        WeatherComment = c.WeatherComment
                    });
                }
            }
            catch (Exception e)
            {
                throw new Domain.Exceptions.CityWeatherInfoRepositoryException(e.Message, e);
            }
        }
Beispiel #2
0
 public void Delete(int id)
 {
     try
     {
         using (var context = new CityWeatherInfoContext())
         {
             var info = context.Cities.Find(id);
             if (info != null)
             {
                 context.Cities.Remove(info);
             }
         }
     }
     catch (Exception e)
     {
         throw new Domain.Exceptions.CityWeatherInfoRepositoryException(e.Message, e);
     }
 }
Beispiel #3
0
 public IEnumerable <Domain.Models.CityWeatherInfo> GetAll()
 {
     try
     {
         using (var context = new CityWeatherInfoContext())
         {
             return(context.Cities.Select(c => new Domain.Models.CityWeatherInfo
             {
                 CityId = c.CityId,
                 Name = c.Name,
                 TempDay = c.TempDay,
                 TempNight = c.TempNight,
                 WeatherComment = c.WeatherComment
             }).ToList());
         }
     }
     catch (Exception e)
     {
         throw new Domain.Exceptions.CityWeatherInfoRepositoryException(e.Message, e);
     }
 }
Beispiel #4
0
 public void Update(Domain.Models.CityWeatherInfo item)
 {
     try
     {
         using (var context = new CityWeatherInfoContext())
         {
             var daoModel = new CityWeatherInfo
             {
                 CityId         = item.CityId,
                 Name           = item.Name,
                 TempDay        = item.TempDay,
                 TempNight      = item.TempNight,
                 WeatherComment = item.WeatherComment
             };
             context.Entry(daoModel).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw new Domain.Exceptions.CityWeatherInfoRepositoryException(e.Message, e);
     }
 }