Exemple #1
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"));
        }
        public async Task <IActionResult> Index()
        {
            var posts = await PostEndpoints.GetPosts();

            var userNames = new List <string>();

            List <IdentityUser> users = _userManager.Users.ToList();

            for (int i = 0; i < posts.Count; i++)
            {
                foreach (var user in users)
                {
                    if (user.Id == posts[i].UserID)
                    {
                        userNames.Add(user.UserName);
                    }
                }
            }

            return(View(new PostsUsers()
            {
                Posts = posts, Usernames = userNames
            }));
        }
Exemple #3
0
        public void GetAll()
        {
            var posts = PostEndpoints.GetPosts().Result;

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