public TEntity Get(Expression <Func <TEntity, bool> > filter)
 {
     using (ReCapContext context = new ReCapContext())
     {
         return(context.Set <TEntity>().SingleOrDefault(filter));
     }
 }
 public List <TEntity> GetAll(Expression <Func <TEntity, bool> > filter = null)
 {
     using (ReCapContext context = new ReCapContext())
     {
         return(filter == null?context.Set <TEntity>().ToList() : context.Set <TEntity>().Where(filter).ToList());
     }
 }
 public void Update(TEntity entity)
 {
     using (ReCapContext context = new ReCapContext())
     {
         var updatedEntity = context.Entry(entity);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public bool IsCarAvailable(int carId)
 {
     using (ReCapContext context = new ReCapContext())
     {
         var result = from r in context.Rentals
                      where r.CarId == carId && r.ReturnDate == null
                      select r;
         return((result.Count() == 0) ? true : false);
     }
 }