Esempio n. 1
0
 public virtual void Delete(TEntity TEntity, bool?forzarRetiro = null)
 {
     if (Context.Entry(TEntity).State == EntityState.Detached)
     {
         DbSet.Attach(TEntity);
     }
     if (forzarRetiro != null)
     {
         if (forzarRetiro.Value)
         {
             DbSet.Remove(TEntity);
         }
     }
     else
     {
         if (UtilRepo.HasMember(TEntity, "habilitado"))
         {
             this.Disabled(TEntity);
         }
         else
         {
             DbSet.Remove(TEntity);
         }
     }
 }
Esempio n. 2
0
        public virtual TEntity Find(Expression <Func <TEntity, bool> > predicate)
        {
            var name = typeof(TEntity);

            if (UtilRepo.GetMember(name, "habilitado"))
            {
                return(DbSet.Where("habilitado").FirstOrDefault(predicate));
            }
            else
            {
                return(DbSet.FirstOrDefault(predicate));
            }
        }
Esempio n. 3
0
        public bool Contains(Expression <Func <TEntity, bool> > predicate)
        {
            var name = typeof(TEntity);

            if (UtilRepo.GetMember(name, "habilitado"))
            {
                return(DbSet.Where("habilitado").Count(predicate) > 0);
            }
            else
            {
                return(DbSet.Count(predicate) > 0);
            }
        }
Esempio n. 4
0
        public virtual IQueryable <TEntity> Filter(Expression <Func <TEntity, bool> > predicate)
        {
            var name = typeof(TEntity);

            if (UtilRepo.GetMember(name, "habilitado"))
            {
                return(DbSet.Where(predicate).Where("habilitado").AsQueryable <TEntity>());
            }
            else
            {
                return(DbSet.Where(predicate).AsQueryable <TEntity>());
            }
        }
Esempio n. 5
0
        public virtual IQueryable <TEntity> All()
        {
            var name = typeof(TEntity);

            if (UtilRepo.GetMember(name, "habilitado"))
            {
                return(DbSet.Where("habilitado").AsQueryable <TEntity>());
            }
            else
            {
                return(DbSet.AsQueryable());
            }
        }
Esempio n. 6
0
 public virtual TEntity Create(TEntity TEntity)
 {
     try
     {
         if (UtilRepo.HasMember(TEntity, "habilitado"))
         {
             Context.Entry(TEntity).Member("habilitado").CurrentValue = true;
         }
         var newEntry = DbSet.Add(TEntity);
         return(newEntry);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 7
0
        public virtual IQueryable <TEntity> Filter <Key>(Expression <Func <TEntity, bool> > filter, out int total, int index = 0, int size = 50)
        {
            int skipCount = index * size;
            var name      = typeof(TEntity);

            if (UtilRepo.GetMember(name, "habilitado"))
            {
                var _resetSet = filter != null?DbSet.Where(filter).Where("habilitado") : DbSet;

                _resetSet = skipCount == 0 ? _resetSet.Take(size) : _resetSet.AsEnumerable().Skip(skipCount).Take(size).AsQueryable();
                total     = _resetSet.Where("habilitado").Count();
                return(_resetSet);
            }
            else
            {
                //int skipCount = index * size;
                var _resetSet = filter != null?DbSet.Where(filter) : DbSet;

                _resetSet = skipCount == 0 ? _resetSet.Take(size) : _resetSet.AsEnumerable().Skip(skipCount).Take(size).AsQueryable();
                total     = _resetSet.Count();
                return(_resetSet);
            }
        }