コード例 #1
0
        public async Task <IActionResult> OnPostRemoveToCartAsync(string productId)
        {
            var userName = "******";
            var basket   = await _basketApi.GetBasketAsync(userName);

            var item = basket.Items.Single(r => r.ProductId == productId);

            basket.Items.Remove(item);

            var basketUpdated = await _basketApi.UpdateBasketAsync(basket);

            return(RedirectToPage());
        }
コード例 #2
0
        public async Task <IActionResult> OnPostAddToCartAsync(string productId)
        {
            var product = await _catalogApi.GetCatalogByIdAsync(productId);

            var userName = "******";
            var basket   = await _basketApi.GetBasketAsync(userName);

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

            var backetUpdated = await _basketApi.UpdateBasketAsync(basket);

            return(RedirectToPage("Cart"));
        }