2016-11-07 33 views
0

特定のユーザーのfriendsをすべて取得しようとしています。 DNN RelationshipControllerから、私は2人のユーザー間の関係を得る方法しか見つけられません。ユーザーのすべての友人を得ることは可能ですか?DNNのすべての友人をプログラムで取得する

「2人のユーザ間の関係を取得します。

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

答えて

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

私はちょうどそれがユーザーの唯一の一端を働くことに気づきました。要求と友情を送信したユーザーは、上記の機能を呼び出すときにその要求を表示できます。しかし、受信者は自分のプロフィールからこの機能を呼び出すときに自分自身を友人と見なします。何か案は? – alwaysVBNET

関連する問題