public async Task <ActionResult <Comment> > DeleteComments(long id) { var CommentDelete = new CommentDelete { CommentId = id }; return(await CommentDelete.Excute()); }
public IActionResult DeleteComment(CommentDelete parameters) { var userID = JWTUtility.GetUserID(HttpContext); var role = JWTUtility.GetRole(HttpContext); var comment = (from comments in _context.Comments where comments.Id == parameters.CommentID select comments).Single(); if (role != RoleType.Admin && comment.Userid != userID) { return(BadRequest(new { error = "You do not have permission to delete this post" })); } _context.Comments.Remove(comment); _context.SaveChanges(); return(Ok()); }