/// <summary> /// Edit a single Customer /// </summary> /// <param name="key">Key of the customer to edit</param> /// <returns>Edit Customer view</returns> public ActionResult Edit(Guid key) { using (var context = dataContextFactory.CreateByUser()) { var customer = (from x in context.Customers where x.ObjectId == key select x).SingleOrDefault(); if (customer == null) return new HttpStatusCodeResult(HttpStatusCode.NotFound); var countryQuery = from x in context.Countries select x; var viewModel = new CustomerEditViewModel(customer, countryQuery.ToList()); return View(viewModel); } }
public ActionResult Edit(CustomerEditViewModel viewModel) { if (ModelState.IsValid) { using (var context = dataContextFactory.CreateByUser()) { var customer = (from x in context.Customers where x.ObjectId == viewModel.Customer.ObjectId select x).SingleOrDefault(); if (customer == null) return new HttpStatusCodeResult(HttpStatusCode.NotFound); viewModel.ToEntity(customer); context.SaveChanges(); } return RedirectToAction("Index"); } return View(viewModel); }