public void Save(Book book)
 {
     // SQL UPDATE
     var index = _books.FindIndex(x => x.Id == book.Id);
     _books.RemoveAt(index);
     _books.Insert(index, book);
 }
 public int Add(Book book)
 {
     // SQL INSERT
     book.Id = _books.Max(x => x.Id) + 1;
     _books.Add(book);
     return book.Id;
 }
 public void AddBook(Basket basket, Book book)
 {
     if (basket.Books == null)
     {
         basket.Books = new List<Book>();
     }
     basket.Books.Add(book);
 }
        public HttpResponseMessage Post(Book book)
        {
            if (book == null || !ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            var bookId = _bookRepository.Add(book);

            var response = Request.CreateResponse(HttpStatusCode.Created);
            response.Headers.Location = new Uri(Path.Combine(Request.RequestUri.AbsoluteUri, bookId.ToString()));
            return response;
        }
        //public HttpResponseMessage Patch(int id, Book book)
        //{
        //    if (book == null)
        //    {
        //        return Request.CreateResponse(HttpStatusCode.BadRequest);
        //    }
        //    var originalBook = _bookRepository.Get(id);
        //    if (!String.IsNullOrEmpty(book.Title))
        //        originalBook.Title = book.Title;
        //    if (book.Author != null)
        //    {
        //        originalBook.Author = book.Author;
        //    }
        //     _bookRepository.Save(originalBook);
        //    return Request.CreateResponse(HttpStatusCode.OK);
        //}
        public HttpResponseMessage Put(int id, Book book)
        {
            if (book == null || !ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            _bookRepository.Save(book);

            return Request.CreateResponse(HttpStatusCode.OK);
        }