Пример #1
0
        public ActionResult Deposit(int accountID, decimal?balance)
        {
            bankAccount bankAccount = db.Accounts.Find(accountID);

            if (bankAccount == null)
            {
                return(HttpNotFound());
            }
            else if (!balance.HasValue)
            {
                return(View(bankAccount));
            }

            else
            {
                bankAccount.deposit((decimal)balance);
            }

            if (ModelState.IsValid)
            {
                TransHist transaction = new TransHist()
                {
                    date       = DateTime.Now,
                    customerID = bankAccount.customerID,
                    type       = $"Deposit - {bankAccount.accountID}",
                    amount     = (decimal)balance,
                    employee   = User.Identity.GetUserName()
                };
                db.TransactionHistory.Add(transaction);
                db.Entry(bankAccount).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("userAccounts", new { id = bankAccount.customerID }));
            }
            return(View(bankAccount));
        }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            TransHist transHist = db.TransactionHistory.Find(id);

            db.TransactionHistory.Remove(transHist);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
 public ActionResult Edit([Bind(Include = "TransID,date,customerID,type,amount,employee")] TransHist transHist)
 {
     if (ModelState.IsValid)
     {
         db.Entry(transHist).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.customerID = new SelectList(db.Customers, "customerID", "fName", transHist.customerID);
     return(View(transHist));
 }
Пример #4
0
        public ActionResult Create([Bind(Include = "TransID,date,customerID,type,amount,employee")] TransHist transHist)
        {
            if (ModelState.IsValid)
            {
                db.TransactionHistory.Add(transHist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.customerID = new SelectList(db.Customers, "customerID", "fName", transHist.customerID);
            return(View(transHist));
        }
Пример #5
0
        public ActionResult Withdraw(int accountID, decimal?balance)
        {
            bankAccount bankAccount = db.Accounts.Find(accountID);

            if (bankAccount == null)
            {
                return(HttpNotFound());
            }
            if (!balance.HasValue)
            {
                return(View(bankAccount));
            }
            if (bankAccount.balance >= 0)
            {
                if (bankAccount.type)
                {
                    bankAccount.withdraw((decimal)balance);
                }
                else
                {
                    if (balance > bankAccount.balance)
                    {
                        TempData["msg"] = "<script>alert('Checking accounts can't be overdrawn.');</script>";
                        return(View(bankAccount));
                    }
                    else
                    {
                        bankAccount.withdraw((decimal)balance);
                    }
                }
            }
            else
            {
                TempData["msg"] = "<script>alert('Current debts must be paid before withdrawing more money.');</script>";
                return(View(bankAccount));
            }
            if (ModelState.IsValid)
            {
                TransHist transaction = new TransHist()
                {
                    date       = DateTime.Now,
                    customerID = bankAccount.customerID,
                    type       = $"Withdraw - {bankAccount.accountID}",
                    amount     = (decimal)balance,
                    employee   = User.Identity.GetUserName()
                };
                db.TransactionHistory.Add(transaction);
                db.Entry(bankAccount).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("userAccounts", new { id = bankAccount.customerID }));
            }
            return(View(bankAccount));
        }
Пример #6
0
        // GET: TransHists/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TransHist transHist = db.TransactionHistory.Find(id);

            if (transHist == null)
            {
                return(HttpNotFound());
            }
            return(View(transHist));
        }
Пример #7
0
        // GET: TransHists/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TransHist transHist = db.TransactionHistory.Find(id);

            if (transHist == null)
            {
                return(HttpNotFound());
            }
            ViewBag.customerID = new SelectList(db.Customers, "customerID", "fName", transHist.customerID);
            return(View(transHist));
        }
Пример #8
0
        public ActionResult Create([Bind(Include = "accountID,balance,type,interest,customerID,locked")] bankAccount bankAccount)
        {
            if (ModelState.IsValid)
            {
                TransHist transaction = new TransHist()
                {
                    date       = DateTime.Now,
                    customerID = bankAccount.customerID,
                    type       = "Account Creation",
                    amount     = bankAccount.balance,
                    employee   = User.Identity.GetUserName()
                };
                db.TransactionHistory.Add(transaction);
                db.Accounts.Add(bankAccount);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //ViewBag.customerID = new SelectList(db.Customers, "customerID", "fName", bankAccount.customerID);
            return(RedirectToAction("userAccounts", new { id = bankAccount.customerID }));
        }
Пример #9
0
        public ActionResult Create([Bind(Include = "termID,amount,interest,duration,output,customerID,message")] TermDepo termDepo)
        {
            termDepo.amount += (termDepo.amount * termDepo.interest);
            if (ModelState.IsValid)
            {
                TransHist transaction = new TransHist()
                {
                    date       = DateTime.Now,
                    customerID = termDepo.customerID,
                    type       = $"Term Deposit - {termDepo.termID}",
                    amount     = termDepo.amount,
                    employee   = User.Identity.GetUserName()
                };
                db.TransactionHistory.Add(transaction);
                db.TermDeposit.Add(termDepo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(termDepo));
        }
Пример #10
0
        public ActionResult Close(int id)
        {
            bankAccount bankAccount = db.Accounts.Find(id);

            bankAccount.close();
            if (ModelState.IsValid)
            {
                TransHist transaction = new TransHist()
                {
                    date       = DateTime.Now,
                    customerID = bankAccount.customerID,
                    type       = $"Closure -{bankAccount.accountID}",
                    amount     = (decimal)0,
                    employee   = User.Identity.GetUserName()
                };
                db.TransactionHistory.Add(transaction);
                db.Entry(bankAccount).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("userAccounts", new { id = bankAccount.customerID }));
            }
            return(View(bankAccount));
        }
Пример #11
0
        public ActionResult Create([Bind(Include = "loanID,amount,interest,duration,customerID,locked")] Loan loan)
        {
            loan.amount += (loan.amount * loan.interest);
            if (ModelState.IsValid)
            {
                TransHist transaction = new TransHist()
                {
                    date       = DateTime.Now,
                    customerID = loan.customerID,
                    type       = $"Loan - {loan.loanID}",
                    amount     = loan.amount,
                    employee   = User.Identity.GetUserName()
                };
                db.TransactionHistory.Add(transaction);
                db.Loans.Add(loan);
                db.SaveChanges();
                return(RedirectToAction("userLoans", new { id = loan.customerID }));
            }

            ViewBag.customerID = new SelectList(db.Customers, "customerID", "fName", loan.customerID);
            return(View(loan));
        }
Пример #12
0
        public ActionResult Payment(int loanID, decimal?amount)
        {
            Loan loan = db.Loans.Find(loanID);

            if (loan == null)
            {
                return(HttpNotFound());
            }
            else if (!amount.HasValue)
            {
                return(View(loan));
            }
            else if (amount > loan.amount)
            {
                TempData["msg"] = "<script>alert('Can not overpay on loan.');</script>";
                return(View(loan));
            }
            else
            {
                loan.installment((decimal)amount);
            }
            if (ModelState.IsValid)
            {
                TransHist transaction = new TransHist()
                {
                    date       = DateTime.Now,
                    customerID = loan.customerID,
                    type       = $"Loan Payment - {loan.loanID}",
                    amount     = (decimal)amount,
                    employee   = User.Identity.GetUserName()
                };
                db.TransactionHistory.Add(transaction);
                db.Entry(loan).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("userLoans", new { id = loan.customerID }));
            }
            return(View(loan));
        }