private async Task <bool> ValidExistDigitalAccountNumberAndDigitAsync(int number, char digit) { DigitalAccountModel account = await _digitalAccountRepository.GetDigitalAccountByNumberAndDigitAsync(number, digit); bool exist = (account != null); return(exist); }
public async Task <DigitalAccountModel> UpdateAsync(DigitalAccountModel digitalAccount) { var digitalAccountUpdate = _appDbContext.DigitalAccounts.Update(digitalAccount); await _appDbContext.SaveChangesAsync(); return(digitalAccountUpdate.Entity); }
public async Task <DigitalAccountModel> InsertAsync(DigitalAccountModel digitalAccount) { var newDigitalAccount = await _appDbContext.DigitalAccounts.AddAsync(digitalAccount); await _appDbContext.SaveChangesAsync(); return(newDigitalAccount.Entity); }
public async Task <IActionResult> GetByIdAsync([Required] int id) { DigitalAccountModel digitalAccount = await _digitalAccountBusiness.GetByIdAsync(id); DigitalAccountResponseDTO response = _mapper.Map <DigitalAccountResponseDTO>(digitalAccount); return(Ok(response)); }
public async Task <IActionResult> CreateDigitalAccountAsync([FromBody] DigitalAccountRequestDTO digitalAccountRequest) { CustomerModel customer = _mapper.Map <CustomerModel>(digitalAccountRequest); DigitalAccountModel digitalAccount = await _digitalAccountBusiness.InsertAsync(customer); DigitalAccountResponseDTO response = _mapper.Map <DigitalAccountResponseDTO>(digitalAccount); return(Ok(response)); }
public async Task <IActionResult> GetDigitalAccountByCustomerAsync([Required] int customerId) { await _digitalAccountBusiness.Authorize(_accessToken); DigitalAccountModel digitalAccount = await _digitalAccountBusiness.GetDigitalAccountByCustomerIdAsync(customerId); DigitalAccountResponseDTO response = _mapper.Map <DigitalAccountResponseDTO>(digitalAccount); return(Ok(response)); }
private async Task <DigitalAccountTransactionModel> ProcessCustomerSenderDepositTransactionAsync(DigitalAccountTransactionModel transaction) { DigitalAccountModel digitalAccountSender = await _digitalAccounBusiness.GetByIdAsync(transaction.DigitalAccountSender.Id); DigitalAccountTransactionModel transactionSender = await ProcessCustomerSenderTransactionAsync(transaction, TransactionOperationEnum.Deposit, digitalAccountSender); transactionSender.DigitalAccount = digitalAccountSender; return(transactionSender); }
public async Task <DigitalAccountModel> GetByIdAsync(int digitalAccountId) { DigitalAccountModel digitalAccount = await _digitalAccountRepository.GetByIdAsync(digitalAccountId); if (digitalAccount == null) { throw new KeyNotFoundException("Conta não localizada"); } return(digitalAccount); }
private async Task EffectedTransation(DigitalAccountTransactionModel transaction) { DigitalAccountModel digitalAccount = await _digitalAccounBusiness.GetByIdAsync(transaction.DigitalAccountId); digitalAccount.Balance = transaction.Type == TransactionTypeEnum.Output ? (digitalAccount.Balance - transaction.Value) : (digitalAccount.Balance + transaction.Value); await _digitalAccounBusiness.UpdateAsync(digitalAccount); await UpdateStatusAsync(transaction, TransactionStatusEnum.Effected); }
private async Task <DigitalAccountTransactionModel> ProcessCustomerSenderTransferTransactionAsync(DigitalAccountTransactionModel transaction) { DigitalAccountModel digitalAccountSender = await _digitalAccounBusiness.GetByIdAsync(transaction.DigitalAccountSender.Id); await ValidRequestCustomerIdWithCustomerTokenAsync(digitalAccountSender.CustomerId); DigitalAccountTransactionModel transactionSender = await ProcessCustomerSenderTransactionAsync(transaction, TransactionOperationEnum.Transfer, digitalAccountSender); transactionSender.DigitalAccount = digitalAccountSender; return(transactionSender); }
public async Task <DigitalAccountModel> GetDigitalAccountByCustomerIdAsync(int customerId) { ValidRequestCustomerIdWithCustomerToken(customerId); DigitalAccountModel digitalAccount = await _digitalAccountRepository.GetDigitalAccountByCustomerIdAsync(customerId); if (digitalAccount == null) { throw new KeyNotFoundException("Conta não localizada"); } return(digitalAccount); }
public async Task <DigitalAccountTransactionModel> CreateTransactionTransferAsync(DigitalAccountTransactionModel transaction) { DigitalAccountTransactionModel transactionSender = await ProcessCustomerSenderTransferTransactionAsync(transaction); DigitalAccountModel digitalAccount = await _digitalAccounBusiness.GetByIdAsync(transaction.DigitalAccount.Id); transaction = await CreateTransactionAsync(transaction, TransactionTypeEnum.Input, TransactionOperationEnum.Transfer, transaction.DigitalAccount.Id, transaction.DigitalAccountSender.Id); transaction.DigitalAccount = digitalAccount; transaction.DigitalAccountSender = transactionSender.DigitalAccount; return(transaction); }
public async Task <DigitalAccountTransactionModel> CreateTransactionDepositAsync(DigitalAccountTransactionModel transaction) { if (transaction.DigitalAccountSender != null) { await ProcessCustomerSenderDepositTransactionAsync(transaction); } DigitalAccountModel digitalAccount = await _digitalAccounBusiness.GetByIdAsync(transaction.DigitalAccount.Id); transaction = await CreateTransactionAsync(transaction, TransactionTypeEnum.Input, TransactionOperationEnum.Deposit, digitalAccount.Id, transaction.DigitalAccountSender?.Id); transaction.DigitalAccount = digitalAccount; return(transaction); }
public async Task <DigitalAccountModel> InsertAsync(CustomerModel customer) { CustomerModel newCustomer = await _customerBusiness.InsertAsync(customer); DigitalAccountModel digitalAccount = new DigitalAccountModel(); digitalAccount = await GenerateNewDigitalAccountNumberAndDigit(digitalAccount); digitalAccount.CustomerId = newCustomer.Id; digitalAccount.Balance = 0m; digitalAccount.TransferLimitTransaction = 700m; digitalAccount.TransferLimitTransactionDay = 2000m; digitalAccount.Status = true; digitalAccount = await _digitalAccountRepository.InsertAsync(digitalAccount); return(digitalAccount); }
public void GetById_Success_ReturnDigitalAccount(int id) { DigitalAccountModel digitalAccount = new DigitalAccountModel() { Id = id, Balance = 100m, Number = 1234 + id, Digit = 'X', CreatedDate = DateTime.Now }; _digitalAccountRepositoryMock.Setup(repository => repository.GetByIdAsync(id)).ReturnsAsync(() => digitalAccount); DigitalAccountModel result = _digitalAccountBusiness.GetByIdAsync(id).Result; Assert.IsNotNull(result); Assert.AreEqual(id, result.Id); _digitalAccountRepositoryMock.Verify(x => x.GetByIdAsync(id), Times.Once); }
public async Task <DigitalAccountModel> GenerateNewDigitalAccountNumberAndDigit(DigitalAccountModel digitalAccount) { Random random = new Random(); digitalAccount.Number = random.Next(1000, Int32.MaxValue); digitalAccount.Digit = 'X'; bool exist = await ValidExistDigitalAccountNumberAndDigitAsync(digitalAccount.Number, digitalAccount.Digit); if (exist) { await GenerateNewDigitalAccountNumberAndDigit(digitalAccount); } return(digitalAccount); }
private async Task <DigitalAccountTransactionModel> ProcessCustomerSenderTransactionAsync(DigitalAccountTransactionModel transaction, TransactionOperationEnum operation, DigitalAccountModel digitalAccountSender) { await CheckExceededLimitTransctionAsync(transaction.Value, digitalAccountSender.TransferLimitTransaction); await ValidTransactionIfAccountSenderAndRecipientEqualsAsync(transaction.DigitalAccountSender.Id, transaction.DigitalAccount.Id); await CheckExceededDigitalAccountDailyLimitTransctionAsync(transaction.DigitalAccountSender.Id, transaction.Value, digitalAccountSender); DigitalAccountTransactionModel transactionSender = await CreateTransactionAsync(transaction, TransactionTypeEnum.Output, operation, transaction.DigitalAccountSender.Id, transaction.DigitalAccount.Id); return(transactionSender); }
private async Task CheckExceededDigitalAccountDailyLimitTransctionAsync(int digitalAccountId, decimal transactionValue, DigitalAccountModel digitalAccount) { List <DigitalAccountTransactionModel> transactions = await _digitalAccountTransactionRepository.GetTransactionsEffectedByDateAsync(digitalAccountId, DateTime.Now); decimal transactionsValue = transactions.Sum(t => t.Value); if ((digitalAccount.TransferLimitTransactionDay - transactionsValue) < transactionValue) { throw new ArgumentException("Nao foi possivel efetuar a transação, limite de transações diária da conta excedida"); } }
public async Task <DigitalAccountModel> GetByIdAsync(int digitalAccountId) { DigitalAccountModel digitalAccount = await _digitalAccountRepository.GetByIdAsync(digitalAccountId); return(digitalAccount); }
public async Task <DigitalAccountModel> UpdateAsync(DigitalAccountModel digitalAccount) { return(await _digitalAccountRepository.UpdateAsync(digitalAccount)); }