public Car Get(Expression <Func <Car, bool> > filter)
 {
     using (RentCarContext context = new RentCarContext())
     {
         return(context.Set <Car>().SingleOrDefault(filter));
     }
 }
 public List <Car> GetAll(Expression <Func <Car, bool> > filter = null)
 {
     using (RentCarContext context = new RentCarContext())
     {
         return(filter == null?context.Set <Car>().ToList() : context.Set <Car>().Where(filter).ToList());
     }
 }
Exemple #3
0
 public Product Get(Expression <Func <Product, bool> > filter)
 {
     using (RentCarContext context = new RentCarContext())
     {
         return(context.Set <Product>().SingleOrDefault(filter));
     }
 }
 public void Delete(Car entity)
 {
     using (RentCarContext context = new RentCarContext())
     {
         var deletedEntity = context.Entry(entity);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
 public void Update(Car entity)
 {
     using (RentCarContext context = new RentCarContext())
     {
         var updatedEntity = context.Entry(entity);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void Add(Car entity)
 {
     using (RentCarContext context = new RentCarContext())
     {
         var addedEntity = context.Entry(entity);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }