public ActionResult Save(Customer customer) { if (!ModelState.IsValid) { var viewModel = new CustomerFormViewModel { Customer = customer, MembershipTypes = _context.MembershipTypes.ToList() }; return View("CustomerForm", viewModel); } if (customer.Id == 0) _context.Customers.Add(customer); else { var customerInDb = _context.Customers.Single(c => c.Id == customer.Id); //Mapper.Map(customer, customerInDb); customerInDb.MembershipTypeId = customer.MembershipTypeId; customerInDb.Name = customer.Name; customerInDb.Birthday = customer.Birthday; customerInDb.IsSubscribedToNewsletter = customer.IsSubscribedToNewsletter; customerInDb.MembershipType = customer.MembershipType; } _context.SaveChanges(); return RedirectToAction("GetCustomers"); }
public ActionResult New() { var membershipTypes = _context.MembershipTypes.ToList(); var viewModel = new CustomerFormViewModel { MembershipTypes = membershipTypes }; return View("CustomerForm",viewModel); }
public ActionResult CustomerForm() { //get all membership types from db var membershipTypes = _context.MembershipTypes.ToList(); var viewModel = new CustomerFormViewModel { MembershipTypes = membershipTypes }; return View(viewModel); }
public ActionResult Edit(int id) { var customer = _context.Customers.SingleOrDefault(c => c.Id == id); if (customer == null) return HttpNotFound(); var viewModel = new CustomerFormViewModel { Customer = customer, MembershipTypes = _context.MembershipTypes.ToList() }; return View("CustomerForm", viewModel); }