public static bool IsUserInItemRole(this SPListItem item, SPPrincipal user, int roleId)
        {
            SPPermissionInfo userEffectivePermissions = item.GetUserEffectivePermissionInfo(user.LoginName);
            SPRoleDefinition roleDefinition           = item.Web.RoleDefinitions.GetById(roleId);

            foreach (SPRoleAssignment roleAssignment in userEffectivePermissions.RoleAssignments)
            {
                if (roleAssignment.RoleDefinitionBindings.Contains(roleDefinition))
                {
                    return(true);
                }
            }

            return(false);
        }