Beispiel #1
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");
        }
Beispiel #2
0
        public ActionResult PayExpense(int expenseId)
        {
            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 accounts = db.Accounts.Where(x => x.StudentID == student.UserId);
            var selectedExpense = db.StudentExpenses.Find(expenseId);
            var selectionList = new SelectList(accounts, "AccountID", "AccountName");

            var vm = new PayExpenseViewModel { ListOfAccounts = selectionList, ExpenseAmount = selectedExpense.CurrentAmountOwed, StudentExpenseId = selectedExpense.StudentExpenseID };

            return View(vm);
        }