public void EditCartItemQty(string itemId, string quantity)
        {
            model = (ShopModel)Session["model"]; // get the model object
            Item currentItem = null;

            // For each item in the item catalog, check whether the item's ID matches the
            // input ID.
            foreach (var i in model.itemCatalog)
            {
                if (i.itemID == Int32.Parse(itemId) /*Parse Item ID, TODO: exception handling... */)
                {
                    currentItem = i; break; // there is a match - store the matching item and break out of the loop
                }
            }

            if (currentItem != null) // if we have found an item
            {
                model.shoppingCart = CheckoutFacilitator.EditQuantity(currentItem, Int32.Parse(quantity), model);
            }
            Session["model"] = model; // reassign model.
        }
Exemple #2
0
        public void EditQuantityTest()
        {
            ShopModel tempModel = new ShopModel();

            tempModel.shoppingCart = new Dictionary <Item, int>();
            Item item1 = new Item
            {
                itemID       = 1,
                name         = "Item1",
                sellingPrice = 50
            };

            tempModel.shoppingCart.Add(item1, 5);                  // added 5 of item 1 to cart.

            CheckoutFacilitator.EditQuantity(item1, 2, tempModel); // should now have 2 of item1

            if (tempModel.shoppingCart[item1] != 2)
            {
                Assert.Fail();
            }
        }