public IActionResult DelAdminRole(int id) { AdminRoles entity = AdminRoles.Find(AdminRoles._.Id == id); if (entity == null) { tip.Message = "系统找不到本管理组详情!"; return(Json(tip)); } if (entity.NotAllowDel == 1) { tip.Message = "本管理组设定不允许删除,如果需要删除,请先解除限制!"; return(Json(tip)); } //如果不是超级管理员,不允许删除 Core.Admin my = Core.Admin.GetMyInfo(); if (my.Roles.IsSuperAdmin != 1) { tip.Message = "非超级管理员,不能执行此操作!"; return(Json(tip)); } //如果只有一个管理组,不允许删除! if (AdminRoles.FindCount(null, null, null, 0, 0) == 1) { tip.Message = "只有一个管理组,不能删除!"; return(Json(tip)); } //删除管理组,并删除旗下所有管理员 Core.Admin.WriteLogActions($"执行删除管理组({entity.Id}:{entity.RoleName})详情;"); entity.Delete(); tip.Status = JsonTip.SUCCESS; tip.Message = "删除管理组成功"; return(Json(tip)); }
public IActionResult EditAdminRole(int id) { AdminRoles entity = AdminRoles.Find(AdminRoles._.Id == id); if (entity == null) { return(EchoTipPage("系统找不到本记录!", 0, true, "")); } if (string.IsNullOrEmpty(entity.Powers)) { entity.Powers = "[]"; } if (string.IsNullOrEmpty(entity.Menus)) { entity.Menus = "[]"; } if (string.IsNullOrEmpty(entity.AuthorizedArticleCagegory)) { entity.AuthorizedArticleCagegory = "[]"; } if (string.IsNullOrEmpty(entity.AuthorizedCagegory)) { entity.AuthorizedCagegory = "[]"; } //获取所有的菜单列表 IList <AdminMenu> list = AdminMenu.GetListTree(0, -1, false, false); //获取所有文章 商品栏目 IList <ArticleCategory> aclist = ArticleCategory.GetListTree(0, -1, true, true); ViewBag.aclist = aclist; IList <Category> pclist = Category.GetListTree(0, -1, true, true); ViewBag.pclist = pclist; ViewBag.MenuList = list; Core.Admin.WriteLogActions($"查看管理组({id})详情;"); return(View(entity)); }
public IActionResult EditAdminRole(int id) { AdminRoles entity = AdminRoles.Find(AdminRoles._.Id == id); if (entity == null) { return(EchoTipPage("系统找不到本记录!", 0, true, "")); } if (string.IsNullOrEmpty(entity.Powers)) { entity.Powers = "[]"; } if (string.IsNullOrEmpty(entity.Menus)) { entity.Menus = "[]"; } //获取所有的菜单列表 IList <AdminMenu> list = AdminMenu.GetListTree(0, -1, false, false); ViewBag.MenuList = list; Core.Admin.WriteLogActions($"查看管理组({id})详情;"); return(View(entity)); }
public IActionResult EditAdminRole(IFormCollection fc) { string Id = fc["Id"]; string RoleName = fc["RoleName"]; string RoleDescription = fc["RoleDescription"]; string IsSuperAdmin = fc["IsSuperAdmin"]; string NotAllowDel = fc["NotAllowDel"]; string OnlyEditMyselfArticle = fc["OnlyEditMyselfArticle"]; string OnlyEditMyselfProduct = fc["OnlyEditMyselfProduct"]; if (string.IsNullOrEmpty(OnlyEditMyselfArticle) || !Utils.IsInt(OnlyEditMyselfProduct)) { OnlyEditMyselfProduct = "0"; } if (string.IsNullOrEmpty(OnlyEditMyselfProduct) || !Utils.IsInt(OnlyEditMyselfProduct)) { OnlyEditMyselfProduct = "0"; } if (string.IsNullOrEmpty(Id)) { tip.Message = "错误参数传递!"; return(Json(tip)); } if (string.IsNullOrEmpty(RoleName)) { tip.Message = "管理组名称不能为空!"; return(Json(tip)); } AdminRoles entity = AdminRoles.Find(AdminRoles._.Id == int.Parse(Id)); if (entity == null) { tip.Message = "系统找不到本记录!"; return(Json(tip)); } entity.RoleName = RoleName; entity.RoleDescription = RoleDescription; entity.IsSuperAdmin = int.Parse(IsSuperAdmin); entity.NotAllowDel = !string.IsNullOrEmpty(NotAllowDel) && NotAllowDel == "1" ? 1 : 0; entity.OnlyEditMyselfArticle = int.Parse(OnlyEditMyselfArticle); entity.OnlyEditMyselfProduct = int.Parse(OnlyEditMyselfProduct); //处理权限 if (entity.IsSuperAdmin == 1) { entity.Powers = ""; entity.Menus = ""; } else { //第一步,获取菜单 string[] menuids = Request.Form["menuid"]; //获取所有的菜单列表 IList <AdminMenu> alllist = AdminMenu.GetListTree(0, -1, false, false); IList <AdminMenu> list = new List <AdminMenu>(); IList <AdminMenuEvent> listevents = new List <AdminMenuEvent>(); if (menuids != null && menuids.Length > 0) { foreach (string s in menuids) { if (Utils.IsInt(s) && alllist.FirstOrDefault(v => v.Id == int.Parse(s)) != null) { AdminMenu tmp = alllist.FirstOrDefault(a => a.Id == int.Parse(s)).CloneEntity(); list.Add(tmp); //处理详细权限 详细权限,每一行,则每一个菜单的详细权限,则同一个name string[] eventids = Request.Form["EventKey_" + s]; if (eventids != null && eventids.Length > 0) { foreach (var item in eventids) { if (Utils.IsInt(item)) { AdminMenuEvent model = AdminMenuEvent.Find(AdminMenuEvent._.Id == int.Parse(item)); if (model != null) { listevents.Add(model); } } } } } } //序列化成json if (list != null && list.Count > 0) { entity.Menus = JsonConvert.SerializeObject(list); } if (listevents != null && listevents.Count > 0) { entity.Powers = JsonConvert.SerializeObject(listevents); } } } //处理文章和商品栏目权限 string[] acpower = Request.Form["acpower"]; string[] pcpower = Request.Form["pcpower"]; List <int> acids = new List <int>(); List <int> pcids = new List <int>(); foreach (var item in acpower) { if (!string.IsNullOrEmpty(item) && Utils.IsInt(item)) { acids.Add(int.Parse(item)); } } foreach (var item in pcpower) { if (!string.IsNullOrEmpty(item) && Utils.IsInt(item)) { pcids.Add(int.Parse(item)); } } entity.AuthorizedArticleCagegory = JsonConvert.SerializeObject(acids); entity.AuthorizedCagegory = JsonConvert.SerializeObject(pcids); entity.Update(); tip.Status = JsonTip.SUCCESS; tip.Message = "编辑管理组详情成功"; tip.ReturnUrl = "close"; Core.Admin.WriteLogActions($"执行编辑管理组({entity.Id})详情;"); return(Json(tip)); }