Esempio n. 1
0
        public async Task <FilterProductInfo> FilterProduct(FilterProductInfo filter)
        {
            var productQuery = _context.Products.AsQueryable();

            if (!string.IsNullOrEmpty(filter.Title))
            {
                productQuery = productQuery.Where(f => f.ProductName.Contains(filter.Title));
            }


            if (filter.StartPrice != 0)
            {
                productQuery = productQuery.Where(f => f.Price >= filter.StartPrice);
            }

            if (filter.EndPrice != 0)
            {
                productQuery = productQuery.Where(p => p.Price <= filter.EndPrice);
            }


            var count = (int)Math.Ceiling(productQuery.Count() / (double)filter.TakeEntity);
            var pager = PagerInfo.Build(count, filter.PageId, filter.TakeEntity);

            var product = await productQuery.Paging(pager).ToListAsync();

            return(filter.SetProduct(product).SetPaging(pager));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetProduct([FromQuery] FilterProductInfo filter)
        {
            await Task.Delay(2000);

            var products = await _productRepositoryQuery.FilterProduct(filter);

            return(Success(products));
        }