Esempio n. 1
0
        public void AddCartItem(int productId, int userId)
        {
            var stock = _productRepository.GetProductAvailableStock(productId);

            if (stock == 0)
            {
                throw new BgsException((int)WebApiErrorCodes.OutOfStock);
            }
            else
            {
                var cartItem = _cartRepository.GetCartItem(productId, userId);

                using (var transaction = new BgsTransactionScope())
                {
                    if (cartItem == null)
                    {
                        _cartRepository.AddCartItem(productId, userId, 1, DateTime.Now);
                    }
                    else
                    {
                        _cartRepository.UpdateCartItemQuantity(cartItem.Id, cartItem.Quantity + 1);
                    }

                    BlockStock(productId, 1);

                    transaction.Complete();
                }
            }
        }
        /// <summary>
        /// Add free item to cart
        /// </summary>
        /// <param name="productID">Product ID</param>
        /// <param name="quantity">Quantity</param>
        public void AddFreeCartItem(int productID, int quantity)
        {
            try
            {
                var mProduct  = _productRepository.GetProductByID(productID);
                var mLineItem = new LineItem()
                {
                    ProductID    = productID,
                    Quantity     = quantity,
                    LineItemType = LineItem.LineItemTypes.FreeItem
                };

                _cartRepository.AddCartItem(mLineItem);
            }
            catch (System.Exception ex)
            {
                //Log ex

                //re-throw new custom exception to User.
                throw new System.Exception("Error while processing discount to cart");
            }
        }
Esempio n. 3
0
        public ActionResult AddToCart(IFormCollection collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _repository.FillBookLibrary();
                    var customer = _repository.GetCustomers().Where(c => c.ID == Int32.Parse(TempData.Peek("CustomerID").ToString())).First();
                    var book     = Domain.Models.Book.GetBookFromLibrary(collection["isbn"]);
                    int quantity = Int32.Parse(collection["qty"]);

                    _cartrepository.AddCartItem(customer, book, quantity);

                    TempData["TotalCartItems"] = customer.GetCartItemCount();
                    return(RedirectToAction(nameof(Index)));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
Esempio n. 4
0
 public List <AddCartItemResponeseModel> AddCartItem(string userId, string cartId, string storeId, OfflineCartItemModel inventoryId)
 {
     return(_cartRepository.AddCartItem(userId, cartId, storeId, inventoryId));
 }