Example #1
0
        public void InsertCartItemTest()
        {
            CartRepository.AddToCart(cart);
            var cartFromList = CartRepository.GetCartItemById(cart.Id);

            Assert.AreEqual(cart, cartFromList);
        }
Example #2
0
        public void GetCartItemByProductIdTest()
        {
            CartRepository.AddToCart(cart);

            var cartItemFromList = CartRepository.GetCartItemByProductId(cart.StockControl.Product.Id);

            Assert.IsNotNull(cartItemFromList);
        }
Example #3
0
        public void GetCartItemByIdTest()
        {
            CartRepository.AddToCart(cart);

            var cartFromList = CartRepository.GetCartItemById(cart.Id);

            Assert.IsNotNull(cartFromList);
        }
Example #4
0
        public void InsufficientAmountIncreaseQuantityTest()
        {
            CartRepository.AddToCart(cart2);

            var increasedQuantity = CartRepository.IncreaseQuantity(cart2.StockControl.Product.Id);

            Assert.IsFalse(increasedQuantity);
        }
Example #5
0
        public void IncreaseQuantityTest()
        {
            CartRepository.AddToCart(cart);

            var increasedQuantity = CartRepository.IncreaseQuantity(cart.StockControl.Product.Id);

            Assert.IsTrue(increasedQuantity);
        }
Example #6
0
        public void RemoveCartItemTest()
        {
            CartRepository.AddToCart(cart);
            var cartItemFromList = CartRepository.GetCartItemById(cart.Id);

            CartRepository.RemoveCartItem(cartItemFromList);
            var checkRemovedCartItem = CartRepository.GetCartItemById(cartItemFromList.Id);

            Assert.IsNull(checkRemovedCartItem);
        }
Example #7
0
        public void UpdateCartItemTest()
        {
            CartRepository.AddToCart(cart);
            var cartFromList = CartRepository.GetCartItemByProductId(cart.StockControl.Product.Id);

            cartFromList.Quantity = 2;

            CartRepository.Update(cartFromList);

            Assert.Contains(cartFromList, CartRepository.GetCartItems());
        }
Example #8
0
        public int AddToCart(int ItemId, string ItemName)
        {
            Cart cart  = new Cart();
            int  count = GetTotal();

            count++;
            cart.ItemId   = ItemId;
            cart.ItemName = ItemName + " in Cart " + count;
            cartRepository.AddToCart(cart);
            return(cart.Id);
        }
Example #9
0
        public String Add([FromRoute] string item)
        {
            string session_id = Request.Headers["session-id"];

            if (session_id == null)
            {
                Console.WriteLine("Session running");
                Guid id = allCarts.AddNewCart(item);
                Response.Headers.Add("session-id", id.ToString());
            }
            else
            {
                allCarts.AddToCart(Guid.Parse(session_id), item);
            }
            return("Item added to Shopping Cart");
        }
        public ActionResult Create(int productId)
        {
            try
            {
                var cartInList = CartRepository.GetCartItemByProductId(productId);

                if (cartInList != null)
                {
                    if (cartInList.StockControl.ProductAmount > cartInList.Quantity)
                    {
                        cartInList.Quantity = ++cartInList.Quantity;
                        CartRepository.Update(cartInList);
                    }
                    else
                    {
                        var stockControls = Repository.StockControlRepository.GetStockControls();
                        ModelState.AddModelError(string.Empty, "Nuk ka produkt te mjaftueshem ne stok!");
                        return(View("~/Views/StockControls/Index.cshtml", stockControls));
                    }
                }
                else
                {
                    var cartItem = new Cart
                    {
                        Quantity       = 1,
                        CreatedAt      = DateTimeOffset.Now,
                        StockControlId = productId,
                        StockControl   = Repository.StockControlRepository.GetStockControlById(productId)
                    };

                    CartRepository.AddToCart(cartItem);
                }

                return(RedirectToAction(nameof(Index), "StockControls"));
            }
            catch
            {
                return(View());
            }
        }
Example #11
0
        public static void AddToCart(int UserId, int ProductId, int Quantity)
        {
            Cart newCart = new CartFactory().CreateCartData(UserId, ProductId, Quantity);

            CartRepository.AddToCart(newCart);
        }