public async Task <IActionResult> CreateProduct([FromBody] CreateProductRequest request) { var command = new CreateProductRequestCommand(request.Name, request.Price, request.ExpirationDate); var result = await _mediator.Send(command); return(CreatedAtAction("GetProduct", new { productId = result.Id, token = CancellationToken.None }, result)); }
public async Task Handle(CreateProductRequestCommand command) { var product = await _repository.AddAsync(new Product { Name = command.Name, Price = command.Price, ExpirationDate = command.ExpirationDate }); var responseCommand = new CreateProductResponseCommand(product, command.CommandId); var gatewayMessage = new GatewayMessage(responseCommand); await _producer.Produce(gatewayMessage); }