public ActionResult Update(ViewModels.客戶聯絡人.UpdateViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } using (_db = new Models.客戶資料Entities()) { var customerContact = _db.客戶聯絡人.Find(viewModel.Id); if (null == customerContact) { return(HttpNotFound()); } customerContact.職稱 = viewModel.職稱; customerContact.姓名 = viewModel.姓名; customerContact.Email = viewModel.Email; customerContact.手機 = viewModel.手機; customerContact.電話 = viewModel.電話; _db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Update(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewModels.客戶聯絡人.UpdateViewModel viewModel; using (_db = new Models.客戶資料Entities()) { var customerContact = _db.客戶聯絡人.Find(id); if (null == customerContact) { return(HttpNotFound()); } viewModel = new ViewModels.客戶聯絡人.UpdateViewModel { Id = customerContact.Id, 客戶Id = customerContact.客戶Id, 職稱 = customerContact.職稱, 姓名 = customerContact.姓名, Email = customerContact.Email, 手機 = customerContact.手機, 電話 = customerContact.電話 }; } return(View(viewModel)); }