/// <summary> /// 添加或修改菜单 /// </summary> /// <param name="model"></param> /// <param name="appid"></param> /// <returns></returns> public ActionResult Save(MenuInputDto model, string appid) { model.ParentId = model.ParentId == 0 ? null : model.ParentId; if (string.IsNullOrEmpty(model.IconUrl) || !model.IconUrl.Contains("/")) { model.IconUrl = null; } Menu m = MenuBll.GetById(model.Id); if (m == null) { if (!string.IsNullOrEmpty(appid) && ClientAppBll.Any(a => a.AppId.Equals(appid))) { ClientApp app = ClientAppBll.GetFirstEntity(a => a.AppId.Equals(appid)); app.Menus.Add(model.Mapper <Menu>()); bool saved = ClientAppBll.UpdateEntitySaved(app); return(ResultData(null, saved, saved ? "添加成功" : "添加失败")); } var menu = MenuBll.AddEntitySaved(model.Mapper <Menu>()); return(menu != null?ResultData(menu, true, "添加成功") : ResultData(null, false, "添加失败")); } Mapper.Map(model, m); bool b = MenuBll.UpdateEntitySaved(m); return(ResultData(null, b, b ? "修改成功" : "修改失败")); }
public ActionResult Edit(long id = 0) { if (id == 0) { return(View(new Menu())); } var info = MenuBll.GetById(id); return(View(info)); }
/// <summary> /// 移除菜单权限 /// </summary> /// <param name="id">菜单id</param> /// <param name="pid">权限id</param> /// <returns></returns> public ActionResult RemovePermission(int id, int pid) { Menu menu = MenuBll.GetById(id); Permission permission = PermissionBll.GetById(pid); if (menu != null && permission != null) { menu.Permission.Remove(permission); bool b = MenuBll.UpdateEntitySaved(menu); return(ResultData(null, b, b ? "权限分配成功!" : "权限分配失败!")); } return(ResultData(null, false, "未找到菜单或权限!")); }
public JsonResult GetLeftMenu(long topMenuId) { if (UserContext.CurrentUser.GId == 1) { //如果是平台管理员 //获取父级菜单 var parentMenuList = GetMenuListBy(0); var kidMenuList = new List <Menu>(); if (parentMenuList != null && parentMenuList.Any()) { if (topMenuId <= 0) { //获取第一个菜单的子级 var first = parentMenuList[0]; kidMenuList = GetMenuListBy(first.Id); if (kidMenuList == null) { kidMenuList = new List <Menu>(); } } else { var first = parentMenuList.FirstOrDefault(m => m.Id == topMenuId); if (first != null) { kidMenuList = GetMenuListBy(first.Id); if (kidMenuList == null) { kidMenuList = new List <Menu>(); } } } } kidMenuList = kidMenuList.Where(a => a.IsStop == false).ToList(); kidMenuList = kidMenuList.OrderBy(a => a.Seq).ToList(); return(Json(kidMenuList, JsonRequestBehavior.AllowGet)); } else { List <Menu> leftMenuList = new List <Menu>();//页面左侧菜单 //获取用户权限 var groupAuthList = GroupAuthorityBll.GetGroupAuthorityList(UserContext.CurrentUser.GId); if (groupAuthList == null || !groupAuthList.Any()) { return(Json(leftMenuList, JsonRequestBehavior.AllowGet)); } //获取菜单 var parent = MenuBll.GetById(topMenuId); //获取所有菜单 var menuList = MenuBll.GetMenus(); //获取所有的子菜单 var kidList = menuList.Where(m => m.Pid == parent.Id); if (kidList != null && kidList.Any()) { foreach (var auth in groupAuthList) { var menu = kidList.FirstOrDefault(m => m.Id == auth.MenuId); if (menu != null && !leftMenuList.Exists(m => m.Id == menu.Id)) { leftMenuList.Add(menu); } } } leftMenuList = leftMenuList.Where(a => a.IsStop == false).ToList(); leftMenuList = leftMenuList.OrderBy(a => a.Seq).ToList(); return(Json(leftMenuList, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 获取菜单详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Get(int id) { MenuOutputDto c = MenuBll.GetById(id).Mapper <MenuOutputDto>(); return(ResultData(c)); }