public static bool AddInventory(InventoryItem item) { try { Int32 foundIndex = 0; if (item.ProductCode[0] == 'W') { foundIndex = WiPItems.ToList().FindIndex(x => item.MasterID != -1 && x.MasterID == item.MasterID); if (foundIndex == -1) { WiPItems.Add(item); // not found, add new } else { InventoryItem existingItem = WiPItems[foundIndex]; //update old inventory existingItem.SetValues(item); // WiP inventory should only occur once, so set to the most recent value since this is a overwrite load. } } else { foundIndex = InventoryItems.FindIndex(x => item.MasterID != -1 && x.MasterID == item.MasterID); if (foundIndex == -1) { AddInventoryItem(item); // not found, add new } else { InventoryItem existingItem = InventoryItems[foundIndex]; //update old inventory existingItem.Units += item.Units; // add the units, as } } } catch (Exception) { return(false); } return(true); }