Exemplo n.º 1
0
        public OrderSavedResult SaveOrder(OrderModel order)
        {
            using (var context = _contextFactory.Create())
            {
                var latestOrderShipment = context.Shipments.GetLatestByOrderNumber(order.OrderNumber);

                if (latestOrderShipment != null && latestOrderShipment.IsShipped)
                {
                    throw new ArgumentException(string.Format("This order cannot be changed because it has been shipped!"));
                }

                var savedOrder = _entitySaver.Save(context, order, RevisionPolicy.OnlyNewRevision);

                if (latestOrderShipment != null)
                {
                    latestOrderShipment.OrderRevision = savedOrder.Id;
                    latestOrderShipment.Items = _shipmentOrderItemsUpdater.UpdateOrderItems(latestOrderShipment.Items, savedOrder.Items);

                    _entitySaver.Save(context, latestOrderShipment, RevisionPolicy.OnlyNewRevision);
                }

                context.SaveChanges();

                return new OrderSavedResult
                {
                    CustomerId = savedOrder.OrderInfo.CustomerId,
                    OrderNumber = savedOrder.OrderNumber,
                    RevisionId = savedOrder.Id
                };
            }
        }
Exemplo n.º 2
0
 public async Task<OrderSavedResult> SaveOrderAsync(OrderModel order)
 {
     return _saver.SaveOrder(order);
 }