public JsonResult UpdateRole(Dic_Role model) { 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 (model.role_id == 0) { json.msg_text = "获取角色的ID出错。"; json.msg_code = "IDError"; goto next; } if (model.role_id == 1) { json.msg_text = "该角色不允许修改。"; json.msg_code = "CanNotUpdate"; goto next; } var same = db.Dic_Role.Where(x => x.role_name == model.role_name && x.role_id != model.role_id); if (same.Count() > 0) { json.msg_text = "该名称已存在。"; json.msg_code = "NameExists"; goto next; } db.Entry(model).State = EntityState.Modified; try { db.SaveChanges(); DBCaches <Dic_Role> .ClearCache("cache_role"); } catch { json.msg_text = "更新,请重新操作。"; json.msg_code = "UpdateErr"; goto next; } json.state = 1; json.msg_code = "success"; json.msg_text = "更新成功!"; SysLog.WriteLog(user, string.Format("更新角色[{0}]名称", model.role_name), IpHelper.GetIP(), "", 5, "", db); next: return(Json(json, JsonRequestBehavior.AllowGet)); }
public JsonResult DeleteRole(string rid) { int id = PageValidate.FilterParam(rid); 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 (id == 1) { json.msg_text = "该角色不允许删除。"; json.msg_code = "CanNotDel"; goto next; } Dic_Role model = db.Dic_Role.Find(id); if (model == null) { json.msg_text = "没有找到该角色,该角色可能已被删除。"; json.msg_code = "noThis"; goto next; } db.Dic_Role.Remove(model); try { db.SaveChanges(); DBCaches <Dic_Role> .ClearCache("cache_role"); } catch { json.msg_text = "删除失败,请重新操作。"; json.msg_code = "recyErr"; goto next; } json.state = 1; json.msg_code = "success"; json.msg_text = "删除成功!"; SysLog.WriteLog(user, string.Format("删除角色[{0}]", model.role_name), IpHelper.GetIP(), "", 5, "", db); next: return(Json(json, JsonRequestBehavior.AllowGet)); }
public ActionResult Role(Dic_Role model) { 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 = "没有权限当前内容。" })); } model.role_name = PageValidate.InputText(model.role_name, 50); if (db.Dic_Role.Where(x => x.role_name == model.role_name).Count() > 0) { ViewBag.msg = "角色名称已存在"; } else { db.Dic_Role.Add(model); try { db.SaveChanges(); DBCaches <Dic_Role> .ClearCache("cache_role"); } catch { ViewBag.msg = "角色添加失败,请重试。"; } } SysLog.WriteLog(user, string.Format("添加角色[{0}]", model.role_name), IpHelper.GetIP(), "", 5, "", db); ViewData["RoleList"] = DBCaches <Dic_Role> .getCache("cache_role");// db.Dic_Post.ToList(); return(View(model)); }