internal static void addItemToCart(object sender, ref LineItems _shoppingCart, ref int _runningTotal) { //if(CurrentInvoice.LineItems.Where()) DataGridRow row = sender as DataGridRow; Item selectedItem = (row.Item as Item); if (selectedItem != null) { //ifshoppingcart already contains item with same itemcode, then just add 1 if (_shoppingCart.containsItem(selectedItem.ItemCode)) { _shoppingCart.lineItems.Where(x => x.Item.ItemCode == selectedItem.ItemCode).FirstOrDefault().Quantity++; } //otherwise add selectedItem to the running list else { _shoppingCart.addLineItem(new LineItem(selectedItem, 1)); } _runningTotal += Int32.Parse(selectedItem.Cost); } }
/// <summary> /// This method is important for adding all new Items to an invoice so the line item is updated and that the totalItems /// property is also updated. /// </summary> /// <param name="Item"></param> /// <param name="quantity"></param> public void addItem(Item Item, int quantity) { LineItems.addLineItem(new LineItem(Item, quantity)); TotalItems += quantity; }