public void TestGetBook() { using (LinqLibraryDataContext rep = new LinqLibraryDataContext(m_ConnectionString)) { rep.AddBook("nie", "nie", "nie", 2000); Book b = rep.GetBook("nie"); Book d = rep.GetBook(b.book_ID); Assert.AreEqual(b.title, d.title); rep.DeleteBook(b.book_ID); } }
public void TestUpdatingBooks() { using (LinqLibraryDataContext rep = new LinqLibraryDataContext(m_ConnectionString)) { rep.AddBook("just a book", "with some author", "publisher", 2002); Book hello = rep.GetBook("just a book"); rep.UpdateAuthor(hello.book_ID, "not a book"); rep.UpdatePublisher(hello.book_ID, "not a publisher"); rep.UpdateTitle(hello.book_ID, "not an author"); Book bye = rep.GetBook(hello.book_ID); Assert.AreEqual("not a book", bye.author); Assert.AreEqual("not a publisher", bye.publisher); Assert.AreEqual("not an author", bye.title); } }
public IEnumerable <EventDTO> GetEventsByBook(string title) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { List <EventDTO> toReturn = new List <EventDTO>(); Book book = dataContext.GetBook(title); List <Event> listEvent = new List <Event>(); if (book != null) { foreach (Event helloEvent in dataContext.GetAllEvents()) { if (helloEvent.book == book.book_ID) { listEvent.Add(helloEvent); } } foreach (Event e in listEvent) { toReturn.Add(ToDTO(e)); } return(toReturn); } return(toReturn); } }
public BookDTO FindBookID(int ID) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { return(ToDTO(dataContext.GetBook(ID))); } }
public Book FindBookByID(int ID) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { return(dataContext.GetBook(ID)); } }
public void TestAddingAndDeleting() { using (LinqLibraryDataContext rep = new LinqLibraryDataContext(m_ConnectionString)) { rep.AddBook("nie", "nie", "nie", 2000); Book b = rep.GetBook("nie"); Assert.IsNotNull(b); rep.DeleteBook(b.book_ID); } }
public bool BorrowBook(int user, int book) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { if (dataContext.GetReader(user) == null || dataContext.GetBook(book) == null) { return(false); } dataContext.AddEvent(user, book, DateTime.Now, false); return(true); } }
public bool CreateEvent(int userID, int bookID, DateTime when, bool is_Returning) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { if (dataContext.GetBook(bookID) != null && dataContext.GetReader(userID) != null) { dataContext.AddEvent(userID, bookID, when, is_Returning); return(true); } return(false); } }
public bool UpdateTitle(int id, string tit) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { if (dataContext.GetBook(id) == null) { return(false); } else { dataContext.UpdateTitle(id, tit); return(true); } } }
public bool UpdateBook(int ID, string title, string author, string publisher, int year) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { if (dataContext.GetBook(ID) != null) { dataContext.UpdateTitle(ID, title); dataContext.UpdateAuthor(ID, author); dataContext.UpdatePublisher(ID, publisher); dataContext.UpdateYear(ID, year); return(true); } return(false); } }
public bool UpdatePublisher(int id, string pub) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { if (dataContext.GetBook(id) == null) { return(false); } else { dataContext.UpdatePublisher(id, pub); return(true); } } }
public bool UpdateYear(int id, int y) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { if (dataContext.GetBook(id) == null) { return(false); } else { dataContext.UpdateYear(id, y); return(true); } } }
public bool DeleteBookByTitle(string title) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { Book book = dataContext.GetBook(title); if (book != null) { dataContext.DeleteBook(book.book_ID); return(true); } else { return(false); } } }
public bool RemoveBook(int ID) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { Book book = dataContext.GetBook(ID); if (book != null) { dataContext.DeleteBook(ID); return(true); } else { return(false); } } }
public void AddEvent() { using (LinqLibraryDataContext db = new LinqLibraryDataContext(m_ConnectionString)) { Event newEvent = new Event(); newEvent.book = db.GetBook("The Warded Man").book_ID; newEvent.reader = db.GetReader("Eliza", "Lech").reader_ID; newEvent.Event_date = DateTime.Now; newEvent.is_returning = false; db.AddEvent(newEvent); Event gotEvent = db.GetEvent(newEvent.event_ID); Assert.AreEqual(newEvent.book, gotEvent.book); Assert.AreEqual(newEvent.reader, gotEvent.reader); Assert.AreEqual(newEvent.Event_date, gotEvent.Event_date); } }
public void RemoveBook() { using (LinqLibraryDataContext db = new LinqLibraryDataContext(m_ConnectionString)) { Book book2 = new Book(); book2.title = "Dziady"; book2.author = "Adam Mickiewicz"; book2.yearPublished = 1834; book2.publisher = "greg"; db.AddBook(book2); int count = db.CountBooks(); Book someBook = db.GetBook("Dziady"); Assert.IsNotNull(someBook); db.DeleteBook(book2.book_ID); Assert.AreEqual(count - 1, db.CountBooks()); } }
public IEnumerable <Event> GetEventsForBookByBookTitle(string title) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { Book b = dataContext.GetBook(title); List <Event> toBeReturned = new List <Event>(); if (b != null) { foreach (Event e in dataContext.GetAllEvents()) { if (e.book == b.book_ID) { toBeReturned.Add(e); } } } return(toBeReturned); } }
public void AddBook() { using (LinqLibraryDataContext db = new LinqLibraryDataContext(m_ConnectionString)) { int count = db.Book.Count(); Book book1 = new Book(); book1.title = "Game of Thrones"; book1.author = "George R. R. Martin"; book1.yearPublished = 1996; book1.publisher = "Zysk i S-ka"; db.AddBook(book1); Book shouldBeGame = db.GetBook("Game of Thrones"); Assert.IsNotNull(shouldBeGame); Assert.AreEqual(shouldBeGame.title, "Game of Thrones"); Assert.AreEqual(shouldBeGame.author, "George R. R. Martin"); Assert.AreEqual(shouldBeGame.yearPublished, 1996); Assert.AreEqual(shouldBeGame.publisher, "Zysk i S-ka"); Assert.AreEqual(count + 1, db.CountBooks()); } }