public IActionResult Withdrawal(DepositWithdrawalViewModel values) { if (ModelState.IsValid) { var old = _context.Accounts.SingleOrDefault(a => a.AccountId == values.Account.AccountId); if (values.Transaction.Amount > old.Balance) { return(PartialView("_WithdrawalFailed")); } else { values.Transaction.AccountId = values.Account.AccountId; values.Transaction.Date = DateTime.Now; values.Transaction.Date.ToShortDateString(); values.Transaction.Type = "Debit"; values.Transaction.Operation = "Withdrawal in Cash"; values.Account.Frequency = old.Frequency; values.Account.Created = old.Created; values.Transaction.Balance = old.Balance + (-(values.Transaction.Amount)); values.Account.Balance = values.Transaction.Balance; _context.Entry(old).CurrentValues.SetValues(values.Account); _context.Transactions.Add(values.Transaction); _context.SaveChanges(); ModelState.Clear(); return(PartialView("_WithdrawalDone", values)); } } return(View()); }
public IActionResult Withdrawal(int id) { var model = new DepositWithdrawalViewModel(); model.Account = _context.Accounts.SingleOrDefault(a => a.AccountId == id); return(View(model)); }