예제 #1
0
        public PostModel getPostModel(string postId, string loginedUserId)
        {
            Post post = postDao.getPostById(postId);

            User            user       = userDao.getUserByPostId(post.id);
            UserAvatarModel userOfPost = new UserAvatarModel()
            {
                Id = user.id, Username = user.username, Avatar = user.avatar
            };
            List <CommentModel> top3CommentModels = commentDao.getAllCommentModelsOfPost(post.id);
            int    numberOfLikes = favoriteDao.getNumberOfLikesInPost(post.id);
            string timeAgo       = DateTimeUtils.getTimeAgo(post.time.GetValueOrDefault());
            bool   isLike        = favoriteDao.isLikeByUser(loginedUserId, post.id);

            PostModel postModel = new PostModel()
            {
                UserOfPost        = userOfPost,
                PostId            = post.id,
                PostContent       = post.content,
                PostImage         = post.image,
                Top3CommentModels = top3CommentModels,
                NumberLikes       = numberOfLikes,
                Time                = post.time,
                TimeAgo             = timeAgo,
                IsLikeByLoginedUser = isLike
            };

            return(postModel);
        }