public ActionResult Create(EmployeeViewModel viewModel) { if (!ModelState.IsValid) { return View(viewModel); } using (ModelRepository db = new ModelRepository(this._factory.GetDatabaseObject())) { EmployeeService service = new EmployeeService(db); service.Add(this._toBusinessModel(viewModel)); db.SaveChanges(); } return RedirectToAction("Index"); }
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.GetObjectList(x => x.Id == viewModel.Id).FirstOrDefault(); if (model == null) { return RedirectToAction("Index"); } service.Update(this._toBusinessModel(viewModel)); db.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Edit(DepartmentViewModel viewModel) { if (!ModelState.IsValid) { return View(viewModel); } using (ModelRepository db = new ModelRepository(this._factory.GetDatabaseObject())) { DepartmentService service = new DepartmentService(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"); }