private void Button_Add(object sender, RoutedEventArgs e) { int ISBN = Convert.ToInt32(tb_ISBN.Text.ToString()); string Titel = tb_Titel.Text.ToString(); int Author_ID = cb_Author.selectedIndex; int Verlage_ID = cb_Publishing.selectedIndex; int Pages = Convert.ToInt32(tb_pages.Text.ToString()); string purchaseDate = tb_purchaseDate.Text.ToString();; decimal price = Convert.ToDecimal(tb_price.Text.ToString()); int rating = Convert.ToInt32(tb_rating.Text.ToString()); int Owner_ID = cb_Owner.SelectedIndex; int Place_ID = cb_Place.SelectedIndex; int Language_ID = cb_Language.SelectedIndex; decimal weight; decimal width; decimal lenght; decimal height; weight = Convert.ToDecimal(tb_weight.Text.ToString()); width = Convert.ToDecimal(tb_width.Text.ToString()); lenght = Convert.ToDecimal(tb_lenght.Text.ToString()); height = Convert.ToDecimal(tb_height.Text.ToString()); Book b = new Book() { Isbn = ISBN, Titel = Titel, AuthorId = Author_ID, VerlagId = Verlage_ID, Pages = Pages, PurchaseDate = purchaseDate, Price = price, Rating = rating, OwnerId = Owner_ID, PlaceId = Place_ID, LanguageId = Language_ID, Weight = weight, Width = width, Lenght = lenght, Height = height }; try { db.Books.Add(b); db.SaveChanges(); loadBookList(); fillUserControlls(); } catch (InvalidOperationException exc) { MessageBox.Show("A book with this ISBN already exists in this Database, please check the ISBN again"); } }
private void Button_Click(object sender, RoutedEventArgs e) { string firstName = tb_firstName.Text.ToString(); string lastName = tb_lastName.Text.ToString(); db.Authors.Add(new Author { FirstName = firstName, LastName = lastName }); db.SaveChanges(); this.Close(); }