Esempio n. 1
0
        public void Delete()
        {
            int validID = GetValidPostID();


            var response = PostEndpoints.DeletePost(validID).Result;


            Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK);
        }
Esempio n. 2
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"));
        }
Esempio n. 3
0
        public async Task <IActionResult> Delete(int id)
        {
            var result = await PostEndpoints.DeletePost(id);

            return(RedirectToAction("Index", "Post"));
        }