/// <summary> /// 初始化用户权限 /// </summary> /// <param name="addUserId"></param> public static void AddAuthority(int addUserId) { using (venuesEntities db = new venuesEntities()) { tbl_sys_authority au = new tbl_sys_authority(); au.AT_UserId = addUserId; au.AT_MenuId = 1; db.AddTotbl_sys_authority(au); db.SaveChanges(); } }
/// <summary> /// 编辑用户对应的菜单列表,多对多关系 /// </summary> /// <param name="curUserID"></param> /// <param name="editUserID"></param> /// <param name="menusList"></param> /// <returns></returns> public static string EditAuthorityByUserId(int curUserID, int editUserID, String menusList, int userTypeId, string loginUserInfo) { //throw new NotImplementedException(); string returnStr = ""; try { using (venuesEntities db = new venuesEntities()) { //先删除用户权限关联关系表中,该用户的所有关联关系 String deleteReturn = AuthorityManager.deleteAllAuthoriyByUserID(editUserID, userTypeId, loginUserInfo); if (deleteReturn == "成功!") { List<string> mlist = new List<string>(menusList.Split(',')); foreach (String auMenuId in mlist) { if (auMenuId != "") { tbl_sys_authority au = new tbl_sys_authority(); au.AT_UserId = editUserID; au.AT_MenuId = int.Parse(auMenuId); au.AT_UserTypeId = userTypeId; db.AddTotbl_sys_authority(au); } } } if (db.SaveChanges() != 0) { returnStr = "成功!"; LogManager.addLog(KeyManager.LogTypeId_Option, KeyManager.MENUS.Menu_Authority, "编辑用户权限菜单,userID=" + editUserID, loginUserInfo); } else returnStr = "不成功!"; } } catch (Exception e) { returnStr = "不成功!"; LogManager.addLog(KeyManager.LogTypeId_Error, KeyManager.MENUS.Menu_Authority, "编辑用户权限菜单,userID=" + editUserID + ",错误信息:" + e.Message, loginUserInfo); } return returnStr; }