Exemple #1
0
        public async Task <IActionResult> OnPostRemoveToCartAsync(string productId)
        {
            var cart = await _basketApi.GetBasket("johndoe");

            var item = cart.Items.FirstOrDefault(x => x.ProductId == productId);

            if (item != null)
            {
                cart.Items.Remove(item);
                await _basketApi.CreateBasket(cart);
            }

            return(RedirectToPage());
        }
        public async Task <IActionResult> OnPostAddToCartAsync(string productId)
        {
            Models.ProductModel product = await _catalogApi.GetProduct(productId);

            string      username = "******";
            BasketModel basket   = await _basketApi.GetBasket(username);

            basket.Items.Add(new BasketItemModel
            {
                ProductId   = productId,
                ProductName = product.Name,
                Price       = product.Price,
                Quantity    = 1,
                Color       = "Black"
            });
            basket = await _basketApi.CreateBasket(basket);

            return(RedirectToPage("Cart"));
        }