public ActionResult Create(DepartmentDTO entity) { int errors = 0; string message = string.Empty; if (Const.IsNullOrEmpty(entity.Name)) { errors++; message = "部门名称不能为空。<br/>"; } using (DataClassesDataContext data = new DataClassesDataContext()) { if (data.DepartmentDTO.Where(u => u.ID == entity.ID).Count() > 0) { errors++; message = entity + " 部门已经存在。<br/>"; } if (errors == 0) { data.DepartmentDTO.InsertOnSubmit(entity); data.SubmitChanges(); } } return Json(new { success = (errors == 0), message = message }, JsonRequestBehavior.AllowGet); }
public ActionResult Update(DepartmentDTO entity) { try { if (entity.ID == 1) { return Json(new { success = false, message = "默认部门不能修改。<br/>" }, JsonRequestBehavior.AllowGet); } int errors = 0; string message = string.Empty; if (Const.IsNullOrEmpty(entity.Name)) { errors++; message = "部门名称不能为空。<br/>"; } using (DataClassesDataContext data = new DataClassesDataContext()) { var items = data.DepartmentDTO.Where(u => u.ID == entity.ID) .ToList(); if (items.Count == 0) { errors++; message = entity.Name + " 部门不存在。<br/>"; } if (errors == 0) { var e = items.First(); e.Name = entity.Name; e.Description = entity.Description; data.SubmitChanges(); } } return Json(new { success = (errors == 0), message = message }, JsonRequestBehavior.AllowGet); } catch { return View(); } }
partial void UpdateDepartmentDTO(DepartmentDTO instance);
partial void DeleteDepartmentDTO(DepartmentDTO instance);
partial void InsertDepartmentDTO(DepartmentDTO instance);