public Core.Finance.Domain.Order PlaceOrder(Core.Finance.Domain.Order order) { var newOrder = _orderFactory.CreateDuplicateOrder(order); if (!_lineItems.Any()) { throw new InvalidOperationException("The order must contain at least one line item."); } if (order == null) { throw new InvalidOperationException("The order can not be null."); } using (var transaction = new TransactionScope()) { foreach (var lineItem in _lineItems) { OrderItem orderItem = _orderItemRepository.SaveOrderItem(lineItem.SecondValue.Id, lineItem.SecondValue.OrderItemType); lineItem.FirstValue.OrderItemId = orderItem.Id; lineItem.FirstValue.OrderId = order.Id; newOrder.OrderDetails.Add(lineItem.FirstValue); } // Get the new sourceCode applied... var orderDetailWithSourceCode = newOrder.OrderDetails.SingleOrDefault(od => od.SourceCodeOrderDetail != null); var sourceCodeOrderDetail = orderDetailWithSourceCode != null ? orderDetailWithSourceCode.SourceCodeOrderDetail : null; if (orderDetailWithSourceCode != null) { orderDetailWithSourceCode.SourceCodeOrderDetail = null; } newOrder = _orderSynchronizationService.SynchronizeOrder(order, newOrder, sourceCodeOrderDetail); newOrder = _orderRepository.SaveOrder(newOrder); transaction.Complete(); } _lineItems.Clear(); return(newOrder); }