Exemple #1
0
        public async Task <PagedList <IcProductStock> > GetIcProductStockPaged(IcProductStockParams icProductStockParams)
        {
            var icProductStocks = _iicproductstockrepository.GetEntitys();

            //icWarehouses = icWarehouses.Where();
            return(await PagedList <IcProductStock> .CreatePagedList(icProductStocks, icProductStockParams.PageSize, icProductStockParams.PageNum));
        }
        private string CreateLink(PagedType pagedType, IcProductStockParams icProductStockParams)
        {
            switch (pagedType)
            {
            case PagedType.Previous:
                return(Url.Link(nameof(GetIcProductStocks), new
                {
                    PageNum = icProductStockParams.PageNum - 1,
                    PageSize = icProductStockParams.PageSize
                }));

            case PagedType.Next:
                return(Url.Link(nameof(GetIcProductStocks), new
                {
                    PageNum = icProductStockParams.PageNum + 1,
                    PageSize = icProductStockParams.PageSize
                }));
            }
            return(string.Empty);
        }
        public async Task <ActionResult <IEnumerable <IcProductStockDto> > > GetIcProductStocks([FromQuery] IcProductStockParams icProductStockParams)
        {
            var res  = new MessageModel <IEnumerable <IcProductStockDto> >();
            var list = await _icProductStockServices.GetIcProductStockPaged(icProductStockParams);

            string previousLink = list.HasPrevious ? CreateLink(PagedType.Previous, icProductStockParams) : null;
            string nextLink     = list.HasNext ? CreateLink(PagedType.Next, icProductStockParams) : null;
            var    pagination   = new
            {
                currentPage = list.PageNum,
                totalPage   = list.TotalPage,
                totalCount  = list.TotalCount,
                previousLink,
                nextLink
            };

            HttpContext.Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(pagination));
            res.Data = _mapper.Map <IEnumerable <IcProductStockDto> >(list);
            return(Ok(res));
        }