Esempio n. 1
0
        public UnmergeOrderResponse UnmergeOrder(UnmergeOrderRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.OrderRef, "OrderRef");

            // reason is not required for dry run, but otherwise it is
            if (!request.DryRun && request.UnmergeReason == null)
            {
                throw new ArgumentNullException("UnmergeReason");
            }

            DryRunHelper(request.DryRun,
                         delegate
            {
                var destinationOrder = this.PersistenceContext.Load <Order>(request.OrderRef);
                var sourceOrders     = destinationOrder.MergeSourceOrders;
                if (sourceOrders.Count == 0)
                {
                    throw new RequestValidationException("This order does not have any orders to un-merge.");
                }

                // load the reason; if reason is null (eg dry run), just get the first available reason
                var reason = request.UnmergeReason == null ?
                             CollectionUtils.FirstElement(PersistenceContext.GetBroker <IEnumBroker>().Load <OrderCancelReasonEnum>(false))
                                                : EnumUtils.GetEnumValue <OrderCancelReasonEnum>(request.UnmergeReason, PersistenceContext);

                var cancelInfo = new OrderCancelInfo(reason, this.CurrentUserStaff, "Un-merged");
                var accBroker  = PersistenceContext.GetBroker <IAccessionNumberBroker>();

                // do unmerge
                UnmergeHelper(sourceOrders, cancelInfo, accBroker);
            });

            return(new UnmergeOrderResponse());
        }
        protected bool ExecuteCore(WorklistItemSummaryBase item)
        {
            EnumValueInfo reason;
            var           reasonCode = OrderMergeSettings.Default.UnmergeDefaultReasonCode;

            if (string.IsNullOrEmpty(reasonCode))
            {
                var unmergeComponent = new UnmergeOrderComponent();
                var exitCode         = ApplicationComponent.LaunchAsDialog(
                    this.Context.DesktopWindow,
                    unmergeComponent,
                    string.Format("Undo merge order {0}", AccessionFormat.Format(item.AccessionNumber)));

                if (exitCode != ApplicationComponentExitCode.Accepted)
                {
                    return(false);
                }

                reason = unmergeComponent.SelectedReason;
            }
            else
            {
                // confirm
                var message = string.Format("Un-merge all orders merged into {0}?", item.AccessionNumber);
                if (DialogBoxAction.No == this.Context.DesktopWindow.ShowMessageBox(message, MessageBoxActions.YesNo))
                {
                    return(false);
                }
                reason = new EnumValueInfo(reasonCode, null, null);
            }

            Platform.GetService(
                delegate(IOrderEntryService service)
            {
                var request = new UnmergeOrderRequest(item.OrderRef)
                {
                    UnmergeReason = reason
                };
                service.UnmergeOrder(request);
            });

            InvalidateFolders();
            return(true);
        }