Exemplo n.º 1
0
        public IViewComponentResult Invoke(int id, string userId)
        {
            var comments = commentService.GetComments(id);

            if (comments != null)
            {
                var commentsViewModel = mapper.Map <List <CommentViewModel> >(comments);

                if (userId != null)
                {
                    foreach (var item in commentsViewModel)
                    {
                        var fullname = profileService.FindFullName(item.UserId);

                        item.FullName = new FullNameViewModel {
                            FirstName = fullname.FirstName, LastName = fullname.LastName
                        };

                        item.UserLike = likeService.UserLike(item.Id, userId);

                        item.Count = likeService.GetCountLikes(item.Id);
                    }
                }
                else
                {
                    foreach (var item in commentsViewModel)
                    {
                        var fullname = profileService.FindFullName(item.UserId);

                        item.FullName = new FullNameViewModel {
                            FirstName = fullname.FirstName, LastName = fullname.LastName
                        };

                        item.Count = likeService.GetCountLikes(item.Id);
                    }
                }
                return(View(commentsViewModel));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
 public ActionResult Like([FromQuery] int commentId)
 {
     try
     {
         var  userId     = User.FindFirst(ClaimTypes.NameIdentifier).Value;
         bool isLiked    = likeService.IsAddedLike(commentId, userId);
         var  likeAmount = likeService.GetCountLikes(commentId);
         return(Ok(new { isLiked, likeAmount }));
     }
     catch
     {
         return(Unauthorized());
     }
 }