public async Task <IActionResult> Withdraw(int id, [Bind("Balance", "Amount", "AccountType")] WithdrawlVM withdrawlVM) { Account account = await _repo.Get(id); if (ModelState.IsValid) { try { if (withdrawlVM.Amount > account.Balance) { await _repo.Overdraft(await UserManager.GetUserAsync(User), account, withdrawlVM.Amount); } else { await _repo.Withdraw(account, withdrawlVM.Amount); } } catch (DbUpdateConcurrencyException) { if (!AccountExists(id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(withdrawlVM)); }
public async Task <IActionResult> Withdraw(int?id) { if (id == null) { return(NotFound()); } var account = await _repo.Get(id); if (account == null) { return(NotFound()); } WithdrawlVM withdrawlVM = new WithdrawlVM { Amount = 0, Balance = account.Balance, AccountType = account.AccountType }; return(View(withdrawlVM)); }