Exemplo n.º 1
0
        public async Task <IActionResult> delete_sub_comment([FromBody] DeleteSubComment deleteSubComment)
        {
            if (ModelState.IsValid)
            {
                Owner  owner                     = um.GetUser_Cookie(Request);
                string decoded_post_id           = _helper.DecodeFrom64(deleteSubComment.post_id);
                string decoded_parent_comment_id = _helper.DecodeFrom64(deleteSubComment.comment_id);
                string decoded_sub_comment_id    = _helper.DecodeFrom64(deleteSubComment.sub_comment_id);
                if (deleteSubComment.sub_post_id != null)
                {
                    await pm.increase_sub_post_sub_comment_countAsync(decoded_post_id, _helper.DecodeFrom64(deleteSubComment.sub_post_id), -1);

                    decoded_post_id = _helper.DecodeFrom64(deleteSubComment.sub_post_id);
                }
                else
                {
                    await pm.decrease_sub_commentsAsync(decoded_post_id, 1);
                }
                Comment comment = cm.getSubComment(decoded_post_id, decoded_parent_comment_id, decoded_sub_comment_id);
                if (comment.owner._id != owner._id)
                {
                    return(BadRequest(new { Message = "You are not the owner of the comment" }));
                }
                await cm.delete_sub_commentAsync(decoded_post_id, decoded_parent_comment_id, decoded_sub_comment_id);

                await cm.update_comment_count(decoded_post_id, decoded_parent_comment_id, -1);

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