Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
 public void UpdateFund(Fund newFund)
 {
     Fund fund = context.Funds.Where(f => f.FundId == newFund.FundId).FirstOrDefault();
     fund.Name = newFund.Name;
     fund.Balance = newFund.Balance;
     context.SaveChanges();
 }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        public EditViewModel(Fund fund)
        {
            var accounts = bankAccountRepository.GetBankAccounts();

            Id = fund.FundId;
            Name = fund.Name;
            Balance = fund.Balance;
            Accounts = accounts.Select(a => new SelectListItem
            {
                Value = a.BankAccountId.ToString(),
                Text = a.Name
            });
        }
Ejemplo n.º 5
0
        public ActionResult CreateFund(FundViewModel fundViewModel)
        {
            if (ModelState.IsValid)
            {
                // Maybe use mapper here like this
                // Product product = Mapper.Map<ProductViewModel, Product>(productViewModel);

                Fund fund = new Fund
                {
                    Name = fundViewModel.Name,
                    //Balance = fundViewModel.Balance,
                    BankAccountId = fundViewModel.BankAccountId
                };

                repo.InsertFund(fund);

                return RedirectToAction("Edit", new {accountId = fundViewModel.BankAccountId});
            }
            else
            {
                return View(fundViewModel);
            }
        }
Ejemplo n.º 6
0
 public void InsertFund(Fund fund)
 {
     context.Funds.Add(fund);
     context.SaveChanges();
 }
Ejemplo n.º 7
0
 public IndexViewModel(Fund fund)
 {
     Id = fund.FundId;
     Name = fund.Name;
     Balance = fund.Balance;
 }
Ejemplo n.º 8
0
        public ActionResult CreateFund(CreateFundViewModel model)
        {
            if (ModelState.IsValid)
            {
                Fund fund = new Fund
                {
                    Name = model.Name,
                    BankAccountId = model.BankAccountId
                };

                fundRepository.InsertFund(fund);

                return RedirectToAction("Details", new { accountId = model.BankAccountId });
            }
            else
            {
                return View(model);
            }
        }