public async Task <ActionResult> Post(MaintainPostRequest createPostRequest) //Automatic model validation was set with a combination of Action Filters and the FluentValidation library { var post = createPostRequest.CastTo <Post>(); post.UserId = HttpContext.GetCurrentUserId(); if (await _postService.CreateAsync(post)) { var response = post.CastTo <MaintainPostResponse>(); return(CreatedAtRoute(new { id = response.Id }, response)); } return(BadRequest()); }
public async Task <ActionResult> Update(int id, MaintainPostRequest updatePostRequest) { var post = updatePostRequest.CastTo <Post>(); post.Id = id; if (await _postService.UpdateAsync(post)) { var response = post.CastTo <MaintainPostResponse>(); return(Ok(response)); } return(NotFound()); }