Exemplo n.º 1
0
        /// <summary>
        /// Metoda wywoływana po naciśnięciu przycisku dodania nowej książki
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAddBook_Click(object sender, EventArgs e)
        {
            // Pobranie parametrów użytkownika z tabel
            string user             = textBoxUser.Text;
            string title            = textBoxTitle.Text;
            string genre            = textBoxGenre.Text;
            string authorsFirstName = textBoxAuthorsFirstName.Text;
            string authorsLastName  = textBoxAuthorsLastName.Text;
            string state            = textBoxState.Text;
            string restriction      = textBoxRestriction.Text;

            // Dodanie książki
            bool isAdded = booksRepository.AddBook(user, title, genre, authorsFirstName, authorsLastName, state, restriction);

            // Jeżeli książka została dodana
            if (isAdded)
            {
                // Odświeżamy tabelę
                RefreshDataGridViewBooks();
                // Czyścimy okienka
                ClearTextBoxes();
            }
            // Jeżeli nie, to wyświetlamy odpowiedni komunikat
            else
            {
                MessageBox.Show("Książka nie została dodana sprawdź poprawność parametrów");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine(Text.appWelcomeMessage);
            BooksRepository bookRepository = new BooksRepository();

            Console.WriteLine(Text.invitationToTheMainAction);
            string currentUserInput;

            while (true)
            {
                ShowWelcomeMenu();
                currentUserInput = Console.ReadLine();
                try
                {
                    if (currentUserInput == "1")
                    {
                        Console.WriteLine(Text.requestForTheBookInput);
                        string bookName = Console.ReadLine();
                        Console.WriteLine(Text.requestForTheYearOfBookPublishInput);
                        string year = Console.ReadLine();
                        Console.WriteLine(Text.requestForTheAuthorsInput);
                        var authorsString = Console.ReadLine();
                        var authors       = authorsString.Split(',');
                        bookRepository.AddBook(bookName, year, authors);
                    }
                    if (currentUserInput == "2")
                    {
                        bookRepository.ShowAuthors();
                    }
                    if (currentUserInput == "3")
                    {
                        bookRepository.ShowBooks();
                    }
                    if (currentUserInput == "4")
                    {
                        bookRepository.ShowAuthors();
                        bookRepository.ShowAuthorsBooks(Console.ReadLine());
                    }
                    if (currentUserInput == "5")
                    {
                        bookRepository.ShowBooks();
                        bookRepository.ShowBooksAuthors(Console.ReadLine());
                    }
                    if (currentUserInput == "6")
                    {
                        bookRepository.ShowBooks();
                        Console.WriteLine(Text.requestFortheBookIndexForDelete);
                        bookRepository.DeleteBook(Console.ReadLine());
                    }
                }
                catch (System.Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Exemplo n.º 3
0
 public IActionResult Create(Book book)
 {
     if (ModelState.IsValid)
     {
         var newBookId = _booksRepository.AddBook(book);
         return(RedirectToAction("Details", new { id = newBookId }));
     }
     else
     {
         InitializeViewBagGenresDropdown();
         return(View(book));
     }
 }
Exemplo n.º 4
0
 public IActionResult Create(Book book)
 {
     if (ModelState.IsValid)
     {
         var newBookId = _booksRepository.AddBook(book);
         return(RedirectToAction("Details", new { id = newBookId }));
     }
     ViewBag.Genres = new GenreRepository().GetAll().Select(x => new SelectListItem
     {
         Text  = x.Name,
         Value = x.Id.ToString()
     });
     return(View(book));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Metoda wywoływana po naciśnięciu przycisku do dodawania nowej książki
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAddBook_Click(object sender, EventArgs e)
        {
            //wyciagniecie danych z textboxow
            string title           = textBoxBookTitle.Text;
            int    yearOfPublish   = int.Parse(textBoxYearOfPublication.Text);
            float  price           = float.Parse(textBoxPrice.Text);
            string genre           = textBoxGenre.Text;
            string authorFirstName = textBoxFirstName.Text;
            string authorLastName  = textBoxLastName.Text;

            booksRepository.AddBook(title, yearOfPublish, price, genre, authorFirstName, authorLastName);

            RefreshDataGridViewBooks();
            ClearTextBoxes();
            labelLastAction.Text = "Dodano książkę";
        }
Exemplo n.º 6
0
        public void Books_AddBook_AddSameBook()
        {
            // Arrange
            var repo = new BooksRepository(context);
            var book = new BookView {
                Title       = TITLE_LOTR,
                Author      = AUTHOR_LOTR,
                ReleaseDate = RELEASE_LOTR,
                ISBN        = ISBN_LOTR
            };

            // Act
            repo.AddBook(book);

            // Assert
            Assert.Fail("Should have thrown AlreadyExistsException");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Przycisk odpowiadający za dodanie książki
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAddBook_Click(object sender, EventArgs e)
        {
            // Pobranie odpowiednich wartości wpisanych przez użytkownika
            string personName       = textBoxPersonName.Text;
            string title            = textBoxTitle.Text;
            string genre            = textBoxGenre.Text;
            string authorsFirstName = textBoxAuthorFirstName.Text;
            string authorsLastName  = textBoxAuthorLastName.Text;
            string state            = textBoxState.Text;
            string restriction      = textBoxRestriction.Text;

            // Funkcja dodająca książke do bazy
            booksRepository.AddBook(personName, title, genre, authorsFirstName, authorsLastName, state, restriction);
            // Odświeżenie tabel
            RefreshDataGridViewBooks();
            // Wyczyszczenie okien
            ClearTextBoxes();
        }
Exemplo n.º 8
0
        public void Books_AddBook_OneBook()
        {
            // Arrange
            var repo = new BooksRepository(context);
            var book = new BookView {
                Title       = "A Game Of Thrones",
                Author      = "George R.R. Martin",
                ReleaseDate = new DateTime(1996, 8, 1),
                ISBN        = "535135468543246846541"
            };

            // Act
            repo.AddBook(book);

            // Assert
            Assert.AreEqual(2, context.Books.Count());
            Assert.AreEqual("A Game Of Thrones", context.Books.Where(b => b.Title == "A Game Of Thrones").SingleOrDefault().Title);
            Assert.AreEqual("George R.R. Martin", context.Books.Where(b => b.Title == "A Game Of Thrones").SingleOrDefault().Author);
            Assert.AreEqual(new DateTime(1996, 8, 1), context.Books.Where(b => b.Title == "A Game Of Thrones").SingleOrDefault().ReleaseDate);
            Assert.AreEqual("535135468543246846541", context.Books.Where(b => b.Title == "A Game Of Thrones").SingleOrDefault().ISBN);
        }
Exemplo n.º 9
0
        public void Books_AddBook_AddBookAgainThatHasBeenDeleted()
        {
            // Arrange
            var repo        = new BooksRepository(context);
            var deletedBook = (from b in context.Books where b.Title == TITLE_LOTR select b).SingleOrDefault();

            deletedBook.Deleted = true;
            context.SaveChanges();

            var book = new BookView {
                Title       = TITLE_LOTR,
                Author      = AUTHOR_LOTR,
                ReleaseDate = RELEASE_LOTR,
                ISBN        = ISBN_LOTR
            };

            // Act
            repo.AddBook(book);

            // Assert
            Assert.AreEqual(2, context.Books.Where(b => b.ISBN == ISBN_LOTR).ToList().Count());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Metoda wywoływana po naciśnięciu przycisku do dodawania nowej książki
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAddBook_Click(object sender, EventArgs e)
        {
            string title         = textBoxBookTitle.Text;
            int    yearOfPublish = int.Parse(textBoxYearOfPublication.Text);
            float  price         = float.Parse(textBoxPrice.Text);

            string genre           = textBoxGenre.Text;
            string authorFirstName = textBoxFirstName.Text;
            string authorLastName  = textBoxLastName.Text;

            bool isAdded = booksRepository.AddBook(title, yearOfPublish, price, genre, authorFirstName, authorLastName);

            if (isAdded)
            {
                RefreshDataGridViewBooks();
                ClearTextBoxes();
                labelLastAction.Text = "Dodano książkę";
            }
            else
            {
                MessageBox.Show("Ksiązka nie została dodana sprawdź poprawność paretremów");
            }
        }
        public void AddBook_BookIsNull_ThrowsNullArgumentException()
        {
            Book book = null;

            Assert.Throws <ArgumentNullException>(() => _repository.AddBook(book));
        }
Exemplo n.º 12
0
 public Books Add([FromForm] Books item)
 {
     _BooksRepository.AddBook(item);
     return(item);
 }