Example #1
0
 public void Add(T entity)
 {
     using (var context = new PrzychodniaLekarskaContext())
     {
         context.Set <T>().Add(entity);
         context.SaveChanges();
     }
 }
Example #2
0
 public void Update(T entity)
 {
     using (var context = new PrzychodniaLekarskaContext())
     {
         context.Set <T>().Attach(entity);
         context.Entry <T>(entity).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #3
0
 public int AddAndReturnId(T entity)
 {
     using (var context = new PrzychodniaLekarskaContext())
     {
         context.Set <T>().Add(entity);
         context.SaveChanges();
         context.Entry(entity).GetDatabaseValues();
         return(entity.ID);
     }
 }
Example #4
0
 public List <T> FindAll(params Expression <Func <T, object> >[] includeItems)
 {
     using (var context = new PrzychodniaLekarskaContext())
     {
         var result = context.Set <T>() as IQueryable <T>;
         foreach (var include in includeItems)
         {
             result = result.Include(include);
         }
         return(result.Where(x => !x.IsDeleted).ToList());
     }
 }
Example #5
0
 public bool Any(Func <T, bool> filter, params Expression <Func <T, object> >[] includeItems)
 {
     using (var context = new PrzychodniaLekarskaContext())
     {
         var result = context.Set <T>() as IQueryable <T>;
         foreach (var include in includeItems)
         {
             result = result.Include(include);
         }
         return(result.Where(x => !x.IsDeleted).Where(filter).Any());
     }
 }
Example #6
0
 public T FindById(int id, params Expression <Func <T, object> >[] includeItems)
 {
     using (var context = new PrzychodniaLekarskaContext())
     {
         var result = context.Set <T>() as IQueryable <T>;
         foreach (var include in includeItems)
         {
             result = result.Include(include);
         }
         return(result.FirstOrDefault(x => x.ID == id && !x.IsDeleted));
     }
 }