public JsonResult ContrlModule(EditModules models) { BaseJsonData json = new BaseJsonData(); if (!User.Identity.IsAuthenticated) { json.msg_text = "没有登陆或登陆失效,请重新登陆后操作。"; json.msg_code = "notLogin"; goto next; } int user = PageValidate.FilterParam(User.Identity.Name); if (!RoleCheck.CheckHasAuthority(user, db, "系统管理")) { json.msg_text = "没有权限。"; json.msg_code = "NoPower"; goto next; } if (ModelState.IsValid) { string ctrl_name; foreach (ModuleInfo info in models.modules) { ctrl_name = info.name; var no1 = db.Role_vs_Controller.Where(x => x.rvc_role_id != 1 && x.rvc_controller == ctrl_name); if (no1.Count() > 0) { db.Role_vs_Controller.RemoveRange(no1); db.SaveChanges(); } if (info.roles != null && info.roles.Length > 0) { foreach (RoleInfo rinfo in info.roles) { Role_vs_Controller rvc = new Role_vs_Controller(); rvc.rvc_role_id = rinfo.id; rvc.rvc_controller = ctrl_name; if (db.Role_vs_Controller.Find(rvc.rvc_role_id, rvc.rvc_controller) == null) { db.Role_vs_Controller.Add(rvc); } } } } db.SaveChanges(); SysLog.WriteLog(user, "修改系统模块", IpHelper.GetIP(), "", 5, "", db); json.state = 1; json.msg_code = "success"; json.msg_text = "数据更新成功。"; DBCaches2.ClearCache("dic-module"); } else { json.msg_code = "error"; json.msg_text = "数据接收错误。"; } next: return(Json(json, JsonRequestBehavior.AllowGet)); }
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 JsonResult DeleteDept(string pid) { int id = PageValidate.FilterParam(pid); BaseJsonData json = new BaseJsonData(); if (!User.Identity.IsAuthenticated) { json.msg_text = "没有登陆或登陆失效,请重新登陆后操作。"; json.msg_code = "notLogin"; goto next; } int user = PageValidate.FilterParam(User.Identity.Name); if (!RoleCheck.CheckHasAuthority(user, db, "系统管理")) { json.msg_text = "没有权限。"; json.msg_code = "NoPower"; goto next; } Dic_Department model = db.Dic_Department.Find(id); if (model == null) { json.msg_text = "没有找到该部门/科室,该部门/科室可能已被删除。"; json.msg_code = "noThis"; goto next; } db.Dic_Department.Remove(model); try { db.SaveChanges(); DBCaches2.ClearCache("cache_depts"); } catch { json.msg_text = "删除失败,请重新操作。"; json.msg_code = "recyErr"; goto next; } SysLog.WriteLog(user, string.Format("删除部门[{0}]", model.dept_name), IpHelper.GetIP(), "", 5, "", db); json.state = 1; json.msg_code = "success"; json.msg_text = "删除成功!"; next: return(Json(json, JsonRequestBehavior.AllowGet)); }
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)); }
public ActionResult ContrlModule() { 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 <ModuleInfo> models = DBCaches2.getModuleInfo(); foreach (ModuleInfo model in models) { int[] roles = (from rvc in db.Role_vs_Controller where rvc.rvc_controller == model.name select rvc.rvc_role_id ).ToArray(); RoleInfo[] rvcs = DBCaches2.getRoleInfo(); foreach (RoleInfo item in rvcs) { if (roles.Contains(item.id)) { item.hasrole = true; } else { item.hasrole = false; } } model.roles = rvcs; } return(View(models)); }
public JsonResult UpdateDept(DepartMentModel dept) { BaseJsonData json = new BaseJsonData(); if (!User.Identity.IsAuthenticated) { json.msg_text = "没有登陆或登陆失效,请重新登陆后操作。"; json.msg_code = "notLogin"; goto next; } int user = PageValidate.FilterParam(User.Identity.Name); if (!RoleCheck.CheckHasAuthority(user, db, "系统管理")) { json.msg_text = "没有权限。"; json.msg_code = "NoPower"; goto next; } if (dept.deptId == null || dept.deptId == 0) { json.msg_text = "获取部门/科室的ID出错。"; json.msg_code = "IDError"; goto next; } int id = (int)dept.deptId; Dic_Department model = db.Dic_Department.Find(id); if (model == null) { json.msg_text = "没有找到该部门/科室,该部门/科室可能已被删除。"; json.msg_code = "noThis"; goto next; } var same = db.Dic_Department.Where(x => x.dept_name == dept.deptName && x.dept_id != dept.deptId); if (same.Count() > 0) { json.msg_text = "该名称已存在。"; json.msg_code = "NameExists"; goto next; } model.dept_name = dept.deptName; model.dept_parent_id = dept.parentId; db.Entry(model).State = EntityState.Modified; try { db.SaveChanges(); DBCaches2.ClearCache("cache_depts"); } catch { json.msg_text = "更新,请重新操作。"; json.msg_code = "UpdateErr"; goto next; } SysLog.WriteLog(user, string.Format("更新部门[{0}]", model.dept_name), IpHelper.GetIP(), "", 5, "", db); json.state = 1; json.msg_code = "success"; json.msg_text = "更新成功!"; next: return(Json(json, JsonRequestBehavior.AllowGet)); }