public void AddItem(int itemId, int quantity) { if(orderId != 0 && quantity > 0) { int index = orderlines.FindIndex(x => x.ItemId == itemId); if (index != -1) { orderlines[index].Quantity += quantity; } else { OrderLine line = new OrderLine(orderId, itemId, quantity); line.Sync(); orderlines.Add(line); } } }
public void AddItem(OrderLine line) { if(line.OrderId == orderId) { if (orderlines.Any(x => x.ItemId != line.ItemId)) { // Add new item to order orderlines.Add(line); } else { // Update quantity int index = orderlines.FindIndex(x => x.ItemId == line.ItemId); if (index != -1) { orderlines[index].Quantity = line.Quantity; } } } }