public ActionResult Create(CustomerAccount customeraccount) { customeraccount.AccountType = (AccountType)Convert.ToInt32(Request.Form["Type"]); customeraccount.branchName = Request.Form["Branch"]; var accountType = customeraccount.AccountType.ToString(); customeraccount.AccountNumber = _logic.generateAccountNumber(accountType, customeraccount.customerId); customeraccount.AccountName = Request.Form["AcctName"]; customeraccount.customerId = Request.Form["customerId"]; var id = Convert.ToInt32(Request.Form["customerId"]); try { if (ModelState != null) { if (customeraccount.AccountType != 0) { //Adding values into database _contextCustomerAccount.Add(customeraccount); //Saving Information into database _contextCustomerAccount.Save(customeraccount); return(RedirectToAction("Index", "CustomerAccount")); } if (customeraccount.AccountType == 0) { ModelState.AddModelError("AcctEmpty", "Account Type Not Selected"); } } } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } var cust = _contextCustomer.Get(id); var viewmodel = new CustomerAccountViewModels { Branches = _contextBranch.GetAll(), Customers = cust }; return(View(viewmodel)); }
//GET: CustomerAccount/Create public ActionResult Create(int id) { var cust = _contextCustomer.Get(id); var viewmodel = new CustomerAccountViewModels { Branches = _contextBranch.GetAll(), Customers = cust }; return(View(viewmodel)); }
//GET: CustomerAccount/Lien/{id} public ActionResult Lien(int?id) { if (id != null) { CustomerAccount account = _contextCustomerAccount.Get(id); var viewmodel = new CustomerAccountViewModels { CustomerAccount = account }; if (account != null) { return(View(viewmodel)); } return(HttpNotFound()); } return(HttpNotFound()); }