public IHttpActionResult Edit(BookModel book) { try { BookService bookService = new BookService(); Book dbBook = bookService.GetBookByID(book.ID); if (dbBook == null) { return(NotFound()); } //dbBook.Description = book.Description; //dbBook.Author = book.Author; //dbBook.Genre = book.Genre; //dbBook.Quantity = book.Quantity; //dbBook.Title = book.Title; //dbBook.Description = book.Description; book.CopyValuesToEntity(dbBook); bookService.EditBook(dbBook); return(StatusCode(HttpStatusCode.NoContent)); // or use Ok() } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Put(BookModel book) { try { BookService bookService = new BookService(); Book dbBook = bookService.GetBookByID(book.ID); if (dbBook == null) { return(NotFound()); } book.CopyValuesToEntity(dbBook); bookService.EditBook(dbBook); return(StatusCode(HttpStatusCode.NoContent)); // or use Ok() } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Create(BookModel book) { try { BookService bookService = new BookService(); Book dbBook = new Book(); //dbBook.Description = book.Description; //dbBook.Author = book.Author; //dbBook.Genre = book.Genre; //dbBook.Quantity = book.Quantity; //dbBook.Title = book.Title; book.CopyValuesToEntity(dbBook); bookService.AddBook(dbBook); // return the newly created Book return(Ok(dbBook)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }