Ejemplo n.º 1
0
        public IActionResult Get(int pageIndex, int pageSize)
        {
            var data       = _context.Orders.Include(o => o.Customer).OrderByDescending(c => c.Placed);
            var page       = new PaginatedResponse <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));
        }
Ejemplo n.º 2
0
        public IActionResult Get(int pageIndex, int pageSize)
        {
            var data = _ctx.Customers.OrderBy(c => c.Id);
            var page = new PaginatedResponse <Customer>(data, pageIndex, pageSize);

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

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

            return(Ok(response));
        }
Ejemplo n.º 3
0
        public IActionResult Get(int pageIndex, int pageSize)
        {
            var data = _ctx.Trips.Include(o => o.Account)
                       .OrderByDescending(c => c.RTA);

            var page = new PaginatedResponse <Trip>(data, pageIndex, pageSize);

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

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

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

            var page       = new PaginatedResponse <Order>(data, pageIndex, pageSize);
            var totalCount = data.Count();
            //will create a new page if there are still some results left that dont fit
            var totalPages = Math.Ceiling((double)totalCount / pageSize);

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

            return(Ok(response));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetAllOrders(int pageIndex, int pageSize)
        {
            //Get orders include customers and sort by orders placed.
            var data = _context.Orders
                       .Include(order => order.Customer)
                       .OrderByDescending(order => order.Placed);

            //Paginate the data.
            var page = new PaginatedResponse <Order>(data, pageIndex, pageSize);

            var totalCount = await data.CountAsync();

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

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

            return(Ok(response));
        }