public ActionResult Save(Customer customer) { if (!ModelState.IsValid) { var customerViewModel = new CustomerMshipViewModel() { Customer = customer, MembershipTypes = _context.MembershipTypes.ToList() }; return(View("CustomerForm", customerViewModel)); } if (customer.Id == 0) { _context.Customers.Add(customer); } else { var customerInDb = _context.Customers.Single(x => x.Id == customer.Id); customerInDb.Name = customer.Name; customerInDb.MembershipTypeId = customer.MembershipTypeId; } _context.SaveChanges(); return(RedirectToAction("Index", "Customer")); }
public ActionResult Edit(int?id) { var customer = _context.Customers.SingleOrDefault(x => x.Id == id); var viewModel = new CustomerMshipViewModel() { Customer = customer, MembershipTypes = _context.MembershipTypes.ToList() }; return(View("CustomerForm", viewModel)); }
public ActionResult New() { var membershipType = _context.MembershipTypes.ToList(); var viewModel = new CustomerMshipViewModel() { Customer = new Customer(), MembershipTypes = membershipType }; //return View("CustomerForm",viewModel); return(View("CustomerForm_Two", viewModel)); }