public IHttpActionResult Dislike([FromUri] string AccessToken, [FromUri] string PostId) { var UserId = TokenValidator.VerifyToken(AccessToken); var PostDisliked = PostAuxiliar.PostById(PostId); if (PostDisliked.Dislikes.Contains(UserId)) { PostDisliked.Dislikes.Remove(UserId); } else { PostDisliked.Dislikes.Add(UserId); } if (PostDisliked.Likes.Contains(UserId)) { PostDisliked.Likes.Remove(UserId); } var Update = Builders <Post> .Update .Set("Likes", PostDisliked.Likes) .Set("Dislikes", PostDisliked.Dislikes); PostAuxiliar.UpdatePostById(PostDisliked.Id, Update); int TotalLikes = PostDisliked.Likes.Count; int TotalDeslikes = PostDisliked.Dislikes.Count; dynamic Response = new { TotalLikes, TotalDeslikes }; return(Ok(Response)); }
private void UpdateParent(Post Parent, ObjectId CommentId) { var NewComments = new List <ObjectId>(Parent.Comments) { CommentId }; var Update = Builders <Post> .Update.Set("Comments", NewComments); PostAuxiliar.UpdatePostById(Parent.Id, Update); }