Esempio n. 1
0
        public IActionResult Profile(string userId)
        {
            UserWithFollowersAndFollowingDTO user = this.UsersFollowingFunctionalityService.GetUserById(userId);
            List <PostDTO> postsOfUser            = this.UsersPostsService.GetAllImagePostsOfGivenUsersIds(new List <string>()
            {
                userId
            })
                                                    .OrderByDescending(post => post.DateTimeCreated)
                                                    .ToList();

            return(this.View(this.FillUserProfileViewModelWithData(user, postsOfUser)));
        }
Esempio n. 2
0
        private UserProfileViewModel FillUserProfileViewModelWithData(UserWithFollowersAndFollowingDTO user, List <PostDTO> postsOfUser)
        {
            return(new UserProfileViewModel()
            {
                Name = user.Name,
                UserId = user.Id,
                UserPosts = postsOfUser.Select(post =>
                {
                    List <UserLikedPostHomeIndexViewModel> usersWhoLikeTheCurrentPost =
                        this.likesService.GetPeopleWhoLikePost(post.PostId).Select(
                            user => new UserLikedPostHomeIndexViewModel(
                                user.UserName,
                                user.Id,
                                this.GetProfilePicturePath(user.Id)))
                        .ToList();

                    return new PostHomeIndexViewModel
                    {
                        Description = post.Description,
                        Username = post.Username,
                        TimeSinceCreated = this.timeConvertingService.ConvertDateTime(post.DateTimeCreated),
                        PostId = post.PostId,
                        Comments = post.Comments.Select(comment => new CommentHomeIndexViewModel(
                                                            comment.Content,
                                                            comment.Username,
                                                            comment.UserId,
                                                            this.GetProfilePicturePath(comment.UserId))).ToList(),
                        UserProfilePicturePath = this.GetProfilePicturePath(post.CreatorId),
                        UserId = post.CreatorId,
                        UsersLikedThePost = usersWhoLikeTheCurrentPost,
                        HasCurrentUserLikedThePost = usersWhoLikeTheCurrentPost.Any(user => user.Id == this.GetUserId()),
                        LogedIdUserId = this.GetUserId(),
                        PhotosPaths = post.PhotosIds.Select(photoId => this.GetFileUrl(photoId)).ToList(),
                        VideosPaths = post.VideosIds.Select(videoId => this.GetFileUrl(videoId)).ToList(),
                    };
                })
                            .ToList(),
                ProfilePicturePath = this.GetProfilePicturePath(user.Id),
            });
        }