Exemplo 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);
         }
     }
 }
Exemplo 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));
            }
        }
Exemplo 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);
            }
        }
Exemplo 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>());
            }
        }
Exemplo 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());
            }
        }
Exemplo 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);
     }
 }
Exemplo 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);
            }
        }