Ejemplo n.º 1
0
        public virtual IQueryable <T> BaseEntityFilter <T>(DbSet <T> dbSet, BaseFilterServiceModel model)
            where T : BaseEntity
        {
            var result = dbSet.AsQueryable();

            if (model.EntityStatus != default(int))
            {
                result = result.Where(o => o.Status == (int)model.EntityStatus);
            }

            if (model.Page != default(int))
            {
                result = result.Skip((model.Page) * (model.PageSize - 1)).Take(model.PageSize);
            }

            return(result);
        }
        public static IQueryable <TEntity> FilterByServiceModel <TType, TEntity>(this IQueryable <TEntity> list, BaseFilterServiceModel <TType> serviceModel)
            where TEntity : IEntityWithTypeId <TType>, IEntityWithStatus
        {
            if (serviceModel.Ids != null && serviceModel.Ids.Count() != 0)
            {
                list = list.Where(o => serviceModel.Ids.Contains(o.Id));
            }

            if (serviceModel.EntityStatues != null)
            {
                var statues = serviceModel.EntityStatues.Select(o => (int)o);
                list = list.Where(o => statues.Contains(o.Status));
            }

            return(list);
        }