public void Delete() { Comment comment = GetValidComment(); var response = CommentEndpoints.DeleteComment(comment.ID).Result; Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK); }
public async Task <IActionResult> Delete(string id) { var user = await _userManager.FindByIdAsync(id); var posts = await PostEndpoints.GetPosts(); // Delete all comments from the user foreach (var post in posts) { foreach (var comment in post.Comments) { if (comment.UserID == user.Id) { await CommentEndpoints.DeleteComment(comment.ID); } } } // Delete all posts by user foreach (var post in posts) { if (post.UserID == user.Id) { // First delete all comments on that post foreach (var comment in post.Comments) { await CommentEndpoints.DeleteComment(comment.ID); } // Then delete the post await PostEndpoints.DeletePost(post.ID); } } // Delete the user from the database var result = await _userManager.DeleteAsync(user); return(RedirectToAction("Index", "User")); }
public async Task <IActionResult> Delete(int postId, int commentId) { var result = await CommentEndpoints.DeleteComment(commentId); return(RedirectToAction("Get", "Post", new { id = postId })); }