public void addOrder(Order x) { bool available = true; if (x.orderID > 0) { foreach (Order item in orderList) { if (item.orderID == x.orderID) // search through if key exists in list. { available = false; } } } if (x.orderID == 0) { do { available = true; x.randOrderNum(); // func in Branch.cs that gives a new random orderNum -> [1,10000] foreach (Order item in orderList) { if (item.orderID == x.orderID) { available = false; } } } while (!available); // The fact that the number exists in the list doesn't mean we arent going to add it, just give it a new random numer } //Have to check that the order's hechser fits the branch: if ((int)x.orderHechserOrder < (int)getBranch(x.orderBranch).branchHechserBranch) { throw new Exception("The Order's Hechser isn't high enough for the Branch"); } if (available) // add to the list. { orderList.Add(x); } else { throw new Exception("orderID already exists for a different order."); } }