/// <summary> /// Updates any order line items when a shipment is deleted to null /// </summary> /// <param name="shipment"> /// The shipment. /// </param> private void UpdateOrderLineItemShipmentKeys(IShipment shipment) { using (var repository = _repositoryFactory.CreateOrderRepository(_uowProvider.GetUnitOfWork())) { // there really should only ever be one of these var orderKeys = shipment.Items.Select(x => ((OrderLineItem)x).ContainerKey).Distinct(); foreach (var orderKey in orderKeys) { var order = repository.Get(orderKey); if (order != null) { var items = order.Items.Where(x => ((OrderLineItem)x).ShipmentKey == shipment.Key); foreach (var item in items) { ((OrderLineItem)item).ShipmentKey = null; } repository.AddOrUpdate(order); UpdatedOrder.RaiseEvent(new SaveEventArgs <IOrder>(order), this); } } } }