//[ValidateAntiForgeryToken] public async Task <IActionResult> CreateTransfer(BankTransactionViewModel transfer) { // Eur, 7856a896-25be-494c-829b-d97fc2f8c8ad, [email protected] if (ModelState.IsValid) { transfer.SourceClientId = GetCurrentClientId(); var result = await _bankTransferService.Send(transfer); if (result) { return(RedirectToAction(nameof(TransferSent))); } else { ModelState.AddModelError("", "Oh no, something went boo-boo!"); } } var activeAccounts = (await _bankAccountService.GetAllAccountsForClient(transfer.SourceClientId)) .Where(x => x.Enabled && x.Approved.HasValue && x.Approved.Value).ToList(); PopulateSelectListWithAccounts(activeAccounts, transfer.ActiveAccounts); return(View(transfer)); }
public async Task <IActionResult> CreateTransfer() { var clientId = GetCurrentClientId(); var activeAccounts = (await _bankAccountService.GetAllAccountsForClient(clientId)) .Where(x => x.Enabled && x.Approved.HasValue && x.Approved.Value).ToList(); var vm = new BankTransactionViewModel { ActiveAccounts = new List <SelectListItem>(), SourceClientId = 1 }; PopulateSelectListWithAccounts(activeAccounts, vm.ActiveAccounts); return(View(vm)); }
public async Task <bool> Send(BankTransactionViewModel transactionViewModel) { if (transactionViewModel.Amount <= 0m) { return(false); } var sourceAccount = await _bankAccountService.GetByAccountNumber(transactionViewModel.SourceAccountNumber); if (sourceAccount == null) { return(false); } var destinationAccount = await _bankAccountService.GetByAccountNumber(transactionViewModel.DestinationAccountNumber); if (destinationAccount == null) { return(false); } if (sourceAccount.ClientId != transactionViewModel.SourceClientId || sourceAccount.Currency != transactionViewModel.Currency || destinationAccount.Currency != transactionViewModel.Currency || sourceAccount.Balance < transactionViewModel.Amount) { return(false); } var transaction = _mapper.Map <BankTransaction>(transactionViewModel); transaction.Timestamp = DateTime.UtcNow; transaction.Approved = true; transaction.DestinationAccountId = destinationAccount.ID; transaction.DestinationClientId = destinationAccount.Client.ID; transaction.SourceAccountId = sourceAccount.ID; await _bankTransactionRepository.AddAsync(transaction); await _bankAccountService.UpdateBalance(sourceAccount.ID, -(transactionViewModel.Amount)); await _bankAccountService.UpdateBalance(destinationAccount.ID, transactionViewModel.Amount); return(true); }
public void ShouldCreateABankTransactionWithViewModelData() { var bankTransactionViewModel = new BankTransactionViewModel { Description = "DOC 399.1934NIBO SOF CUR", Date = "04/02/2014 10:00:00", Type = "CRÉDITO", Value = "R$ 14.000,00" }; var listOfViewModels = new List <BankTransactionViewModel> { bankTransactionViewModel }; _bankTransactionManager.AddBankTransactions(listOfViewModels); _factoryMock.Verify( factory => factory.CreateBankTransactionWith(bankTransactionViewModel.Description, bankTransactionViewModel.Date, bankTransactionViewModel.Value, bankTransactionViewModel.Type), Times.Exactly(listOfViewModels.Count)); }
public void ShouldSaveBankTransaction() { var bankTransactionViewModel = new BankTransactionViewModel { Description = "DOC 399.1934NIBO SOF CUR", Date = "04/02/2014 10:00:00", Type = "CRÉDITO", Value = "R$ 14.000,00" }; var listOfViewModels = new List <BankTransactionViewModel> { bankTransactionViewModel }; var bankTransaction = SetupForValidTransactions(listOfViewModels); var bankTransactionList = new List <BankTransaction> { bankTransaction }; _bankTransactionManager.AddBankTransactions(listOfViewModels); _repositoryMock.Verify(repository => repository.SaveBankTransactions(bankTransactionList), Times.Once); }
private BankTransactionViewModel SetupForDuplicateTransactions(out List <BankTransactionViewModel> listOfDuplicateViewModels) { var bankTransactionViewModel = new BankTransactionViewModel { Description = "DOC 399.1934NIBO SOF CUR", Date = "04/02/2014 10:00:00", Type = "CRÉDITO", Value = "R$ 14.000,00" }; listOfDuplicateViewModels = new List <BankTransactionViewModel> { bankTransactionViewModel, bankTransactionViewModel }; const string expectedDescription = "DOC 399.1934NIBO SOF CUR"; const int expectedValue = 14000; var expectedDate = new DateTime(2014, 2, 4, 10, 0, 0); const TransactionType expectedType = TransactionType.Credit; var bankTransaction = new BankTransaction(expectedDescription, expectedDate, expectedValue, expectedType); _factoryMock.Setup(factory => factory.CreateBankTransactionWith(bankTransactionViewModel.Description, bankTransactionViewModel.Date, bankTransactionViewModel.Value, bankTransactionViewModel.Type)) .Returns(bankTransaction); return(bankTransactionViewModel); }