Example #1
0
 public void RemoveReader()
 {
     using (LinqLibraryDataContext db = new LinqLibraryDataContext(m_ConnectionString))
     {
         db.AddUser("VeryUnusualName", "VeryUnusualName");
         int    count   = db.CountReaders();
         Reader whoIsHe = db.GetReader("VeryUnusualName", "VeryUnusualName");
         db.DeleteUser(whoIsHe.reader_ID);
         Assert.AreEqual(count - 1, db.CountReaders());
     }
 }
Example #2
0
 public IEnumerable <ReaderDTO> GetReaderDTOs()
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         List <ReaderDTO> toReturn = new List <ReaderDTO>();
         foreach (Reader r in GetAllReaders())
         {
             toReturn.Add(ToDTO(r));
         }
         return(toReturn);
     }
 }
Example #3
0
 public void GetReaderID()
 {
     using (LinqLibraryDataContext rep = new LinqLibraryDataContext(m_ConnectionString))
     {
         rep.AddUser("oh", "no");
         Reader oh = rep.GetReader("oh", "no");
         Reader no = rep.GetReader(oh.reader_ID);
         Assert.AreEqual(no.reader_ID, oh.reader_ID);
         Assert.AreEqual(no.reader_firstName, oh.reader_firstName);
         rep.DeleteUser(oh.reader_ID);
     }
 }
Example #4
0
 public bool BorrowBook(Reader user, Book book)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         if (user != null && book != null)
         {
             CreateEvent(user.reader_ID, book.book_ID, DateTime.Now, false);
             return(true);
         }
         return(false);
     }
 }
Example #5
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);
     }
 }
Example #6
0
 public IEnumerable <BookDTO> GetBookDTOs()
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         List <BookDTO> toReturn = new List <BookDTO>();
         foreach (Book b in GetAllBooks())
         {
             toReturn.Add(ToDTO(b));
         }
         return(toReturn);
     }
 }
Example #7
0
 public bool CreateReader(string name, string surname)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         if (name == null)
         {
             return(false);
         }
         dataContext.AddUser(name, surname);
         return(true);
     }
 }
Example #8
0
 public bool CreateBook(Book book)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         if (book != null)
         {
             dataContext.AddBook(book);
             return(true);
         }
         return(false);
     }
 }
Example #9
0
 public bool CreateReader(Reader reader)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         if (reader != null && dataContext.GetReader(reader.reader_ID) == null)
         {
             dataContext.AddUser(reader.reader_firstName, reader.reader_surname);
             return(true);
         }
         return(false);
     }
 }
Example #10
0
 public bool CreateBook(string title, int year, string publisher, string author)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         if (title != null)
         {
             dataContext.AddBook(title, author, publisher, year);
             return(true);
         }
         return(false);
     }
 }
Example #11
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);
     }
 }
Example #12
0
 public IEnumerable <EventDTO> GetEventDTOs()
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         List <EventDTO> toReturn = new List <EventDTO>();
         foreach (Event e in dataContext.GetAllEvents())
         {
             toReturn.Add(ToDTO(e));
         }
         return(toReturn);
     }
 }
Example #13
0
 public bool DeleteReader(int ID)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         Reader reader = dataContext.GetReader(ID);
         if (reader != null)
         {
             dataContext.DeleteUser(ID);
             return(true);
         }
         return(false);
     }
 }
Example #14
0
 public bool UpdateReader(int ID, string name, string surname)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         if (dataContext.GetReader(ID) != null)
         {
             dataContext.UpdateUserName(ID, name);
             dataContext.UpdateUserSurname(ID, surname);
             return(true);
         }
         return(false);
     }
 }
Example #15
0
        public static void ClassInitialize(TestContext context)
        {
            db = new LinqLibraryDataContext(BookTest.connectionString);
            Book book = new Book();

            book.title         = "Chrzest Ognia";
            book.author        = "Andrzej Sapkowski";
            book.yearPublished = 1996;
            book.publisher     = "superNOWA";

            db.Book.InsertOnSubmit(book);
            db.SubmitChanges();
        }
Example #16
0
 public Book FindBookByTitle(string title)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         foreach (Book book in dataContext.GetAllBooks())
         {
             if (book.title.Equals(title))
             {
                 return(book);
             }
         }
         return(null);
     }
 }
Example #17
0
 public Reader FindReaderByID(int ID)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         foreach (Reader r in dataContext.GetAllReaders())
         {
             if (r.reader_ID == ID)
             {
                 return(r);
             }
         }
         return(null);
     }
 }
Example #18
0
 public Reader FindReaderByData(string name, string surname)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         foreach (Reader user in dataContext.GetAllReaders())
         {
             if (user.reader_firstName == name && user.reader_surname == surname)
             {
                 return(user);
             }
         }
         return(null);
     }
 }
Example #19
0
 public Event GetEvent(int eventID)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         foreach (Event e in dataContext.GetAllEvents())
         {
             if (e.event_ID == eventID)
             {
                 return(e);
             }
         }
         return(null);
     }
 }
Example #20
0
 public void TestUpdateUser()
 {
     using (LinqLibraryDataContext rep = new LinqLibraryDataContext(m_ConnectionString))
     {
         rep.AddUser("airzile", "pods");
         Reader airZile = rep.GetReader("airzile", "pods");
         rep.UpdateUserName(airZile.reader_ID, "Stu");
         rep.UpdateUserSurname(airZile.reader_ID, "GizzardLizardWizard");
         airZile = rep.GetReader(airZile.reader_ID);
         Assert.AreEqual("Stu", airZile.reader_firstName);
         Assert.AreEqual(airZile.reader_surname, rep.GetReader(airZile.reader_ID).reader_surname);
         rep.DeleteUser(airZile.reader_ID);
     }
 }
Example #21
0
 public bool UpdateSurname(int id, string s)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         if (dataContext.GetReader(id) == null)
         {
             return(false);
         }
         else
         {
             dataContext.UpdateUserSurname(id, s);
             return(true);
         }
     }
 }
Example #22
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);
         }
     }
 }
Example #23
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);
         }
     }
 }
Example #24
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);
         }
     }
 }
Example #25
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);
     }
 }
Example #26
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);
     }
 }
Example #27
0
 public bool ReturnBook(int user, int book)
 {
     using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext())
     {
         foreach (EventDTO e in GetEventsByBook(book))
         {
             if (e.reader == user)
             {
                 dataContext.AddEvent(user, book, DateTime.Now, true);
                 return(true);
             }
         }
         return(false);
     }
 }
Example #28
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);
         }
     }
 }
Example #29
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);
         }
     }
 }
Example #30
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);
            }
        }