Ejemplo n.º 1
0
        public void Test_Search_RetrievesBooksByAuthor()
        {
            Book testBook1 = new Book("The Call of Cthulhu", "A story written by HP Lovecraft.");
            Book testBook2 = new Book("Captain Underpants", "A silly children's book series.");
            Book testBook3 = new Book("The Call of Cthulhu", "A second edition printing by Penguin Books.");

            testBook1.Save();
            testBook2.Save();
            testBook3.Save();

            Author newAuthor1 = new Author("HP Lovecraft");
            Author newAuthor2 = new Author("Dav Pilkey");

            newAuthor1.Save();
            newAuthor2.Save();

            testBook1.AddBook(newAuthor1);
            testBook2.AddBook(newAuthor2);
            testBook3.AddBook(newAuthor1);

            List <Book> testList = new List <Book> {
                testBook1, testBook3
            };
            List <Book> returnedList = Book.SearchByAuthor("HP Lovecraft");

            Assert.Equal(testList, returnedList);
        }
Ejemplo n.º 2
0
        public void Test_MultAuthors_AddsMultAuthorsToBook()
        {
            Book testBook1 = new Book("The Call of Hamlet", "From the creators of Much Ado About Cthulhu.");

            testBook1.Save();

            Author newAuthor1 = new Author("HP Lovecraft");
            Author newAuthor2 = new Author("William Shakespeare");

            newAuthor1.Save();
            newAuthor2.Save();

            testBook1.AddBook(newAuthor1);
            testBook1.AddBook(newAuthor2);
            List <Book> returnedBook1 = Book.SearchByAuthor("HP Lovecraft");
            List <Book> returnedBook2 = Book.SearchByAuthor("William Shakespeare");

            Assert.Equal(returnedBook1, returnedBook2);
        }
Ejemplo n.º 3
0
        private void AppendBook()
        {
            int      bookID           = -1;
            string   isbn             = txtISBN.Text;
            string   title            = txtTitle.Text;
            int      genreID          = int.Parse(ddlGenres.SelectedValue);
            string   coverImage       = ddlCoverImages.SelectedItem.Text;
            string   description      = txtDescription.Text;
            int      authorID         = int.Parse(ddlAuthors.SelectedValue);
            int      publisherID      = int.Parse(ddlPublishers.SelectedValue);
            DateTime publicationDate  = Convert.ToDateTime(txtPublicationDate.Text);
            int      edition          = int.Parse(txtEdition.Text);
            string   language         = ddlLanguages.SelectedItem.Text;
            int      numOfPages       = int.Parse(txtNumOfPages.Text);
            double   price            = Convert.ToDouble(txtPrice.Text);
            DateTime registrationDate = Convert.ToDateTime(txtRegistrationDate.Text);
            int      totalCopies      = int.Parse(txtTotalCopies.Text);
            int      issuedCopies     = 0;
            string   status           = "Available";
            string   sectionID        = txtSectionID.Text;
            string   rackID           = txtRackID.Text;
            string   shelfID          = txtShelfID.Text;

            //Creates an instace of Book class
            Book book = new Book(isbn, title, genreID, coverImage, description, authorID, publisherID, publicationDate, edition, language,
                                 numOfPages, price, registrationDate);

            //Checks if book already exists or not
            if (!book.CheckIfBookExists(title, edition))
            {
                //if not, Calls a method in the Book class to append a new book
                bookID = book.AddBook(book);

                //Creates an instance of Inventory class & Adds a new inventory into database
                Inventory inventory = new Inventory(bookID, totalCopies, issuedCopies, status, sectionID, rackID, shelfID);

                //Calls a method in the Inventory class to append a new book
                inventory.AddInventory(inventory);
                divSuccess.Visible = true;
                lblNewBook.Text    = title;
                ClearTextFields();
            }
            else
            {
                book            = null;
                divFail.Visible = true;
            }
        }
Ejemplo n.º 4
0
        private async void AddButton_Click(object sender, RoutedEventArgs e)
        {
            Book book = new Book()
            {
                ReleaseDate = (ReleaseDateTextbox.Text != "") ? Convert.ToDateTime(ReleaseDateTextbox.Text) : default(DateTime?),
                Author      = AuthorTextbox.Text,
                Name        = NameTextbox.Text,
                Genre       = GenreTextbox.Text,
                Price       = (PriceTextbox.Text != "") ? Convert.ToSingle(PriceTextbox.Text) : default(float?),
                PageCount   = (PageCountTextbox.Text != "") ? Convert.ToInt16(PageCountTextbox.Text) : default(short?),
                State       = (StateTextbox.Text != "") ? (BookState?)Convert.ToByte(StateTextbox.Text) : default(BookState?)
            };

            await book.AddBook();

            MyBookListView.ItemsSource = await Book.GetBooks();
        }
Ejemplo n.º 5
0
        public void Test_SaveBookToDatabase()
        {
            Book testBook = new Book("Atlas Shrugged", "Lorem ipsum");

            testBook.Save();
            Author newAuthor = new Author("Ayn Rand");

            newAuthor.Save();
            testBook.AddBook(newAuthor);

            List <Book> result   = Book.GetAll();
            List <Book> testList = new List <Book> {
                testBook
            };

            Assert.Equal(testList, result);
        }
Ejemplo n.º 6
0
        public ActionResult IndexBook(AuthBookPublish model, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                //string strDDL = form["NameAuthor"].ToString();
                //string strDDLPublish = form["NamePublish"].ToString();
                book.AddBook(model.book, authors, publisher);
                //book.AddBook(model.book, strDDL, strDDLPublish, authors, publisher);
                AllViewBag();

                return(View("Index"));
            }

            else
            {
                AllViewBag();

                return(View("Index"));
            }
        }