/// <summary> /// Checks if the input in condition is a number and if true, creates a new bookcopy. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddCopy_Click(object sender, EventArgs e) { int id = copyService.GenerateId(); int x; bool convertSuccess = int.TryParse(txtCondition.Text, out x); Book book = lbOfBooks.SelectedItem as Book; if (convertSuccess && lbOfBooks.SelectedIndex != -1) { if (1 <= x && x <= 10) { BookCopy copy = new BookCopy { Id = id, Condition = x, Book = book, BookId = book.Id }; copyService.Add(copy); copyService.Edit(copy); } else { MessageBox.Show("Invalid input, condition was not a number within the specified limit"); } } else { MessageBox.Show("Invalid input"); } }