public IHttpActionResult GetAuthor(int id) { Author author = context.Authors.Find(id); if (author == null) { return NotFound(); } var authorViewModel = new AuthorViewModel(author); return Ok(authorViewModel); }
public IHttpActionResult PostAuthor(AddAuthorBindingModel authorBindingModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var author = new Author(authorBindingModel.FirstName, authorBindingModel.LastName); context.Authors.Add(author); context.SaveChanges(); var authorViewModel = new AuthorViewModel(author); return CreatedAtRoute("DefaultApi", new { id = authorViewModel.Id }, authorViewModel); }