Skip to content

Instantly share code, notes, and snippets.

@ntakouris
Created July 18, 2019 09:22
Show Gist options
  • Select an option

  • Save ntakouris/daf6d74313e5cf320407a221fafe6e3a to your computer and use it in GitHub Desktop.

Select an option

Save ntakouris/daf6d74313e5cf320407a221fafe6e3a to your computer and use it in GitHub Desktop.
[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