コード例 #1
0
ファイル: ProductsController.cs プロジェクト: norb-c/Shop
        public async Task <IActionResult> GetProductInCategory(int childId, [FromQuery] ProductQueryParams queryParams)
        {
            var products = await this.repo.GetProductInCategory(childId, queryParams);

            var productToList = this.mapper.Map <QueryResultResource <ProductForList> >(products);

            return(Ok(productToList));
        }
コード例 #2
0
ファイル: ProductsController.cs プロジェクト: norb-c/Shop
        public async Task <IActionResult> GetArchiveProducts([FromQuery] ProductQueryParams queryParams)
        {
            var products = await this.repo.GetArchiveProduct(queryParams);

            var productToList = this.mapper.Map <QueryResultResource <ProductForList> >(products);

            return(Ok(productToList));
        }
コード例 #3
0
ファイル: ProductRepository.cs プロジェクト: norb-c/Shop
        public async Task <QueryResult <Product> > GetArchiveProduct(ProductQueryParams queryParams)
        {
            var query = this.context.Products
                        .Where(p => p.Deleted)
                        .Include(x => x.Photos)
                        .Include(ch => ch.ChildCategory)
                        .ThenInclude(c => c.Category).AsQueryable();

            return(await this.ApplyPagingAndSorting(query, queryParams));
        }
コード例 #4
0
ファイル: ProductRepository.cs プロジェクト: norb-c/Shop
        public async Task <QueryResult <Product> > GetProducts(ProductQueryParams queryParams)
        {
            var query = queryParams.LowItems ? this.context.Products
                        .Select(x => new Product
            {
                Sizes = x.Sizes,
                Title = x.Title,
                Id    = x.Id
            })
                        .Where(p => !p.Deleted)
                        .AsQueryable()
                                                        :
                        this.context.Products
                        .Where(p => !p.Deleted)
                        .Include(x => x.Photos)
                        .Include(ch => ch.ChildCategory)
                        .ThenInclude(c => c.Category).AsQueryable();


            return(await this.ApplyPagingAndSorting(query, queryParams));
        }
コード例 #5
0
ファイル: ProductRepository.cs プロジェクト: norb-c/Shop
        public async Task <QueryResult <Product> > GetProductInCategory(int childId, ProductQueryParams queryParams)
        {
            var queryResult = new QueryResult <Product>();

            var query = queryParams.Deleted ?
                        this.context.Products
                        .Include(p => p.Photos)
                        .Where(x => x.ChildCategoryId == childId && x.Deleted)
                        .Include(ch => ch.ChildCategory)
                        .ThenInclude(c => c.Category)
                        .AsQueryable()

                                                        :

                        this.context.Products
                        .Include(p => p.Photos)
                        .Where(x => x.ChildCategoryId == childId && !x.Deleted)
                        .Include(ch => ch.ChildCategory)
                        .ThenInclude(c => c.Category)
                        .AsQueryable();

            return(await this.ApplyPagingAndSorting(query, queryParams));
        }
コード例 #6
0
ファイル: ProductRepository.cs プロジェクト: norb-c/Shop
        private async Task <QueryResult <Product> > ApplyPagingAndSorting(IQueryable <Product> query, ProductQueryParams queryParams)
        {
            var queryResult = new QueryResult <Product>();

            var columMap = new Dictionary <string, Expression <Func <Product, object> > >()
            {
                ["price"]       = v => v.Price,
                ["sold"]        = v => v.Sold,
                ["lastUpdated"] = v => v.LastUpdated,
                ["featured"]    = v => v.Featured,
            };

            query = query.ApplyOrdering(queryParams, columMap);

            queryResult.TotalItems = await query.CountAsync();

            queryResult.Items = query.ApplyPaging(queryParams);

            return(queryResult);
        }