Created
March 18, 2017 01:00
-
-
Save dcomartin/21b7db42ac64b6c9648d2652504fa1cf to your computer and use it in GitHub Desktop.
This file contains 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
// 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