示例#1
0
        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 }));
        }
示例#2
0
        public void Delete()
        {
            Comment comment = GetValidComment();

            var response = CommentEndpoints.DeleteComment(comment.ID).Result;

            Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK);
        }
示例#3
0
        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);
        }
示例#4
0
        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"));
        }
示例#5
0
        public async Task <IActionResult> Delete(int postId, int commentId)
        {
            var result = await CommentEndpoints.DeleteComment(commentId);

            return(RedirectToAction("Get", "Post", new { id = postId }));
        }
示例#6
0
        public void GetAll()
        {
            var comments = CommentEndpoints.GetComments().Result;

            Assert.IsTrue(comments.Count != 0);
        }