Example #1
0
        public MergeOrderResponse MergeOrder(MergeOrderRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.SourceOrderRefs, "SourceOrderRefs");
            Platform.CheckTrue(request.SourceOrderRefs.Count > 0, "SourceOrderRefs.Count > 0");
            Platform.CheckMemberIsSet(request.DestinationOrderRef, "DestinationOrderRef");

            var response = new MergeOrderResponse();

            DryRunHelper(request.DryRun,
                         delegate
            {
                var destinationOrder = this.PersistenceContext.Load <Order>(request.DestinationOrderRef);
                var sourceOrders     = CollectionUtils.Map(request.SourceOrderRefs, (EntityRef r) => PersistenceContext.Load <Order>(r));
                var mergeInfo        = new OrderMergeInfo(this.CurrentUserStaff, Platform.Time, destinationOrder);

                MergeOrderHelper(destinationOrder, sourceOrders, mergeInfo, request.ValidationOnly);

                if (request.DryRun)
                {
                    var orderAssembler = new OrderAssembler();
                    var orderDetail    = orderAssembler.CreateOrderDetail(destinationOrder,
                                                                          OrderAssembler.CreateOrderDetailOptions.GetVerboseOptions(), PersistenceContext);
                    response.DryRunMergedOrder = orderDetail;
                }
            });
            return(response);
        }
        private void MergeOrderDryRun(out OrderDetail mergedOrder, out string failureReason)
        {
            if (_selectedOrder == null)
            {
                failureReason = null;
                mergedOrder   = null;
                return;
            }

            var destinationOrderRef = _selectedOrder.OrderRef;
            var sourceOrderRefs     = new List <EntityRef>(_orderRefs);

            sourceOrderRefs.Remove(_selectedOrder.OrderRef);

            try
            {
                MergeOrderResponse response = null;
                Platform.GetService(
                    delegate(IOrderEntryService service)
                {
                    var request = new MergeOrderRequest(sourceOrderRefs, destinationOrderRef)
                    {
                        DryRun = true
                    };
                    response = service.MergeOrder(request);
                });

                mergedOrder   = response.DryRunMergedOrder;
                failureReason = null;
            }
            catch (RequestValidationException e)
            {
                failureReason = e.Message;
                mergedOrder   = null;
            }
        }