2016-11-07 54 views
0

我試圖檢索特定用戶的所有friends。從DNN RelationshipController我只能找到獲得兩個用戶之間關係的方式。是否有可能獲得用戶的所有朋友?以編程方式獲取DNN中的所有朋友

「獲取的關係,兩個用戶之間:

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

回答

2

我有這個代碼躺在附近。我得到當前用戶,然後獲得所有關係userIds,這是朋友(與追隨者)並且是'Accepted'。使用該列表,我會回到用戶列表以獲取朋友的用戶屬性並作爲新對象返回。

希望這會有所幫助。

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 
+0

我剛纔注意到,它的作品只有一個用戶的一端。發送請求和友誼建立的用戶可以查看何時調用上述功能。但是,接收者在從他的配置文件調用此函數時將自己視爲朋友。有任何想法嗎? – alwaysVBNET

相關問題