Exemplo n.º 1
0
        public IActionResult Like(int postId)
        {
            if (postId > 0)
            {
                PostModel post = _postService.GetById(postId, "");

                if (post != null)
                {
                    LikesModel alreadyLiked = _likesService.AlreadyLikedData(postId, Convert.ToInt32(User.FindFirst("Id").Value));

                    if (alreadyLiked == null)
                    {
                        LikesModel like = new LikesModel
                        {
                            PostId           = postId,
                            LikedById        = Convert.ToInt32(User.FindFirst("Id").Value),
                            CreationDate     = DateTime.Now,
                            ModificationDate = DateTime.Now,
                        };
                        _likesService.Add(like);
                        return(Ok("add"));
                    }

                    else
                    {
                        _likesService.Remove(alreadyLiked.Id);
                        return(Ok("remove"));
                    }
                }
                return(BadRequest());
            }
            return(BadRequest());
        }
Exemplo n.º 2
0
        public BroadcastResult Handle(AddLikeCommand command)
        {
            var likeTargetEntityId = command.EntityId;

            _likesService.Add(command.Author, likeTargetEntityId);
            UpdateCache(command.EntityType, likeTargetEntityId);

            return(BroadcastResult.Success);
        }
Exemplo n.º 3
0
        public BroadcastResult Handle(AddLikeCommand command)
        {
            var likeTarget         = command.Context.Value;
            var likeTargetEntityId = likeTarget.EntityId.Value;

            _likesService.Add(command.Author, likeTargetEntityId);
            UpdateCache(likeTarget.Type, likeTargetEntityId);

            return(BroadcastResult.Success);
        }