コード例 #1
0
        public async Task <IActionResult> ByFilter([FromQuery] int CategoryId,
                                                   [FromQuery] int BrandId,
                                                   [FromQuery] double MinPrice,
                                                   [FromQuery] double MaxPrice)
        {
            IEnumerable <ProductDto> products = null;

            try
            {
                products = await _ProductFacade.GetProductsByFilter(CategoryId, BrandId,
                                                                    MinPrice, MaxPrice);
            }
            catch (HttpRequestException)
            {
                _logger.LogWarning("Exception Occured using Product Facade");
                products = null;
            }

            IEnumerable <ProductViewModel> viewModel = products.Select(p => new ProductViewModel
            {
                ProductId   = p.ProductId,
                Name        = p.Name,
                Description = p.Description,
                Quantity    = p.Quantity,
                BrandId     = p.BrandId,
                Brand       = p.Brand,
                CategoryId  = p.CategoryId,
                Category    = p.Category,
                Price       = p.Price
            });

            ViewData["Category"]   = products.First().Category;
            ViewData["Brand"]      = products.First().Brand;
            ViewData["CategoryId"] = MinPrice;
            ViewData["BrandId"]    = MaxPrice;
            ViewData["MinPrice"]   = MinPrice;
            ViewData["MaxPrice"]   = MaxPrice;

            return(View(viewModel));
        }