コード例 #1
0
        public Task <bool> Handle(CancelOrderCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var order = _orderRepository.GetByNumber(message.Number);

            if (order == null)
            {
                NotifyValidationError(new DomainNotification(message.MessageType, $"pedido não encontrado"));
                return(Task.FromResult(false));
            }

            // after create then validate
            if (!order.IsValid())
            {
                NotifyValidationErrors(order);
                return(Task.FromResult(false));
            }

            // cancel order
            order.Cancel();

            // if has notifications then notify the application
            if (order.HasNotifications)
            {
                DisparchNotifications(order);
            }

            _orderRepository.Update(order);

            // if already it´s ok then disparch all events
            if (Commit())
            {
                DisparchEvents(order.DomainEvents);
            }
            else
            {
                NotifyValidationError(new DomainNotification(message.MessageType, "houve algum problema ao salvar status do pedido"));
                return(Task.FromResult(false));
            }

            return(Task.FromResult(true));
        }
コード例 #2
0
        public async Task Handle(CancelOrderCommand message)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return;
            }

            var order = new CancelOrderBitfinex
            {
                order_id = message.order_id
            };

            var result = await _bitfinexRepository.CancelOrder(order).ConfigureAwait(false);

            //if (result.Id > 0)
            //await Bus.RaiseEvent(new OrderCanceledEvent(long.Parse(result.Id.ToString())));
        }