public async Task <bool> Post([FromBody] PedidoModel model) { try { AdicionarPedidoCommand adicionarPedidoCommand = new AdicionarPedidoCommand(); adicionarPedidoCommand.ClienteId = model.Cliente.Id; await _mediatorHandler.EnviarComando(adicionarPedidoCommand); foreach (var item in model.Itens) { AdicionarItemPedidoCommand adicionarItemPedidoCommand = new AdicionarItemPedidoCommand(item.Produto.Id, item.Quantidade, model.Cliente.Id); await _mediatorHandler.EnviarComando(adicionarItemPedidoCommand); } return(true); } catch (DominioException ex) { return(false); } catch (Exception ex) { return(false); } }
public Task Handle(AdicionarPedidoCommand message, IMessageHandlerContext context) { RequestTimeout <PedidoTimeout>(context, TimeSpan.FromMilliseconds(5000)); WriteToConsole(message, message.Id); return(context.Publish(new PedidoRecebidoEvent(message.Id))); }
public async Task <bool> Handle(AdicionarPedidoCommand request, CancellationToken cancellationToken) { Pedido pedido = new Pedido(0, request.ClienteId); _pedidoRepository.Adicionar(pedido); await _pedidoRepository.UnitOfWork.Commit(); _mongo.Pedidos.InsertOne(new DtoPedido(pedido.Id, pedido.ClienteId)); return(true); }
public async Task <IActionResult> Post(AdicionarPedidoCommand command) { var result = await _pedidoService.CreateAsync(command); if (result.Success) { return(Ok("Pedido cadastrado com sucesso!")); } else { return(BadRequest(result.Messages)); } }
public async Task <ActionResult> PostAsync([FromBody] PedidoViewModel pedido) { var command = new AdicionarPedidoCommand(peso: pedido.Peso, latitude: pedido.Latitude, longitude: pedido.Longitude); var enviado = await _bus.EnviarComando(command); if (!enviado) { return(BadRequest()); } await _bus.PublicarEvento(new SolicitarEntregaEvent(command.Id)); return(CreatedAtAction("GetPedido", new { Sucess = true, command.Id })); }
public async void Handle(AdicionarPedidoCommand command) { var model = new PedidoEntity() { _id = new ObjectId(), Descricao = command.Descricao, CNPJ = command.CNPJ, Empresa = command.Empresa, Status = command.Status, Valor = command.Valor }; await _repository.Insert(model); }
public async Task <Pedido> ConverterAdicionar(AdicionarPedidoCommand command) { var produto = await _produtoRepository.GetByIdAsync(command.ProdutoId); var valorTotal = produto.Preco * command.Quantidade; return(new Pedido() { ClienteId = command.ClienteId, ProdutoId = command.ProdutoId, Quantidade = command.Quantidade, Data = DateTime.Now, ValorTotal = valorTotal }); }
public async Task <ResponseToUser> CreateAsync(AdicionarPedidoCommand command) { var result = _adicionarValidator.Validate(command); if (!result.IsValid) { return(ErrorResult(result.Errors.Select(q => q.ErrorMessage))); } var entidade = await _pedidoMapper.ConverterAdicionar(command); var entidadePersistida = await _pedidoRepository.CreateAsyncWithReturn(entidade); _publisher.Publisher(_pedidoMapper.ConverterPedidoCriadoEvent(entidadePersistida)); return(SuccessResult()); }
private static async Task ConfigureAndSend() { EscapeSequencer.Install(); EscapeSequencer.Bold = true; var defaultFactory = LogManager.Use <DefaultFactory>(); defaultFactory.Level(LogLevel.Warn); while (true) { var endpointConfiguration = new EndpointConfiguration("ExemploSaga.Pedidos"); endpointConfiguration.SendFailedMessagesTo("ExemploSaga.Pedidos.Errors"); /* Para testes, é possível usar persistencia em memória */ //endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.Subscriptions>(); //endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.Timeouts>(); //endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.Outbox>(); //endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.GatewayDeduplication>(); //endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.Sagas>(); endpointConfiguration.UsePersistence <NHibernatePersistence>(); endpointConfiguration.UseSerialization <JsonSerializer>(); endpointConfiguration.EnableInstallers(); endpointConfiguration.SagaPlugin("OpenPlatform.ServiceControl"); var transport = endpointConfiguration.UseTransport <RabbitMQTransport>(); transport.ConnectionString("host=localhost"); var endpoint = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false); var adicionarPedido = new AdicionarPedidoCommand(Guid.NewGuid(), "Heber"); Console.WriteLine($"ENTER para enviar mensagem para pedido {adicionarPedido.Id} - {adicionarPedido.Cliente}"); Console.ReadLine(); await endpoint.SendLocal(adicionarPedido); Console.WriteLine("Aguardando os handlers... ENTER para finalizar"); await Task.Delay(300).ConfigureAwait(false); } }
public async Task <IActionResult> AdicionarPedido(AdicionarPedidoCommand pedido) { pedido.ClienteId = new Guid("3fa85f64-5717-4562-b3fc-2c963f66afa6"); return(CustomResponse(await _mediator.EnviarComando(pedido))); }
public async Task <IActionResult> AdicionarPedido(AdicionarPedidoCommand pedido) { pedido.ClienteId = _user.ObterUserId(); return(CustomResponse(await _mediator.EnviarComando(pedido))); }
public void AdicionarPedido(string descricao, string empresa, string cnpj, decimal valor, PedidoStatus status) { var command = new AdicionarPedidoCommand(descricao, cnpj, empresa, valor, status); _handler.Handle(command); }
public async Task <AdicionarPedidoResponse> AdicionarPedido([FromRoute] Guid comandaId, [FromBody] AdicionarPedidoCommand command) { command.ComandaId = comandaId; var response = await _adicionarPedidoCommandHandler.Handler(command); _uow.Commit(); return(response); }