public JsonResult UpdateDepartment(int id, FormCollection collection) { if (!UserInfo.CurUser.HasRight("系统管理-部门管理")) return Json(new Result { success = false, obj = "没有权限" }); Models.Result result = new Models.Result(); var dept = (from o in db.Departments where o.Id == id select o).FirstOrDefault(); if (dept == null) { dept = new Department(); dept.PId = int.Parse(collection["pid"]); db.Departments.Add(dept); } dept.Name = collection["name"]; dept.DepartmentType = collection["departmenttype"]; if (dept.DepartmentType == null) dept.DepartmentType = ""; db.SaveChanges(); DepartmentBLL.UpdateDepartments(); result.success = true; result.obj = dept; return Json(result); }
static void list_findchildren(List<SelectListItem> list, Department parent, int level,int selectValue) { string pre=""; for(int i=0;i<level;i++)pre+=" "; list.Add(new SelectListItem { Value = parent.Id.ToString(), Text = pre + parent.Name,Selected=(selectValue==parent.Id) }); Departments.ForEach(o => { if (o.PId == parent.Id) list_findchildren(list, o, level + 1,selectValue); }); }
static void list_findchildren(List<Department> list, Department parent) { list.Add(parent); Departments.ForEach(o => { if (o.PId == parent.Id) list_findchildren(list, o); }); }
void addProject(List<Department> list, Department d) { bool found = false; foreach (var i in list) { if (i.Id == d.Id) { found = true; } } if (!found) list.Add(d); }