Ejemplo n.º 1
0
        private async void InsertItemAsync()
        {
            var title       = TBAddItemTitle.Text;
            var description = TBAddItemDescription.Text;
            var author      = TBAddItemAuthor.Text;
            var response    = new AuthResponseModel();
            int publishYear;

            if (!Regex.IsMatch(TBAddItemPublishYear.Text, @"^\d{4}$"))
            {
                MessageBox.Show("Year should consist of 4 Numbers!");
                return;
            }
            else
            {
                publishYear = Convert.ToInt32(TBAddItemPublishYear.Text);
            }

            ComboBoxItem typeItem = (ComboBoxItem)CBAddItemCategory.SelectedItem;
            string       category = typeItem.Content.ToString();

            ComboBoxItem typeItem2 = (ComboBoxItem)CBAddItemAccess.SelectedItem;
            string       access    = typeItem2.Content.ToString();

            if (category == T13.Content.ToString()) //Books
            {
                BookProcessor book = new BookProcessor();
                response = await book.InsertBook(title, description, author, publishYear, access);

                MessageBox.Show(response.Info);
            }
            else
            if (category == T14.Content.ToString()) //Newspapers
            {
                NewspaperProcessor newspaper = new NewspaperProcessor();
                response = await newspaper.InsertNewspaper(title, description, author, publishYear, access);

                MessageBox.Show(response.Info);
            }
            else
            if (category == T15.Content.ToString()) //Journals
            {
                JournalProcessor journal = new JournalProcessor();
                response = await journal.InsertJournal(title, description, author, publishYear, access);

                MessageBox.Show(response.Info);
            }
            else
            if (category == T16.Content.ToString()) //Magazines
            {
                MagazineProcessor magazine = new MagazineProcessor();
                response = await magazine.InsertMagazine(title, description, author, publishYear, access);

                MessageBox.Show(response.Info);
            }
            else
            if (category == T17.Content.ToString()) //Manuscripts
            {
                ManuscriptProcessor manuscript = new ManuscriptProcessor();
                response = await manuscript.InsertManuscript(title, description, author, publishYear, access);

                MessageBox.Show(response.Info);
            }
        }