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);
            }
        }
Esempio n. 2
0
        public ActionResult Create(CreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                BankAccount bankAccount = new BankAccount
                {
                    Name = model.Name,
                    Balance = model.Balance
                };

                bankAccountRepository.InsertBankAccount(bankAccount);

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

                fundRepository.InsertFund(fund);

                return RedirectToAction("Index");
            }
            else
            {
                return View(model);
            }
        }
 public void UpdateBankAccount(BankAccount bankAccount)
 {
     BankAccount account = context.Accounts.Where(b => b.BankAccountId == bankAccount.BankAccountId).FirstOrDefault();
     account.Name = bankAccount.Name;
     account.Balance = bankAccount.Balance;
     account.Funds = bankAccount.Funds;
     context.SaveChanges();
 }
Esempio n. 4
0
 public EditViewModel(BankAccount account)
 {
     Id = account.BankAccountId;
     Name = account.Name;
     Balance = account.Balance;
 }
 public void InsertBankAccount(BankAccount bankAccount)
 {
     context.Accounts.Add(bankAccount);
     context.SaveChanges();
 }
Esempio n. 6
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);
            }
        }