Example #1
0
        public SinglePostViewComponentModel GetSinglePostViewComponentModel(string id, string visitorId)
        {
            var viewModel = new SinglePostViewComponentModel();
            var post      = this.GetPostById(id);

            if (post == null)
            {
                return(null);
            }
            var likes = userLikesRepository.All().Where(x => x.PostId == post.Id).Select(x => x.User).To <SimpleUserViewModel>().ToList();

            foreach (var liker in likes)
            {
                liker.IsFollowingCurrentUser = this.IsBeingFollowedBy(liker.Id, visitorId);
            }
            post.Likes = likes;
            var postAuthorId = post.User.Id;

            if (post.Likes.FirstOrDefault(x => x.Id == visitorId) == null)
            {
                post.IsLiked = false;
            }
            else
            {
                post.IsLiked = true;
            }

            viewModel.Post = post;
            viewModel.CommentInputModel = new CommentInputModel();
            viewModel.PostVisitorId     = visitorId;
            viewModel.PostAuthorId      = postAuthorId;
            return(viewModel);
        }
Example #2
0
        public async Task <IViewComponentResult> InvokeAsync(
            int currentUserId,
            PostViewModel post,
            string profilePictureURL)
        {
            SinglePostViewComponentModel viewModel = new SinglePostViewComponentModel
            {
                Post = post,
                CommentInputModel = new CommentInputModel(),
                ProfilePictureURL = profilePictureURL,
                PostVisitorId     = currentUserId,
                PostAuthorId      = post.UserId,
            };

            return(View(viewModel));
        }