public ActionResult CreateAccount(BankAccountViewModel bankAccountViewModel)
        {
            if (ModelState.IsValid)
            {
                // Maybe use mapper here like this
                // Product product = Mapper.Map<ProductViewModel, Product>(productViewModel);

                BankAccount bankAccount = new BankAccount
                {
                    Name = bankAccountViewModel.Name,
                    Balance = bankAccountViewModel.Balance,
                    Funds = new List<Fund>()
                };

                // Note that EF automatically updates the object with the new ID after db insert.
                repo.InsertBankAccount(bankAccount);

                Fund whatsleft = new Fund
                {
                    Name = "What's Left",
                    Balance = bankAccountViewModel.Balance,
                    BankAccountId = bankAccount.BankAccountId
                };

                bankAccount.Funds.Add(whatsleft);
                repo.UpdateBankAccount(bankAccount);

                return RedirectToAction("Index");
            }
            else
            {
                return View(bankAccountViewModel);
            }
        }
        public ViewResult CreateAccount()
        {
            BankAccountViewModel model = new BankAccountViewModel()
            {
                Name = String.Empty,
                Balance = 0,
            };

            return View(model);
        }
        public ActionResult Transfer(BankAccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Maybe use mapper here like this
                // Product product = Mapper.Map<ProductViewModel, Product>(productViewModel);

                BankAccount bankAccount = repo.GetBankAccountById(model.Id);

                Fund fromFund = bankAccount.Funds.Where(f => f.FundId == model.FromFundId).FirstOrDefault();
                Fund toFund = bankAccount.Funds.Where(f => f.FundId == model.ToFundId).FirstOrDefault();

                if (fromFund.Balance >= model.Amount)
                {
                    fromFund.Balance -= model.Amount;
                    toFund.Balance += model.Amount;
                    repo.UpdateBankAccount(bankAccount);
                }

                return RedirectToAction("Edit", new { accountId = model.Id });
            }
            else
            {
                return View(model);
            }
        }
        // GET: WhatsLeft
        public ActionResult Index()
        {
            BankAccountsViewModel bankAccountsViewModel = new BankAccountsViewModel();

            //model.BankAccounts = repo.GetBankAccounts();
            var accounts = repo.GetBankAccounts();
            foreach (var account in accounts)
            {
                BankAccountViewModel model = new BankAccountViewModel
                {
                    Id = account.BankAccountId,
                    Name = account.Name,
                    Balance = account.Balance,
                    Funds = account.Funds
                };

                bankAccountsViewModel.BankAccounts.Add(model);
            }

            return View(bankAccountsViewModel);
        }
        public ActionResult Edit(int accountId)
        {
            BankAccount bankAccount = repo.GetBankAccountById(accountId);

            BankAccountViewModel model = new BankAccountViewModel
            {
                Id = bankAccount.BankAccountId,
                Name = bankAccount.Name,
                Balance = bankAccount.Balance,
                Funds = bankAccount.Funds
            };

            return View(model);
        }
示例#6
0
        public ActionResult Transfer(BankAccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                BankAccount bankAccount = bankAccountRepository.GetBankAccountById(model.BankAccountId);

                Fund fromFund = bankAccount.Funds.Where(f => f.FundId == model.FromFundId).FirstOrDefault();
                Fund toFund = bankAccount.Funds.Where(f => f.FundId == model.ToFundId).FirstOrDefault();

                if (fromFund.Balance >= model.Amount)
                {
                    fromFund.Balance -= model.Amount;
                    toFund.Balance += model.Amount;
                    bankAccountRepository.UpdateBankAccount(bankAccount);
                }

                return RedirectToAction("Details", new { accountId = model.BankAccountId });
            }
            else
            {
                return View(model);
            }
        }
示例#7
0
        public ActionResult Details(BankAccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                BankAccount bankAccount = new BankAccount
                {
                    BankAccountId = model.BankAccountId,
                    Balance = model.Balance,
                    Name = model.Name
                };
                bankAccountRepository.UpdateBankAccount(bankAccount);

                User user = new User
                {
                    UserId = model.UserId,
                    NextPayDay = model.NextPayDay
                };
                userRepository.UpdateUser(user);

                return RedirectToAction("Details", new { accountId = model.BankAccountId });
            }
            else
            {
                return View(model);
            }
        }
示例#8
0
        public ActionResult Details(int accountId)
        {
            BankAccount bankAccount = bankAccountRepository.GetBankAccountById(accountId);
            User user = userRepository.GetUsers().FirstOrDefault();

            BankAccountViewModel model = new BankAccountViewModel
            {
                BankAccountId = bankAccount.BankAccountId,
                UserId = user.UserId,
                Name = bankAccount.Name,
                Balance = bankAccount.Balance,
                Funds = bankAccount.Funds.ToList(),
                RegularPayments = bankAccount.RegularPayments.ToList(),
                WhatsLeft = bankAccount.Funds.Where(f => f.Name == "What's Left").FirstOrDefault().Balance,
                NextPayDay = user.NextPayDay
            };

            return View(model);
        }