// *******************************************************************************************************************************
        #region -  ApproveOrder  -

        public async Task <string> ApproveOrderAsync(ApproveOrderCommand cmd)
        {
            var tran    = new ApproveOrderTransaction(cmd);
            var ctl     = ControllerFactory.CreateForTcc(tran);
            var msgCode = await ctl.RunAsync().ConfigureAwait(false);

            if (msgCode.IsSuccess())
            {
                // 抛出Order更改事件
                _ = MessageDispatcher.PublishAsync(new OrderApprovedEvent(cmd.OrderNo, tran.Result));
            }

            return(msgCode);
        }
Exemple #2
0
        public async Task <Unit> Handle(ApproveOrderCommand request, CancellationToken cancellationToken)
        {
            var order = await orderRepository.FirstOrDefaultAsync(e => e.Id == request.OrderId);

            if (order == null)
            {
                return(Unit.Value);
            }

            var user = await userRepository.GetAsync(request.UserId);

            order.Approve(user);
            await orderRepository.UpdateAsync(order);

            Commit();
            await bus.InvokeAsync(new ApproveOrderEvent(request.OrderId, request.UserId));

            return(Unit.Value);
        }
        private List<CommandRouteItem> GetApproveOrderCommandRoutes(ApproveOrderCommand approveOrderCommand)
        {
            List<CommandRouteItem> commandRouteItems = new List<CommandRouteItem>();
            string serializedCommand = JsonConvert.SerializeObject(approveOrderCommand);
            List<Guid> ids = GetDestinationIdsFromOrderId(approveOrderCommand.DocumentId);

            Guid[] _destinationIds = RemoveSourceCCAppId(ids.ToArray(), approveOrderCommand);

            foreach (Guid id in _destinationIds)
                commandRouteItems.Add(CreateRouteItem(approveOrderCommand, "ApproveOrder", id, serializedCommand));

            return commandRouteItems;
        }