public DepositWithdrawViewModel Withdraw(DepositWithdrawViewModel model) { model.Message = null; model.Account = null; var account = _accounts.FirstOrDefault(c => c.Id == model.AccountNo); if (account != null) { if (model.Amount <= account.Amount && model.Amount > 0) { account.Amount -= model.Amount; model.Account = account; model.Message = "Withdraw completed"; } else if (model.Amount < 1) { model.Message = "Amount has to be digits with a value above 0"; } else { model.Message = "Not enough money on account"; } } else { model.Message = "Invalid account number"; } return(model); }
public IActionResult Withdraw(DepositWithdrawViewModel model) { var customers = _bankRepository.GetListOfCustomers(); var account = customers.SelectMany(i => i.Accounts.Where(x => x.Accountnumber.Equals(model.Account.Accountnumber))).SingleOrDefault(); if (account == null) { ModelState.AddModelError("", "The account number doesn't exist."); model.Account = null; return(View("DepositWithdraw", model)); } var result = _bankRepository.WithdrawAccount(model.Sum, account); if (result) { model.Account.Balance = account.Balance; return(View("DepositWithdraw", model)); } else { ModelState.AddModelError("", "There's not enough money on account to withdraw."); model.Account.Balance = account.Balance; return(View("DepositWithdraw", model)); } }
public DepositWithdrawViewModel Deposit(DepositWithdrawViewModel model) { model.Message = null; model.Account = null; var account = _accounts.FirstOrDefault(c => c.Id == model.AccountNo); if (account != null) { if (model.Amount > 0) { account.Amount += model.Amount; model.Account = account; model.Message = "Deposit completed"; } else { model.Message = "Amount has to be digits with a value above 0"; } } else { model.Message = "Invalid account number"; } return(model); }
public IActionResult DepositWithdraw(DepositWithdrawViewModel model, int choice) { if (choice == 1) { return(View(_bankrepo.Deposit(model))); } else { return(View(_bankrepo.Withdraw(model))); } }
public ActionResult Deposit(DepositWithdrawViewModel depositData) { if (!ModelState.IsValid) { return(this.View()); } string userEmail = User.Identity.Name; _bankManageService.Deposit(userEmail, depositData.AccountNumber, depositData.OperationSum); return(this.RedirectToAction("ShowAccounts")); }
public ActionResult Withdraw(DepositWithdrawViewModel model) { var bankAccount = this.service.GetAccountDTO(model.Id); if (bankAccount is null) { throw new ArgumentNullException(nameof(bankAccount)); } this.service.WithdrawMoney(bankAccount, model.Amount); return(RedirectToAction("List")); }
public IActionResult DepositWithDraw() { var model = new DepositWithdrawViewModel(); return(View(model)); }