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()); } }
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); } }
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); } }
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); } }
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 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); } }
public bool CreateReader(string name, string surname) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { if (name == null) { return(false); } dataContext.AddUser(name, surname); return(true); } }
public bool CreateBook(Book book) { using (LinqLibraryDataContext dataContext = new LinqLibraryDataContext()) { if (book != null) { dataContext.AddBook(book); return(true); } return(false); } }
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); } }
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); } }
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 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); } }
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); } }
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); } }
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(); }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } } }
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 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 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 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); } }
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 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 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); } }