// GET: api/Authors/5 public IHttpActionResult GetAuthorById(int id) { var author = db.Authors.Select(a => new { Id = a.Id, FirstName = a.FirstName, LastName = a.LastName, BookTitles = a.Books.Select(b => b.Title) }) .FirstOrDefault(a => a.Id == id); if (author == null) { return NotFound(); } var authorView = new AuthorViewModel.AuthorBookViewModel() { FirstName = author.FirstName, LastName = author.LastName, BookTitles = author.BookTitles }; return this.Ok(authorView); }
public IHttpActionResult GetBooksForAuthorById(int id) { var author = db.Authors.FirstOrDefault(a => a.Id == id); if (author == null) { return this.NotFound(); } var authorView = new AuthorViewModel.AuthorBookViewModel() { BookTitles = author.Books.Select(b => b.Title) }; return this.Ok(authorView); }