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 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(); }
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 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 }); }
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); } }
public void InsertFund(Fund fund) { context.Funds.Add(fund); context.SaveChanges(); }
public IndexViewModel(Fund fund) { Id = fund.FundId; Name = fund.Name; Balance = fund.Balance; }
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); } }