我正在尝试检索特定用户的所有friends
。从DNN RelationshipController
我只能找到获得两个用户之间关系的方法。是否有可能获得用户的所有朋友?
'获取两个用户之间的关系:
DotNetNuke.Entities.Users.Social.RelationshipController.Instance.GetFriendRelationship(Me.UserInfo)
答案 0 :(得分: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