public ActionResult SaveRoleMenu() { int roleId = Convert.ToInt32(Request["RoleID"]); string[] strArray = Request["MenuArray"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); DictRole dictRole = DictRoleService.LoadEntities(r => r.ID == roleId).First(); int roleMenuCount = dictRole.DictMenu.Count; int affectRow; if (roleMenuCount != 0) { dictRole.DictMenu = new List <DictMenu>(); affectRow = DictRoleService.SaveChange(); if (affectRow == 0) { return(Content("0")); } } List <DictMenu> addList = DictMenuService.LoadEntities(m => strArray.Contains(m.ID.ToString())).ToList(); if (dictRole.DictMenu.Count == 0 && addList.Count == 0) { return(Content("1")); } dictRole.DictMenu = addList; affectRow = DictRoleService.SaveChange(); if (affectRow == 0) { return(Content("0")); } else { return(Content("1")); } }
//菜单 public ActionResult GetDictMenu() { List <DictMenu> dictMenu = DictMenuService.LoadEntities(m => m.ParentID == 0).OrderBy(m => m.ID).ToList <DictMenu>(); var query = dictMenu.Select(m => new { m.ID, m.MenuName, m.MenuPath, m.Remark, children = DictMenuService.LoadEntities(sm => sm.ParentID == m.ID).Select(sm => new { sm.ID, sm.MenuName, sm.MenuPath, sm.Remark }) }); return(Content(JsonConvert.SerializeObject(query, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }))); }