Exemple #1
0
        /// <summary>
        /// Adds an item to a cart
        /// </summary>
        /// <param name="visitorId">Id of the Visitor</param>
        /// <param name="userId">Id of the user</param>
        /// <param name="productId">Product identifier</param>
        /// <param name="amount">Product amount</param>
        /// <returns>DTO of the cart</returns>
        public AlzaAdminDTO <List <CartItem> > AddToCart(string visitorId, int?userId, int productId, int amount = 1)
        {
            try
            {
                var currentCartItem = _cartItemRepository.GetCartItem(visitorId, productId);
                if (currentCartItem != null)
                {
                    currentCartItem.Amount += amount;
                    _cartItemRepository.UpdateCartItem(currentCartItem);
                }
                else
                {
                    var cartItem = new CartItem {
                        VisitorId = visitorId, Amount = amount, ProductId = productId, UserId = userId
                    };
                    _cartItemRepository.AddCartItem(cartItem);
                }

                return(GetCart(visitorId));
            }
            catch (Exception e)
            {
                return(AlzaAdminDTO <List <CartItem> > .Error(e.Message + Environment.NewLine + e.StackTrace));
            }
        }
Exemple #2
0
 public void Add(CartItem cartItem)
 {
     if (cartItem != null)
     {
         cartItemRepository.AddCartItem(cartItem);
     }
 }
Exemple #3
0
        public ActionResult AddCart(long productId, int quanlity, decimal pricePerProduct)
        {
            var  customer = Session["CUSTOMER"] as Customer;
            Cart cart     = new Cart
            {
                CustomerId = customer.Id
            };

            try
            {
                var      cartId   = _cartRepository.AddCart(cart);
                CartItem cartItem = new CartItem()
                {
                    CartId          = cartId,
                    ItemStatus      = Constants.PENDING,
                    PricePerProduct = pricePerProduct,
                    Quantity        = quanlity,
                    ProductId       = productId
                };
                _cartItemRepository.AddCartItem(cartItem);
                return(RedirectToAction("LoadCartList", "Cart"));
                //ShopCartViewModel shopCartViewModel = GetCartPageViewData(null, null);
                //return View("ShopCart", shopCartViewModel);
            }
            catch (System.Exception)
            {
                throw;
            }
        }