Created
July 18, 2019 09:22
-
-
Save ntakouris/daf6d74313e5cf320407a221fafe6e3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [HttpPost(ApiRoutes.Posts.Create)] | |
| public Task<IActionResult> Create([FromBody] CreatePostRequest postRequest) | |
| { | |
| var post = new Post {Id = postRequest.Id}; // <-- this is called mapping | |
| if (string.IsNullOrEmpty(post.Id) | |
| post.Id = Guid.NewGuid().ToString(); | |
| _posts.AddPost(post); | |
| var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; | |
| var locationUri = baseUrl + "/" + ApiRoutes.Posts.Get.Replace("{postId}", post.Id.ToString()); | |
| return Created(locationUri, post); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment