Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        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);
        }