public ShipOrderTransaction(ShipOrderCommand cmd) : base(cmd.CorrelationId , new ChangeOrderStatusActivity() , new ShipConfirmActivity() ) { SetState(CONSTANTS.TRANSACTIONS.EntryCommand, cmd); }
public async Task <IActionResult> ShipOrder(int id) { var shipOrderCommand = new ShipOrderCommand(id); await _mediator.Send(shipOrderCommand); return(NoContent()); }
public async Task <IActionResult> ShipOrderAsync([FromBody] ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) { bool commandResult = false; if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) { var requestShipOrder = new IdentifiedCommand <ShipOrderCommand, bool>(command, guid); _logger.LogInformation( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", requestShipOrder.GetGenericTypeName(), nameof(requestShipOrder.Command.OrderNumber), requestShipOrder.Command.OrderNumber, requestShipOrder); commandResult = await _mediator.Send(requestShipOrder); } if (!commandResult) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> ShipOrderAsync(int orderId) { var command = new ShipOrderCommand(orderId); _logger.LogInformation(" [x] OrderController.ShipOrderAsync(): Sending ShipOrderCommand for order with id {0}", orderId); await _mediator.Send(command); return(Ok()); }
public async Task ShipOrder(ShipOrderRequest shipOrderRequest) { var shipOrderCommand = new ShipOrderCommand() { OrderCode = shipOrderRequest.OrderCode, }; await _busControl.Send(shipOrderCommand, "ship-order-command-queue"); }
public async Task <IActionResult> ShipOrderAsync([FromBody] ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) { bool commandResult = await _commandSender.SendCommand(command); if (!commandResult) { return(BadRequest()); } return(Ok()); }
public void ShouldReturFalseWhenOrderShipIsInvalid() { Guid OrderId = Guid.Empty; var Data = DateTime.Now.AddHours(-1); var ship = new ShipOrderCommand(Data, OrderId); var orderHandler = new OrderHandlers(new FakeOrderRepository()); var result = orderHandler.Handle(ship); Assert.IsTrue(orderHandler.Invalid); }
public void ShouldReturtrueWhenOrderShipIsValid() { var OrderId = Guid.NewGuid(); var Data = DateTime.Now.AddHours(1); var ship = new ShipOrderCommand(Data, OrderId); var orderHandler = new OrderHandlers(new FakeOrderRepository()); var result = orderHandler.Handle(ship); Assert.IsTrue(orderHandler.IsValid); }
public async Task <IActionResult> ShipOrder([FromBody] ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) { bool commandResult = false; if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) { var requestShipOrder = new IdentifiedCommand <ShipOrderCommand, bool>(command, guid); commandResult = await _mediator.Send(requestShipOrder); } return(commandResult ? (IActionResult)Ok() : (IActionResult)BadRequest()); }
public async Task <ActionResult <Result> > ShipOrderAsync([FromBody] ShipOrderDTO shipOrderDTO) { var command = new ShipOrderCommand(shipOrderDTO.OrderNumber); var commandResult = await _mediator.Send(command); if (commandResult.IsFailure) { return(BadRequest()); } return(Ok()); }
// ******************************************************************************************************************************* #region - ShipOrder - public async Task <string> ShipOrderAsync(ShipOrderCommand cmd) { var tran = new ShipOrderTransaction(cmd); var ctl = ControllerFactory.CreateForTcc(tran); var msgCode = await ctl.RunAsync().ConfigureAwait(false); if (msgCode.IsSuccess()) { // 抛出Order更改事件 _ = MessageDispatcher.PublishAsync(new OrderShippedEvent(cmd.OrderNo, tran.Result)); } return(msgCode); }
public ICommandResult Handle(ShipOrderCommand Command) { //cria a entidade var delivery = new Delivery(Command.EstimatedDelivery, Command.OrderId); AddNotifications(delivery.Notifications); if (Invalid) { return(new Result(false, "Os seguintes campos estão com dados incorretos", delivery.Notifications)); } _reposotory.AddShip(delivery); return(new Result(true, "Entrega adicionado ao pedido", new{ NumberShip = delivery.Id })); }
public async Task <IActionResult> ShipOrderAsync([FromBody] ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) { bool commandResult = false; if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) { commandResult = await _mediator.Send(command); } if (!commandResult) { return(BadRequest()); } return(Ok()); }
public Task <bool> Handle(ShipOrderCommand 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)); } // ship order order.Ship(); // 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); return(Task.FromResult(true)); } NotifyValidationError(new DomainNotification(message.MessageType, "houve algum problema ao salvar status do pedido")); return(Task.FromResult(false)); }
public async Task LifeCycle() { var createCmd = new CreateOrderCommand { Order = _order }; createCmd.SetContext(_identity); var mr = await OrderService.CreateOrderAsync(createCmd).ConfigureAwait(false); Assert.IsTrue(mr.IsSuccess, mr.MsgCode); _order.OrderNo = mr.Result; var approveCmd = new ApproveOrderCommand { OrderNo = _order.OrderNo }; approveCmd.SetContext(_identity); var msgCode = await OrderService.ApproveOrderAsync(approveCmd).ConfigureAwait(false); Assert.IsTrue(msgCode.IsSuccess(), msgCode); var shipCmd = new ShipOrderCommand { OrderNo = _order.OrderNo }; shipCmd.SetContext(_identity); msgCode = await OrderService.ShipOrderAsync(shipCmd).ConfigureAwait(false); Assert.IsTrue(msgCode.IsSuccess(), msgCode); var deleteCmd = new DeleteOrderCommand { OrderNo = _order.OrderNo }; deleteCmd.SetContext(_identity); msgCode = await OrderService.DeleteOrderAsync(deleteCmd).ConfigureAwait(false); Assert.IsTrue(msgCode.IsSuccess(), msgCode); }
public IActionResult ShipOrder([FromBody] ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId) { return(NotFound()); }
public async Task <Unit> Handle(ShipOrderCommand request, CancellationToken cancellationToken) => await UpdateAsync(new OrderId(request.OrderNumber), async state => Order.ShipOrder(state) ) .PipeToAsync(Unit.Value);
public Task <string> ShipOrderAsync(ShipOrderCommand cmd) => base.RequestAsync(cmd);
public ICommandResult PostDelivery([FromBody] ShipOrderCommand delivery) { return(_handle.Handle(delivery)); }
public async Task <IActionResult> ShipOrder(ShipOrderCommand command) { await Mediator.Handle(command); return(RedirectToAction(nameof(OrderList))); }