Exemple #1
0
        public void Get()
        {
            int validID = GetValidPostID();

            var post = PostEndpoints.GetPost(validID).Result;

            Assert.IsTrue(post != null);
        }
        public async Task <IActionResult> Edit(int id)
        {
            var post = await PostEndpoints.GetPost(id);

            if (_userManager.GetUserId(User) != post.UserID) // Wrong user, trying to edit another post
            {
            }

            return(View(post));
        }
        public async Task <IActionResult> Edit(Post post)
        {
            var postToUpdate = await PostEndpoints.GetPost(post.ID);

            postToUpdate.Title      = post.Title;
            postToUpdate.Content    = post.Content;
            postToUpdate.RowVersion = post.RowVersion;

            var result = await PostEndpoints.UpdatePost(postToUpdate);

            return(RedirectToAction("Get", "Post", new { id = postToUpdate.ID }));
        }
Exemple #4
0
        private int GetValidPostID()
        {
            int validID = 0;

            for (int i = 1; i < 100; i++)
            {
                Post post = PostEndpoints.GetPost(i).Result;

                if (post != null && post.ID != 0)
                {
                    validID = post.ID;
                    break;
                }
            }

            return(validID);
        }
        public async Task <IActionResult> Get(int id)
        {
            var post = await PostEndpoints.GetPost(id);

            var username    = _userManager.Users.Where((user) => user.Id == post.UserID).FirstOrDefault().UserName;
            var currentUser = await _userManager.GetUserAsync(User);

            var username_comments = new List <string>();

            foreach (var comment in post.Comments)
            {
                var comment_username = _userManager.Users.Where((user) => user.Id == comment.UserID).FirstOrDefault().UserName;
                username_comments.Add(comment_username);
            }

            return(View(new PostUsername()
            {
                Post = post, Username = username, CurrentUser = currentUser, Username_comments = username_comments
            }));
        }