public static List <SelectOption> getDepartment(int?id = null) { List <DepartMentModel> depts = DBCaches2.getDeptCache(); List <SelectOption> option = (from dep in depts where dep.parentId == (id == null ? dep.parentId : (int)id) select new SelectOption { id = dep.deptId.ToString(), text = dep.deptName }).ToList(); return(option); }
public ActionResult Department() { if (!User.Identity.IsAuthenticated) { return(RedirectToRoute(new { controller = "Login", action = "LogOut" })); } int user = PageValidate.FilterParam(User.Identity.Name); if (!RoleCheck.CheckHasAuthority(user, db, "系统管理")) { return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限执行当前操作。" })); } List <SelectOption> options = DropDownList.getDepartment(); ViewBag.Dept = DropDownList.SetDropDownList(options); ViewData["DeptList"] = DBCaches2.getDeptCache(); return(View(new DepartMentModel())); }
public ActionResult Department(DepartMentModel info) { if (!User.Identity.IsAuthenticated) { return(RedirectToRoute(new { controller = "Login", action = "LogOut" })); } int user = PageValidate.FilterParam(User.Identity.Name); if (!RoleCheck.CheckHasAuthority(user, db, "系统管理")) { return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限执行当前操作。" })); } List <SelectOption> options = DropDownList.getDepartment(); ViewBag.Dept = DropDownList.SetDropDownList(options); Dic_Department model = new Dic_Department(); model.dept_name = PageValidate.InputText(info.deptName, 50); if (db.Dic_Department.Where(x => x.dept_name == model.dept_name && x.dept_parent_id == info.parentId).Count() > 0) { ViewBag.msg = "名称已存在"; } else { model.dept_parent_id = info.parentId; db.Dic_Department.Add(model); try { db.SaveChanges(); DBCaches2.ClearCache("cache_depts"); } catch { ViewBag.msg = "部门添加失败,请重试。"; } } SysLog.WriteLog(user, string.Format("添加部门[{0}]", model.dept_name), IpHelper.GetIP(), "", 5, "", db); ViewData["DeptList"] = DBCaches2.getDeptCache(); return(View(info)); }