Example #1
0
 public Car Get(Expression <Func <Car, bool> > filter)
 {
     using (RentalContext context = new RentalContext())
     {
         return(context.Set <Car>().SingleOrDefault(filter));
     }
 }
Example #2
0
 public void Update(Car entity)
 {
     using (RentalContext context = new RentalContext())
     {
         var updatedEntity = context.Entry(entity);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #3
0
 public void Delete(Car entity)
 {
     using (RentalContext context = new RentalContext())
     {
         var deletedEntity = context.Entry(entity);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Example #4
0
 public void Add(Car entity)
 {
     using (RentalContext context = new RentalContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Example #5
0
 public List <Car> GetAll(Expression <Func <Car, bool> > filter = null)
 {
     using (RentalContext context = new RentalContext())
     {
         if (filter == null)
         {
             return(context.Set <Car>().ToList());
         }
         else
         {
             return(context.Set <Car>().Where(filter).ToList());
         }
     }
 }