/// <summary> /// Edits item quantity /// </summary> /// <param name="cartItem"></param> /// <param name="newNum"></param> public IActionResult EditCartItem(EditCart editCart) { int newAmt = editCart.OrderNum; var itemQuantity = (from Inventory in _db.Inventory where Inventory.StoreInventory == editCart.storeId && Inventory.ItemInInventory == editCart.itemId select Inventory.ProductCurrentQuantity).FirstOrDefault(); if (newAmt > itemQuantity) { ModelState.AddModelError("newAmt", "Input is too large!"); return(View("_Checkcart")); } //TODO Add a check to make sure new quantity isnt more than whats available //TODO Finish the editting functionality var itemCart = _cache.Get("Cart"); List <OrderInformation> cart = new List <OrderInformation>(); cart = (List <OrderInformation>)itemCart; //Select the item from our cart that needs to be edited and edit OrderInformation edit = new OrderInformation(); edit = StoreMethods.ManipulateCartItem(editCart.itemId, cart); //Update the items ordered amount and total unit price edit.OrderedProductAmount = newAmt; edit.UnitPrice = edit.OrderedProductAmount * (edit.UnitPrice * (1 - edit.ProductDiscount)); _cache.Set("Cart", cart); return(RedirectToAction("_CheckCart")); }
/// <summary> /// Deletes item from cart /// </summary> /// <param name="cartItem"></param> public IActionResult DeleteCartItem(OrderInformation cartItem) { var itemCart = _cache.Get("Cart"); List <OrderInformation> cart = new List <OrderInformation>(); cart = (List <OrderInformation>)itemCart; //Select item to be deleted var delete = StoreMethods.ManipulateCartItem(cartItem.OrderedProduct, cart); cart.Remove(delete); _cache.Set("Cart", cart); return(RedirectToAction("GetCustomerStoreInventory")); }