Ejemplo n.º 1
0
        public virtual PaginateResponse <TEntity> Paginate(TFilter filter, int current = 1, int rowCount = 10)
        {
            var entities = new List <TEntity>();
            var response = new PaginateResponse <TEntity>();

            try
            {
                entities = ApplyFilter(filter);
                int total = entities.Count;

                if (rowCount != -1)
                {
                    entities = entities.Skip((current - 1) * rowCount).Take(rowCount).ToList();
                }

                response.Current  = current;
                response.RowCount = rowCount;
                response.Total    = total;
                response.Rows     = entities;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(response);
        }
Ejemplo n.º 2
0
        public IActionResult Get(int pageIndex, int pageSize)
        {
            var data = _context.Orders
                       .Include(o => o.Customer)
                       .OrderByDescending(c => c.Placed);

            var page = new PaginateResponse <Order>(data, pageIndex, pageSize);

            return(Ok(page));
        }
        public IActionResult Get(int pageIndex, int pageSize)
        {
            var data = _ctx.Orders.Include(o => o.Customer)
                       .OrderByDescending(c => c.Placed);

            var page = new PaginateResponse <Order>(data, pageIndex, pageSize);

            var totalCount = data.Count();
            var totalPages = Math.Ceiling((double)totalCount / pageSize);

            var response = new
            {
                Page       = page,
                TotalPages = totalPages
            };

            return(Ok(response));
        }