コード例 #1
0
        public async Task<IActionResult> Items(int? catalogTypeId, int? catalogBrandId, [FromQuery] int pageSize = 5, [FromQuery] int pageIndex = 0)
        {
            var root = (IQueryable<CatalogItem>)catalogContext.CatalogItem;
            if (catalogTypeId.HasValue)
            {
                root = root.Where(m => m.CatalogTypeId == catalogTypeId.Value);
            }

            if (catalogBrandId.HasValue)
            {
                root = root.Where(m => m.CatalogBrandId == catalogBrandId.Value);
            }

            var totalItems = await root
                                    .LongCountAsync();

            var itemsOnPage = await root.OrderBy(m => m.Name)
                                                .Skip(pageSize * pageIndex)
                                                .Take(pageSize)
                                                .ToListAsync();

            itemsOnPage = ChangeUrlPlaceHolder(itemsOnPage);
            var model = new PageniatedItemsViewModel<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage);
            return Ok(model);
        }
コード例 #2
0
        public async Task<IActionResult> Items([FromQuery] int pageSize = 5, [FromQuery] int pageIndex = 0)
        {
            var totalItems = await catalogContext.CatalogItem.LongCountAsync();

            var itemsOnPage = await catalogContext.CatalogItem.OrderBy(m => m.Name)
                                                .Skip(pageSize * pageIndex)
                                                .Take(pageSize)
                                                .ToListAsync();

            itemsOnPage = ChangeUrlPlaceHolder(itemsOnPage);
            var model = new PageniatedItemsViewModel<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage);
            return Ok(model);
        }