コード例 #1
0
        public async Task <IActionResult> ByCategory([FromQuery] int CategoryId)
        {
            IEnumerable <ProductDto> products = null;

            try
            {
                products = await _ProductFacade.GetProductsByCategory(CategoryId);
            }
            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;

            return(View(viewModel));
        }