Exemple #1
0
        public ActionResult TransferFunds(TransferFundsViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    AccountManager manager = new AccountManager();
                    Account srcAccount = db.Accounts.Find(viewModel.SelectedSourceAccountId);
                    Account destAccount = db.Accounts.Find(viewModel.SelectedDestinationAccountId);

                    manager.TransferMoney(srcAccount, destAccount, viewModel.TransferAmount);
                    db.SaveChanges();
                }
                catch (DataException)
                {
                    ModelState.AddModelError("", "Something went wrong, transfer could not be completed.");
                }
            }
            return RedirectToAction("AccountSummary");
        }
Exemple #2
0
        public ActionResult PayExpense(PayExpenseViewModel viewModel)
        {
            var studentProfile = db.UserProfiles.Local.SingleOrDefault(u => u.UserName == User.Identity.Name) ?? db.UserProfiles.SingleOrDefault(u => u.UserName == User.Identity.Name);
            var student = db.Students.Find(studentProfile.UserId);
            var studentExpense = db.StudentExpenses.Find(viewModel.StudentExpenseId);
            var srcAccount = db.Accounts.Find(viewModel.SelectedAccountId);

            AccountManager manager = new AccountManager();

            if (ModelState.IsValid && srcAccount != null && studentExpense != null)
            {
                try
                {
                    manager.PayExpense(srcAccount, studentExpense, student, false); //bIsLate is currently defaulted to false need to implement system to check if the payment is late
                    db.SaveChanges();

                    db.Entry(student).State = EntityState.Modified;
                    db.SaveChanges();

                    db.Entry(studentExpense).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (DataException)
                {
                    ModelState.AddModelError("", "Something went wrong, the transaction could not be completed.");
                }
            }
            return RedirectToAction("ViewExpenses");
        }