Beispiel #1
0
        private void AddBookButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(BookTitleBox.Text) || string.IsNullOrWhiteSpace(BookTitleBox.Text) || string.IsNullOrEmpty(BookGenreBox.Text) ||
                string.IsNullOrWhiteSpace(BookGenreBox.Text) || string.IsNullOrEmpty(AuthorNameBox.Text) || string.IsNullOrWhiteSpace(AuthorNameBox.Text))
            {
                MessageBox.Show("Puste pola!", "Błąd przy dodawaniu do bazy danych", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                var title = BookTitleBox.Text;
                //imię + nazwisko
                var authorName = AuthorNameBox.Text;
                var genreName  = BookGenreBox.Text;

                var author = Autorzy.First(x => x.Nazwa == authorName);

                var książka = new BookModel()
                {
                    Tytuł      = title,
                    Autor      = author,
                    Gatunek    = GenresDatabaseConnectionController.GetGenreByName(genreName),
                    IsBorrowed = false,
                };
                DataInsertionController.InsertBookIntoDatabase(książka);
                UpdateDataGrid();

                AuthorNameBox.Text = "";
                BookTitleBox.Text  = "";
                BookGenreBox.Text  = "";
            }
        }