public IActionResult Update([FromRoute] Guid postId, [FromBody] UpdatePostRequest request)
        {
            var post = new Post {
                Id   = postId,
                Name = request.Name
            };

            if (postService.Update(post))
            {
                return(Ok());
            }
            return(NotFound());
        }
Esempio n. 2
0
        public async Task <IActionResult> Update([FromRoute] Guid postId, [FromBody] UpdatePostRequest request)
        {
            var post = new Post
            {
                Id   = postId,
                Name = request.Name
            };

            var updated = await _postService.UpdatePostAsync(post);

            if (updated)
            {
                return(Ok(post));
            }
            return(NotFound());
        }
Esempio n. 3
0
        public async Task <IActionResult> Update([FromRoute] Guid postId, [FromBody] UpdatePostRequest request)
        {
            var userOwnsPost = await _postService.UserOwnsPostAsync(postId, HttpContext.GetUserId());

            if (!userOwnsPost)
            {
                return(BadRequest(new { error = "You do not own this post." }));
            }

            var post = await _postService.GetPostByIdAsync(postId);

            post.Name = request.Name;
            var updated = await _postService.UpdatePostAsync(post);

            if (updated)
            {
                return(Ok(post));
            }
            return(NotFound());
        }