Exemplo n.º 1
0
        public async Task <IActionResult> Update([FromBody] CreateUpdatePostRequest request)
        {
            if (request.Id == null)
            {
                return(new BadRequestResult());
            }

            var existingPost = await this.postService.GetAsync(request.Id.Value);

            if (existingPost == null)
            {
                return(new BadRequestResult());
            }

            existingPost.Title   = request.Title;
            existingPost.Content = request.Content;

            await this.postService.UpdateAsync(existingPost);

            return(new OkResult());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([FromBody] CreateUpdatePostRequest request)
        {
            var createdPost = await this.postService.CreateAsync(request.Title, request.Content);

            return(new JsonResult(createdPost));
        }