public ActionResult Edit(SampleDataViewModel viewModel) { if (!ModelState.IsValid) { return View(viewModel); } using (ModelRepository db = new ModelRepository(this._factory.GetDatabaseObject())) { SampleDataService service = new SampleDataService(db); var model = service.GetObject(x => x.id == viewModel.Id); if (model == null) { return RedirectToAction("Index"); } service.Update(this._toBusinessModel(viewModel)); db.SaveChanges(); } return RedirectToAction("Index"); }
// // GET: /SampleData/Edit public ActionResult Edit(long? id) { if (id == null) { return RedirectToAction("Index"); } var viewModel = new SampleDataViewModel(); using (ModelRepository db = new ModelRepository(this._factory.GetDatabaseObject())) { SampleDataService service = new SampleDataService(db); var model = service.GetObject(x => x.id == id); if (model == null) { return RedirectToAction("Index"); } viewModel = this._toViewModel(model); } return View(viewModel); }