Exemple #1
0
        public async Task <IActionResult> delete_comment([FromBody] DeleteComment deleteComment)
        {
            if (ModelState.IsValid)
            {
                Owner  owner                     = um.GetUser_Cookie(Request);
                string decoded_post_id           = _helper.DecodeFrom64(deleteComment.post_id);
                string decoded_parent_comment_id = _helper.DecodeFrom64(deleteComment.comment_id);
                if (deleteComment.sub_post_id != null)
                {
                    decoded_post_id = _helper.DecodeFrom64(deleteComment.sub_post_id);
                }
                Comment comment = cm.getComment(decoded_post_id, decoded_parent_comment_id);
                if (comment.owner._id != owner._id)
                {
                    return(BadRequest(new { Message = "You are not the owner of the comment" }));
                }
                if (deleteComment.sub_post_id != null)
                {
                    decoded_post_id = _helper.DecodeFrom64(deleteComment.sub_post_id);
                    await pm.increase_sub_post_comment_countAsync(_helper.DecodeFrom64(deleteComment.post_id), decoded_post_id, -1);
                }
                else
                {
                    await pm.decrease_commentsAsync(decoded_post_id, 1);

                    if (comment.comments > 0)
                    {
                        await pm.decrease_sub_commentsAsync(decoded_post_id, comment.comments);
                    }
                }
                await cm.delete_commentAsync(decoded_post_id, decoded_parent_comment_id);

                return(Ok(new { Message = "Delete sucessfullly" }));
            }
            else
            {
                return(BadRequest(new { Message = "Please fill in something" }));
            }
        }