/// <inheritdoc /> public async Task <ExchangeTransactionModel> Insert(ExchangeTransactionInput input, decimal exchange, decimal totalTransactions, decimal threshold) { try { var transactionModel = _mapper.Map <ExchangeTransactionModel>(input); transactionModel.ExchangedAmount = transactionModel.PesosAmount / exchange; transactionModel.CurrencyExchange = exchange; if (totalTransactions + transactionModel.ExchangedAmount > threshold) { throw new NotSupportedException("Amount is over the limit"); } var transactionEntity = _mapper.Map <TransactionDbEntity>(transactionModel); transactionEntity.CreatedAt = DateTime.Now; transactionEntity.UpdatedAt = DateTime.Now; var id = await _transactionRepository.Insert(transactionEntity); if (id > 0) { return(transactionModel); } else { throw new NotSupportedException("There was an error storing data"); } } catch (NotSupportedException ex) { throw ex; } catch (Exception ex) { _logger.LogError(ex.Message); throw ex; } }
/// <summary> /// Constructor /// </summary> /// <param name="request"></param> public CreateTransactionAsyncCmd(ExchangeTransactionInput request) => TransactionInput = request ?? throw new ArgumentNullException(nameof(request));
public async Task <ApiResponse <ExchangeTransactionModel> > ExchangeTransaction([FromBody] ExchangeTransactionInput transaction) { return(await ExecuteAsync(async() => { return await _mediator.Send(new CreateTransactionAsyncCmd(transaction)); })); }