/// <summary> /// Takes the input from GUI and checks if it is null or empty, if not it creates a new book. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddBook_Click(object sender, EventArgs e) { int id = bookService.GenerateId(); Author author = lbChooseAut.SelectedItem as Author; string title = txtTitle.Text; string isbn = txtIsbn.Text; string descrip = txtDescription.Text; if (string.IsNullOrEmpty(title) && (string.IsNullOrEmpty(isbn) && (string.IsNullOrEmpty(descrip)))) { MessageBox.Show("Input fields are not filled in."); } else if (lbChooseAut.SelectedIndex == -1) { MessageBox.Show("Please choose an author."); } else { Book book = new Book() { Id = id, Title = title, Isbn = isbn, Description = descrip, Author = author, AuthorId = author.Id }; bookService.Add(book); bookService.Edit(book); } }
private void SaveBook_Btn_Click(object sender, EventArgs e) { // validerar List <string> validationList = new List <string> { AddBookISBN_textbox.Text, AddBookTitle_TextBox.Text, AddBookDescription_TextBox.Text, }; var newIsbn = AddBookISBN_textbox.Text; var newTitle = AddBookTitle_TextBox.Text; var newAuthor = AddBookAuthor_ComboBox.SelectedItem; var newDescription = AddBookDescription_TextBox.Text; var newNumberOfCopies = AddBookNumberOfCopies_drop.Value; var id = (int)BookGrid.SelectedRows[0].Cells["Id"].Value; if (CheckInput(validationList) && AddBookAuthor_ComboBox.SelectedItem != null) { var book = new Book() { Id = id, Isbn = newIsbn, Title = newTitle, Description = newDescription, Author = (Author)newAuthor, BookCopies = (int)newNumberOfCopies }; _bookService.Edit(book); ClearBookAdministration(); } }
private void BTNAddCopy_Click(object sender, EventArgs e) { int condition = Convert.ToInt32(dropDown_condition.SelectedItem); BookCopy newCopy = new BookCopy(book, condition); bookCopyService.Add(newCopy); book.BookCopies.Add(newCopy); bookService.Edit(book); this.Close(); }