// // GET: /Department/ public ActionResult Index() { var modelList = new List<DepartmentViewModel>(); using (ModelRepository db = new ModelRepository(this._factory.GetDatabaseObject())) { DepartmentService service = new DepartmentService(db); foreach (var model in service.GetObjectList()) { modelList.Add(this._toViewModel(model)); } } return View(modelList); }
// // GET: /Department/Delete public ActionResult Delete(long? id) { if (id == null) { return RedirectToAction("Index"); } var viewModel = new DepartmentViewModel(); using (ModelRepository db = new ModelRepository(this._factory.GetDatabaseObject())) { DepartmentService service = new DepartmentService(db); var model = service.GetObjectList(x => x.Id == id).FirstOrDefault(); if (model == null) { return RedirectToAction("Index"); } viewModel = this._toViewModel(model); } return View(viewModel); }
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.GetObjectList(x => x.Id == viewModel.Id).FirstOrDefault(); if (model == null) { return RedirectToAction("Index"); } service.Update(this._toBusinessModel(viewModel)); db.SaveChanges(); } return RedirectToAction("Index"); }