예제 #1
0
        private List <ProductInCart> FindProductInCart(string arProdId)
        {
            var listCartItem = JsonSerializer.Deserialize <List <CartDTO> >(arProdId);

            int[] productIds = listCartItem.Select(item => item.ProductId).ToArray();
            if (productIds.Length == 0)
            {
                return(null);
            }
            MapProductDTO(_productSer.GetListById(productIds));
            var listProductCart = new List <ProductInCart>();

            foreach (var item in listCartItem)
            {
                var product = ListProducts.Find(p => p.Id == item.ProductId);
                listProductCart.Add(new ProductInCart()
                {
                    ProductId      = item.ProductId,
                    ProductName    = $"{product.Name} {product.BandName} {product.WireName}",
                    ProductImage   = product.Image,
                    Quantity       = item.Quantity,
                    Price          = product.Price,
                    PricePromotion = (product.Discount % 1 == 0) ?
                                     (product.Price - product.Discount) :
                                     (product.Price - (product.Price * product.Discount))
                });
            }
            return(listProductCart);
        }
예제 #2
0
        public IActionResult OnGet([FromServices] IWebHostEnvironment env, string name)
        {
            ListProducts = _cache.GetData <List <ProductDTO> >(KEY_CACHE_DISCOUNT);
            int prodId = GetProductId(name);

            FindListImage(0, env.WebRootPath);
            if (ListProducts != null && ListProducts.Count > 0)
            {
                Product = ListProducts.Find(item => item.Id == prodId);
            }
            if (Product == null)
            {
                var productAsset = _productSer.GetListById(new int[] { prodId });
                if (productAsset == null || productAsset?.Count == 0)
                {
                    return(RedirectToPage("/error/" + ErrorType.ProductNotFound));
                }
                var prod = _mapper.Map <ProductDTO>(productAsset.First());
                var ls   = new List <ProductDTO>()
                {
                    prod
                };
                CheckProm(ls);
                Product = ls[0];
            }
            ProductDetail = _productSer.GetDetail(prodId);
            return(Page());
        }