public ActionResult Deposit(Transaction transaction)
 {
     if (ModelState.IsValid)
     {
         db.Transactions.Add(transaction);
         db.SaveChanges();
         return RedirectToAction("Index", "Home");
     }
     return View();
 }
Ejemplo n.º 2
0
        public ActionResult Deposit(Transaction transaction)
        {
            if (ModelState.IsValid)
            {
                db.Transactions.Add(transaction);
                db.SaveChanges();

                var service = new CheckingAccountService(db);
                service.UpdateBalance(transaction.CheckingAccountId);
                return RedirectToAction("Index", "Home");
            }
            return View();
        }
Ejemplo n.º 3
0
        public ActionResult Withdrawal(Transaction transaction)
        {
            var checkingAccount = db.CheckingAccounts.Find(transaction.CheckingAccountId);
            if (checkingAccount.Balance < transaction.Amount)
            {
                ModelState.AddModelError("Amount", "You have insufficient funds!");
            }

            if (ModelState.IsValid)
            {
                transaction.Amount = -transaction.Amount;
                db.Transactions.Add(transaction);
                db.SaveChanges();

                var service = new CheckingAccountService(db);
                service.UpdateBalance(transaction.CheckingAccountId);
                return RedirectToAction("Index", "Home");
            }
            return View();
        }
        public ActionResult Withdraw(Transaction transaction)
        {
            CheckingAccount checkingAccount = db.CheckingAccounts.Find(transaction.CheckingAccountId);
            if (checkingAccount.Balance < transaction.Amount)
            {
                // adicionando erro manuamente no model.
                // associando um erro há uma propriedade. @Html.ValidationMessageFor()
                //ModelState.AddModelError("Amount", "You have insufficient funds!");

                // mostra o erro na parte do @Html.ValidationSummary()
                ModelState.AddModelError("", "You have insufficient funds!");
            }

            // se o ModelState.AddModeError() for adicionado, ModelState.Isvalid será false
            if (ModelState.IsValid)
            {
                transaction.Amount = -transaction.Amount;
                db.Transactions.Add(transaction);
                db.SaveChanges();

                CheckingAccountService service = new CheckingAccountService(db);
                service.UpdateBalance(transaction.CheckingAccountId);
                return RedirectToAction("Index", "Home");
            }
            return View();
        }