public void AlterKnownBookInLibraryTest() { testManager.AddBook (book); Book b = new Book (); b.Title = "A Different Book"; b.Author = "Other Author"; b.Genre = "Horror"; b.YearPublished = 1992; b.FilePath = "/home/docs/book.mobi"; testManager.AlterBookData (0, b); Assert.IsTrue (testManager.GetBook (0).Equals (b)); }
public void RemoveBook(Book book) { try { using (SqliteCommand command = new SqliteCommand (Connection)) { command.CommandText = "DELETE FROM " + "Books " + "WHERE " + "BookTitle = :title AND " + "BookAuthor = :author AND " + "BookGenre = :genre AND " + "BookPath = :path AND " + "BookPublishedYear = :year;"; command.Parameters.AddWithValue (":title", book.Title); command.Parameters.AddWithValue (":author", book.Author); command.Parameters.AddWithValue (":genre", book.Genre); command.Parameters.AddWithValue (":year", book.YearPublished); command.Parameters.AddWithValue (":path", book.FilePath); if (command.ExecuteNonQuery () == 0) { throw new BookNotFoundException (); } } } catch (SqliteException e) { throw new SqliteException (e.Message); } }
public int GetBookIndex(Book book) { int index = 0; using (SqliteCommand command = new SqliteCommand (Connection)) { command.CommandText = "SELECT " + "BookID " + "FROM " + "Books " + "WHERE " + "BookTitle = :title AND " + "BookAuthor = :author AND " + "BookGenre = :genre AND " + "BookPath = :path AND " + "BookPublishedYear = :year;"; command.Parameters.AddWithValue (":title", book.Title); command.Parameters.AddWithValue (":author", book.Author); command.Parameters.AddWithValue (":genre", book.Genre); command.Parameters.AddWithValue (":year", book.YearPublished); command.Parameters.AddWithValue (":path", book.FilePath); SqliteDataReader reader = command.ExecuteReader (); if (reader.HasRows == false) { throw new BookNotFoundException (); } while (reader.Read ()) { index = reader.GetInt32 (0); } } return index; }
public Book GetBook(int index) { if (index < 0) { throw new BookNotFoundException (); } Book b = new Book (); using (SqliteCommand command = new SqliteCommand (Connection)) { command.CommandText = "SELECT " + "BookTitle, " + "BookAuthor, " + "BookGenre, " + "BookPublishedYear, " + "BookPath " + "FROM " + "Books " + "WHERE " + "BookID = :index;"; command.Parameters.AddWithValue (":index", index); SqliteDataReader reader = command.ExecuteReader (); if (reader.HasRows == false) { throw new BookNotFoundException (); } while (reader.Read ()) { b.Title = reader.GetString (0); b.Author = reader.GetString (1); b.Genre = reader.GetString (2); b.YearPublished = reader.GetInt32 (3); b.FilePath = reader.GetString (4); } } return b; }
public void AlterBookData(int bookID, Book book) { try { using (SqliteCommand command = new SqliteCommand (Connection)) { command.CommandText = "UPDATE " + "Books " + "SET " + "BookTitle = :title, " + "BookAuthor = :author, " + "BookGenre = :genre, " + "BookPublishedYear = :year, " + "BookPath = :path " + "WHERE " + "BookID = :id;"; command.Parameters.AddWithValue (":title", book.Title); command.Parameters.AddWithValue (":author", book.Author); command.Parameters.AddWithValue (":genre", book.Genre); command.Parameters.AddWithValue (":year", book.YearPublished); command.Parameters.AddWithValue (":path", book.FilePath); command.Parameters.AddWithValue (":id", bookID); if (command.ExecuteNonQuery () == 0) { throw new BookNotFoundException (); } } } catch (SqliteException e) { throw new SqliteException (e.Message); } }
public void AddBook(Book book) { try { using (SqliteCommand command = new SqliteCommand (Connection)) { command.CommandText = "INSERT INTO Books (" + "BookID, " + "BookTitle, " + "BookAuthor, " + "BookGenre, " + "BookPublishedYear, " + "BookPath) " + "VALUES (" + ":id, " + ":title, " + ":author, " + ":genre, " + ":year, " + ":path);"; command.Parameters.AddWithValue (":id", MaxId); command.Parameters.AddWithValue (":title", book.Title); command.Parameters.AddWithValue (":author", book.Author); command.Parameters.AddWithValue (":genre", book.Genre); command.Parameters.AddWithValue (":year", book.YearPublished); command.Parameters.AddWithValue (":path", book.FilePath); command.ExecuteNonQuery (); } } catch (SqliteException e) { throw new SqliteException (e.Message); } }
public void CreateLibraryManager() { testManager = new LibraryDatabaseManager (configFolderString); book = new Book(); book.Title = "Sample Book"; book.Author = "Sample Author"; book.Genre = "Sample Genre"; book.YearPublished = 1969; book.FilePath = "/home/books/ebooks/book.pdf"; }
public void Remove(Book book) { fileManager.DeleteBook (book.FilePath); databaseManager.RemoveBook (book); }
public void Alter(Book original, Book newBook) { }