Example #1
0
 public Car Get(Expression <Func <Car, bool> > filter = null)
 {
     using (CarRentalDBContext context = new CarRentalDBContext())
     {
         return(context.Set <Car>().SingleOrDefault(filter));
     }
 }
Example #2
0
 public void Update(Car entity)
 {
     using (CarRentalDBContext context = new CarRentalDBContext())
     {
         var updatedCar = context.Entry(entity);
         updatedCar.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #3
0
        public List <Car> GetAll(Expression <Func <Car, bool> > filter = null)
        {
            using (CarRentalDBContext context = new CarRentalDBContext())
            {
                return(filter == null?context.Set <Car>().ToList() : context.Set <Car>().Where(filter).ToList());

                // filter = holding lambda expressions while using Linq queries
            }
        }
Example #4
0
 public void Delete(Car entity)
 {
     using (CarRentalDBContext context = new CarRentalDBContext())
     {
         var deletedCar = context.Entry(entity);
         deletedCar.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Example #5
0
 public void Add(Car entity)
 {
     using (CarRentalDBContext context = new CarRentalDBContext())
     {
         var addedCar = context.Entry(entity);
         addedCar.State = EntityState.Added;
         context.SaveChanges();
     }
 }