Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created March 18, 2017 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/21b7db42ac64b6c9648d2652504fa1cf to your computer and use it in GitHub Desktop.
Save dcomartin/21b7db42ac64b6c9648d2652504fa1cf to your computer and use it in GitHub Desktop.
// GET: api/Books/5
[ResponseType(typeof(BookDetailDTO))]
public async Task<IHttpActionResult> GetBook(int id)
{
var book = await db.Books.Include(b => b.Author).Select(b =>
new BookDetailDTO()
{
Id = b.Id,
Title = b.Title,
Year = b.Year,
Price = b.Price,
Author = b.Author,
Genre = b.Genre
}).SingleOrDefaultAsync(b => b.Id == id);
if (book == null)
{
return NotFound();
}
return Ok(book);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment