我有這個代碼躺在附近。我得到當前用戶,然後獲得所有關係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
我剛纔注意到,它的作品只有一個用戶的一端。發送請求和友誼建立的用戶可以查看何時調用上述功能。但是,接收者在從他的配置文件調用此函數時將自己視爲朋友。有任何想法嗎? – alwaysVBNET