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); } }