public ActionResult Create(DepartmentViewModel model) { ServiceResult result = new ServiceResult(); TempData["Service_Result"] = result; if (ModelState.IsValid) { try { Department entity = new Department(); entity.Name = model.Name; entity.Description = model.Description; entity.Leader = model.Leader; DepartmentService.Create(entity); result.Message = "添加部门成功!"; LogHelper.WriteLog("添加部门成功"); return RedirectToAction("index"); } catch (DbEntityValidationException ex) { result.Message = Utilities.GetInnerMostException(ex); result.AddServiceError(result.Message); LogHelper.WriteLog("添加部门错误", ex); return View(model); } } else { result.Message = "请检查表单是否填写完整!"; result.AddServiceError("请检查表单是否填写完整!"); return View(model); } }
public void Update(Department model) { var target = Find(model.ID); db.Attach<Department>(target); target.Description = model.Description; target.Leader = model.Leader; target.Name = model.Name; db.Commit(); }
public void Delete(Department model) { var target = Find(model.ID); db.Remove<Department>(target); db.Commit(); }
public void Create(Department model) { db.Add<Department>(model); db.Commit(); }