Пример #1
0
 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);
     }
 }
Пример #2
0
 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);
     }
 }
Пример #3
0
        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);
            }
        }
Пример #4
0
 public BookDTO FindBookID(int ID)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         return(ToDTO(dataContext.GetBook(ID)));
     }
 }
Пример #5
0
 public Book FindBookByID(int ID)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         return(dataContext.GetBook(ID));
     }
 }
Пример #6
0
 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);
     }
 }
Пример #7
0
 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);
     }
 }
Пример #8
0
 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);
     }
 }
Пример #9
0
 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);
         }
     }
 }
Пример #10
0
 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);
     }
 }
Пример #11
0
 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);
         }
     }
 }
Пример #12
0
 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);
         }
     }
 }
Пример #13
0
 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);
         }
     }
 }
Пример #14
0
 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);
         }
     }
 }
Пример #15
0
        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);
            }
        }
Пример #16
0
        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());
            }
        }
Пример #17
0
 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);
     }
 }
Пример #18
0
        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());
            }
        }