public ActionResult New(int id) { var customer = _customerContext.Get(id); var branches = _userContext.GetBranches().ToList(); var viewModel = new NewCustomerAccountViewModel { Customer = customer, Branches = branches }; return(View("CustomerAccountForm", viewModel)); }
public ActionResult Edit(int id) { var customerId = _context.GetCustomerId(id); var branches = _userContext.GetBranches().ToList(); var customerAccount = _context.Get(id); var customer = _customerContext.GetByCustomerId(customerId); var viewModel = new NewCustomerAccountViewModel(customerAccount) { Branches = branches, Customer = customer }; return(View("CustomerAccountForm", viewModel)); }
public ActionResult Save(CustomerAccount account) { int userId = Convert.ToInt32(Request.Form["userId"]); int id = Convert.ToInt32(Request.Form["id"]); if (ModelState.IsValid) { var accountInDb = _context.Get(account.Id); if (id == 0) //add account { var customerId = Request.Form["customerId"]; var customerName = _customerContext.GetByCustomerId(customerId).FullName; account.CustomerId = customerId; account.CreatedAt = DateTime.Now; account.AccountName = customerName; account.IsOpen = true; account.AccountNumber = _context.GenerateAccountNumber(customerId, account.AccountType.ToString()); _context.Save(account); TempData["Success"] = "Account Created Successfully"; return(RedirectToAction("Index")); } if (account.Id != 0) //update account { accountInDb.AccountName = account.AccountName; accountInDb.BranchId = account.BranchId; accountInDb.Lien = account.Lien; _context.Update(account); TempData["Success"] = "Update Successful"; return(RedirectToAction("Index")); } } var customer = _customerContext.Get(userId); var branches = _userContext.GetBranches().ToList(); var viewModel = new NewCustomerAccountViewModel { Customer = customer, Branches = branches }; return(View("CustomerAccountForm", viewModel)); }