//Get posts by filter, when is commentFilter not null then load also comments public async Task <QueryResultDto <UserProfilePostDto, PostFilterDto> > GetPostsWithUsersNicknamesAndCommentsByFilters(PostFilterDto postFilter, CommentFilterDto commentFilter) { using (UnitOfWorkProvider.Create()) { postFilter.SortCriteria = nameof(Post.PostedAt); var posts = await _userProfilePostService.GetPostsByFilterAsync(postFilter); foreach (var post in posts.Items) { if (postFilter.UserId == null && post.UserId != null) { //Add Nicknames post.NickName = (await _basicUsersService.GetAsync((int)post.UserId)).NickName; } if (commentFilter != null) { commentFilter.PostId = post.Id; post.Comments = await GetCommentsByFilter(commentFilter); } } return(posts); } }
public async Task <GroupProfileDto> GetGroupProfileAsync(int id) { using (UnitOfWorkProvider.Create()) { var groupProfile = await _groupProfileService.GetGroupProfileAsync(id); groupProfile.Posts = await GetGroupPostsAsync(id); foreach (var post in groupProfile.Posts) { if (!post.StayAnonymous) { post.User = await _groupProfileUserService.GetAsync((int)post.UserId); var comments = await _commentService.GetCommentsByPostIdAsync(post.Id); foreach (var comment in comments) { comment.NickName = (await _basicUsersService.GetAsync(comment.UserId)).NickName; } post.Comments = comments; } } groupProfile.GroupUsers = await _getGroupUsersService.GetGroupProfileUsersAsync(id); return(groupProfile); } }
public async Task <BasicUserDto> GetBasicUserWithFriends(int userId) { using (UnitOfWorkProvider.Create()) { var friendships = await _friendshipService.GetFriendshipsByUserIdAsync(userId, true); var friendshipsNotYet = await _friendshipService.GetFriendshipsByUserIdAsync(userId, false); var user = await _basicUsersService.GetAsync(userId); var friendshipDtos = friendships.ToList(); friendshipDtos.AddRange(friendshipsNotYet); user.Friends = friendshipDtos; return(user); } }