예제 #1
0
        private void Btn_AddBookSave_Click(object sender, RoutedEventArgs e)
        {
            bool        hasErrors = false;
            AuthorModel author    = newBook.AuthorInfo as AuthorModel;

            if (author == null || !author.IsValid)
            {
                HighLightAuthorAndReportError();
                hasErrors = true;
            }

            if (string.IsNullOrEmpty(newBook.Title))
            {
                MessageBox.Show("The title is required for adding a new book!");
                TB_BookTitle.Background = Brushes.Red;
                hasErrors = true;
            }

            if (!_genreSelected || string.IsNullOrEmpty(newBook.Genre))
            {
                LB_CategorySelector.Background = Brushes.Red;
                MessageBox.Show("A Genre is required for adding a new book!");
                hasErrors = true;
            }

            if (!_formatSelected || string.IsNullOrEmpty(newBook.Format))
            {
                LB_FormatSelector.Background = Brushes.Red;
                MessageBox.Show("A Format is required for adding a new book!");
                hasErrors = true;
            }

            if (owned != null)
            {
                newBook.Owned = owned;
            }

            if (options != null)
            {
                newBook.ConditionsAndOptions = options;
            }

            if (hasErrors)
            {
                // prevent duplicate error reporting
                return;
            }

            if (!newBook.IsValid)
            {
                hasErrors = true;
            }

            if (!hasErrors)
            {
                if (newBook.AddBookToLibrary())
                {
                    Close();
                }
            }
        }