public IActionResult Create([FromBody] CreateFinancialTransactionInput input) { ApiResponse response; var command = new CreateFinancialTransactionCommand(input.About, input.Amount, (byte)input.Type); var result = RabbitMq.Publish <CreateFinancialTransactionCommand, Result <CreateFinancialTransactionResult> >(command); if (!result.IsSucceeded) { response = new ApiResponse(result.Error.Code, result.Error.Description); return(BadRequest(response)); } response = new ApiResponse("OK", "Success"); return(Ok(response)); }
public async Task <Result <CreateFinancialTransactionResult> > Handle(CreateFinancialTransactionCommand request, CancellationToken cancellationToken) { try { var entity = await _repository.AddAsync( new FinancialTransaction(request.About, request.Amount, (FinancialTransactionTypes)request.Type)); return(Result <CreateFinancialTransactionResult> .Success(new CreateFinancialTransactionResult(entity.Id))); } catch (Exception e) { _logger.LogError(e, e.Message); return(Result <CreateFinancialTransactionResult> .Fail(Error.Default())); } }