Ejemplo n.º 1
0
        /// <summary>
        /// Checking books's input and sending it to the database
        /// </summary>
        /// <returns>True if book sent to DB, otherwise false</returns>
        private bool AddItemBook()
        {
            BookAddViewModel viewmodel = (BookAddViewModel)DataContext;
            Book             book      = viewmodel.MyBook;

            if (string.IsNullOrEmpty(book.Title))
            {
                MessageBox.Show("Title cannnot be empty.");
                return(false);
            }

            if (book.Author_AtBook == null)
            {
                MessageBox.Show("Author must be added.");
                return(false);
            }
            if (book.Genre_AtBook == null)
            {
                MessageBox.Show("Genre must be added.");
                return(false);
            }

            try
            {
                int id = MSAConnectionDB.SaveBookToDB(book);
                book.BookId = id;
                Books.AddBook(book);
                Genres.AddBookToGenre(book, book.Genre_AtBook);
                Authors.AddBookToAuthor(book, book.Author_AtBook);
                ActivateMainWindow();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(true);
        }