Example #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");
        }
Example #2
0
        public ActionResult TransferFunds()
        {
            //Get logged in user
            var studentProfile = db.UserProfiles.Local.SingleOrDefault(u => u.UserName == User.Identity.Name)
                ?? db.UserProfiles.SingleOrDefault(u => u.UserName == User.Identity.Name);
            //Get student account associated with logged in user
            var student = db.Students.Find(studentProfile.UserId);
            //Get accounts associated with student account
            var accounts = db.Accounts.Where(x => x.StudentID == student.UserId);

            var selectionList = new SelectList(accounts, "AccountID", "AccountName");

            var vm = new TransferFundsViewModel { ListOfSourceAccounts = selectionList, ListOfDestinationAccounts = selectionList };

            return View(vm);
        }