public async Task <IActionResult> Create(int postId, string content) { var userId = await _userManager.GetUserIdAsync(await _userManager.GetUserAsync(User)); var result = CommentEndpoints.CreateComment(postId, userId, content); return(RedirectToAction("Get", "Post", new { id = postId })); }
public void Delete() { Comment comment = GetValidComment(); var response = CommentEndpoints.DeleteComment(comment.ID).Result; Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK); }
private Comment GetValidComment() { for (int i = 1; i < 100; i++) { Comment comment = CommentEndpoints.GetComment(i).Result; if (comment != null && comment.ID != 0) { return(comment); } } return(null); }
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 })); }
public void GetAll() { var comments = CommentEndpoints.GetComments().Result; Assert.IsTrue(comments.Count != 0); }