0

我正在尝试检索friends特定用户的所有内容。从 DNNRelationshipController我只能找到获取两个用户之间关系的方法。是否有可能获得一个用户的所有朋友?

'获取两个用户之间的关系:

DotNetNuke.Entities.Users.Social.RelationshipController.Instance.GetFriendRelationship(Me.UserInfo)
4

1 回答 1

2

我有这段代码。我得到当前用户,然后得到所有关系 userIds 是朋友(与追随者)并被“接受”。使用该列表,我加入回用户列表以获取朋友的用户属性并作为新对象返回。

希望这可以帮助。

private const int DNNSOCIAL_RELATIONSHIPTYPE_FRIEND = 1;
private const int DNNSOCIAL_RELATIONSHIPTYPE_FOLLOWER = 2;

public List<UserFriend> GetUserFriends(int portalid, int userid)
{
    UserInfo currentUser = UserController.GetUserById(portalid, userid);

    var friends = currentUser.Social.UserRelationships
                    .Where(r => r.RelationshipId == DNNSOCIAL_RELATIONSHIPTYPE_FRIEND 
                        && r.Status == RelationshipStatus.Accepted);

    return (from f in friends
            join u in UserController.GetUsers(portalid).Cast<UserInfo>()
            on f.RelatedUserId equals u.UserID
            select new UserFriend { UserId = u.UserID,  DisplayName = u.DisplayName, ProfilePicUrl = u.Profile.PhotoURL }).ToList();
}

...

public class UserFriend
{
    public int UserId { get; set; }
    public string DisplayName { get; set; }
    public string ProfilePicUrl { get; set; }
}

VB.NET版

Public Function GetUserFriends(portalid As Integer, userid As Integer) As List(Of UserFriend)
    Dim currentUser As UserInfo = UserController.GetUserById(portalid, userid)

Dim friends = currentUser.Social.UserRelationships.Where(Function(r) r.RelationshipId = DNNSOCIAL_RELATIONSHIPTYPE_FRIEND AndAlso r.Status = Social.RelationshipStatus.Accepted)

Return (From f In friends
        Join u In UserController.GetUsers(portalid).Cast(Of UserInfo)()
        On f.RelatedUserId Equals u.UserID
        Select New UserFriend With {.UserId = u.UserID, .DisplayName = u.DisplayName, .ProfilePicUrl = u.Profile.PhotoURL}).ToList()
 End Function
于 2016-11-08T13:55:13.133 回答