public IActionResult Withdraw(int id, BankAccountWithdrawViewModel bankAccountWithdrawViewModel) { if (ModelState.IsValid) { try { bool withdrawOperationResult = bankAccountRepository.WithdrawAmountIntoBankAccount(id, bankAccountWithdrawViewModel.AmountCurrent, bankAccountWithdrawViewModel.AmountToWithdraw, bankAccountWithdrawViewModel.ModifiedDate); if (withdrawOperationResult) { return(RedirectToAction("Index", "BankAccount", new { @id = id })); } } catch (InvalidBankAccountModifiedTimeStamp ex) { //ViewData["AmountToWithdrawError"] = "The Amount of the Bank account has been modified Please, refresh the page and try to deposit again!"; return(RedirectToAction("Withdraw", "BankAccount", new { @id = id })); } catch (InvalidBankAccountWithdrawException ex) { ModelState.AddModelError("AmountToWithdraw", "The Amount of money to withdraw exceeds the Amount of money in the Bank Account!"); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Something wen wrong! Please retry the operation!"); } } return(View(bankAccountWithdrawViewModel)); }
public IActionResult Withdraw(int id) { var bankAccountDTO = bankAccountRepository.GetBankAccountDTOById(id); BankAccountWithdrawViewModel bankAccounToWithdrawViewModel = BankAccountMapHelpers.MapBankAccountDTOToWithdrawViewModel(bankAccountDTO); return(View(bankAccounToWithdrawViewModel)); }
public static BankAccountWithdrawViewModel MapBankAccountDTOToWithdrawViewModel(BankAccountDTO bankAccountDTO) { BankAccountWithdrawViewModel bankAccounToWithdrawViewModel = new BankAccountWithdrawViewModel { ID = bankAccountDTO.ID, AmountCurrent = bankAccountDTO.Amount, Owner = bankAccountDTO.Owner.UserName, AmountToWithdraw = 0, ModifiedDate = bankAccountDTO.ModifiedDate }; return(bankAccounToWithdrawViewModel); }
public async Task <ActionResult <IValidationResult> > WithdrawAsync(BankAccountWithdrawViewModel bankAccount) { var result = await _bankAccountAppService.WithdrawAsync(bankAccount); return(CustomResponse(result)); }