You are working on a part of an inventory tracking app for a bookstore. Your job is to finish code responsible for creating, updateing, deleting and fetching books.
To complete the task, you need to implement all methods in BookRepository.cs
and BooksController.cs
that are throwing NotImplementedExceptions right now:
-
BookRepository.GetAllBooks
method, it should return all books from data context. -
BookRepository.GetBookById
method, it should return book by given id from data context, or null. -
BookRepository.AddBook
method, should returntrue
and add book to the data context, if there is no book with same isbn yet, otherwise if there is already book with same isbn, or we're trying to add null object, method should returnfalse
. -
BookRepository.UpdateBook
method should update the data context with given book. If it succeess, it should returntrue
. If we're trying to update null object, or trying to update isbn of book to another - already existing in database isbn, it should returnfalse
. -
BookRepository.DeleteBook
method shoud remove book with given id from the data context and returntrue
, if book with given id does not exists, it should returnfalse
. -
BooksController.Create
post action should call repository method responsible for adding a book, if it succeeds, it should redirect toIndex
action, otherwise returnCreate
view with model state errorBook creation failed
. -
BooksController.Update
post action should call repository method responsible for updateing the book if succeeds, it should redirect toIndex
action, otherwise returnUpdate
view with model state errorBook update failed
. -
BooksController.DeleteBook
post action should call repository method responsible for deleting a book, if it succeeds, it should redirect toIndex
action, otherwise returnNonFound
result. -
BooksController.Index
action should call repository method responsible for fetching all books.
- Book object consits of Id and couple of string fields. You don`t have to worry about any validation of those fields, expect ISBN number. This number should be uniqe (in terms of default string equality, in ex. "Abc" is not equal to "abc").
- Please be aware that some user could try to add book with isbn already existing in database or try to update to exisiting isbn. In such cases methods responsive for such behavior in repository should return
false
, and BooksController should behave as decribed previously. - Remember that
BooksController.Update
will be provided with object instance that will be unrelated to any data context scope.