Ejemplo n.º 1
0
        public async Task <IEnumerable <Category> > Search(string filter, PageFilter pf)
        {
            var result = new List <Category>();

            pf.Count = await _db.Categories.Where(c => string.IsNullOrEmpty(filter) || c.CategoryName.Contains(filter)).CountAsync();

            result = await _db.Categories.AsNoTracking().
                     Where(c => string.IsNullOrEmpty(filter) || c.CategoryName.Contains(filter)).
                     OrderBy(pf.Sorting).
                     Skip((pf.Page - 1) * pf.PageSize).
                     Take(pf.PageSize).ToListAsync();

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <List <Category> > ReadAsync(PageFilter pf = null)
        {
            List <Category> result = new List <Category>();

            if (pf != null)
            {
                pf.Count = await db.Categories.CountAsync();

                result = await db.Categories.OrderBy(pf.Sorting).Skip(--pf.Page * pf.PageSize).Take(pf.PageSize).ToListAsync();
            }
            else
            {
                result = await db.Categories.ToListAsync();
            }

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <List <Product> > ReadAsync(PageFilter pf = null)
        {
            List <Product> result = new List <Product>();

            if (pf != null)
            {
                pf.Count = await db.Products.CountAsync();

                result = await db.Products.Include(p => p.Category).Include(p => p.Supplier).
                         OrderBy(pf.Sorting).
                         Skip(--pf.Page * pf.PageSize).
                         Take(pf.PageSize).ToListAsync();
            }
            else
            {
                result = await db.Products.ToListAsync();
            }

            return(result);
        }
Ejemplo n.º 4
0
        public virtual async Task <IEnumerable <T> > GetList(PageFilter pf = null)
        {
            //return await _db.Set<T>().ToListAsync();

            var result = new List <T>();

            if (pf == null)
            {
                result = await _db.Set <T>().AsNoTracking().ToListAsync();
            }
            else
            {
                pf.Count = await _db.Set <T>().CountAsync();

                result = await _db.Set <T>().
                         AsNoTracking().
                         OrderBy(pf.Sorting).
                         Skip((pf.Page - 1) * pf.PageSize).
                         Take(pf.PageSize).ToListAsync();
            }

            return(result);
        }