public bool Update(Book book) { if (this.books.Exists(match => match.Isbn == book.Isbn)) { this.books.Remove(book); this.books.Add(book); return true; } return false; }
// POST public HttpResponseMessage PostBook(Book book) { if (!string.IsNullOrWhiteSpace(book.Isbn)) { return Request.CreateResponse(HttpStatusCode.BadRequest); } else { catalog.Create(book); var uri = Url.Link("DefaultApi", new { isbn = book.Isbn }); var response = Request.CreateResponse<Book>(HttpStatusCode.Created, book); response.Headers.Location = new Uri(uri); return response; } }
public void Create(Book book) { this.books.Add(book); }
// PUT public HttpResponseMessage PutBook(string isbn, Book book) { if (!catalog.Update(book)) { return Request.CreateResponse(HttpStatusCode.NotFound); } else { return Request.CreateResponse<Book>(HttpStatusCode.OK, book); } }