Ejemplo n.º 1
0
        /// <summary>
        /// Updates a cart item
        /// </summary>
        /// <param name="cart">
        /// Models.Cart: the current cart
        /// </param>
        /// <param name="itemId">
        /// int: a flummery's item ID
        /// </param>
        /// <param name="qty">
        /// int: the flummery's new quantity
        /// </param>
        private async Task UpdateCartItems(Models.Cart cart, int itemId, int qty)
        {
            bool containsCartItem = false;

            if (cart.CartItems != null)
            {
                foreach (var oneCartItem in cart.CartItems)
                {
                    if (oneCartItem.ProductId == itemId)
                    {
                        oneCartItem.Qty += qty;
                        containsCartItem = true;
                        await _cartItem.Update(oneCartItem);

                        break;
                    }
                }
            }
            if (!containsCartItem)
            {
                var newCartItem = new Models.CartItem
                {
                    CartId    = cart.Id,
                    ProductId = itemId,
                    Qty       = qty
                };
                await _cartItem.Create(newCartItem);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates a CartItem.
        /// </summary>
        /// <param name="userId">
        /// string: the user ID of the current user
        /// </param>
        /// <returns>
        /// Task<IActionResult>: redirects back to the cart
        /// </returns>
        public async Task <IActionResult> OnPost(string userId)
        {
            CartItem item = new CartItem()
            {
                CartId    = CartId,
                ProductId = ItemId,
                Qty       = NewQuantity
            };

            await _cartItem.Update(item);

            return(RedirectToPage("/Cart/View"));
        }