Example #1
0
 /// <summary>
 /// 授予某个角色访问一个或多个页面的权限
 /// </summary>
 /// <param name="roleID"></param>
 /// <param name="pageIDList"></param>
 public static void AddRolePages(long roleID, List <long> pageIDList)
 {
     try
     {
         tb_Roles role = BizRole.GetRoleByID(roleID);
         foreach (long id in pageIDList)
         {
             tb_Permissions p = new tb_Permissions();
             p.PageID = id;
             role.tb_Permissions.Add(p);
         }
         DataContext.SaveChanges();
     }
     catch (Exception ex)
     {
         LogHelper.g_Logger.ErrorFormat("授予角色权限失败!错误信息:{0}", ex.Message);
         throw ex;
     }
 }
Example #2
0
 /// <summary>
 /// 解除某个角色访问一个或多个页面的权限
 /// </summary>
 /// <param name="roleID"></param>
 /// <param name="pageIDList"></param>
 public static void RemoveRolePages(long roleID, List <long> pageIDList)
 {
     try
     {
         tb_Roles role = BizRole.GetRoleByID(roleID);
         foreach (long id in pageIDList)
         {
             tb_Permissions p = role.tb_Permissions.Where(t => t.PageID == id).First();
             role.tb_Permissions.Remove(p);
             DataContext.tb_Permissions.DeleteObject(p);
         }
         DataContext.SaveChanges();
     }
     catch (Exception ex)
     {
         LogHelper.g_Logger.ErrorFormat("删除角色权限失败!错误信息:{0}", ex.Message);
         throw ex;
     }
 }