private void Button_Click(object sender, RoutedEventArgs e) { using (var context = new BooksAppContext()) { var autorId = ((Autor)AutorComboBox.SelectedItem).Id; var autor = context.Autores.Find(autorId); var livro = new Entidades.Livro() { Titulo = TituloTextBox.Text, Ano = AnoTextBox.Text, Autor = autor }; var livrosGeneros = new List <LivroGenero>(); foreach (var genero in _generos) { livrosGeneros.Add(new LivroGenero() { GeneroId = genero.Id, LivroId = livro.Id }); } livro.LivrosGeneros = livrosGeneros; context.Livros.Add(livro); context.SaveChanges(); ResetScreen(); MessageBox.Show("Livro salvo com sucesso!"); } }
private void CarregarGrid() { using (var context = new BooksAppContext()) { AutorDataGrid.ItemsSource = context.Autores.ToList(); } }
private void CarregarGrid() { using (var context = new BooksAppContext()) { GeneroDataGrid.ItemsSource = context.Generos.ToList(); } }
private void CarregarGrid() { using (var context = new BooksAppContext()) { var livros = context.Livros.ToList(); LivrosDataGrid.ItemsSource = livros; } }
private void Button_Click_1(object sender, RoutedEventArgs e) { using (var context = new BooksAppContext()) { var genero = context.Generos.Find(((Genero)GeneroComboBox.SelectedItem).Id); _generos.Add(genero); } GeneroDataGrid.Items.Refresh(); }
private void CarregarComboBox() { using (var context = new BooksAppContext()) { AutorComboBox.ItemsSource = context.Autores.ToList(); AutorComboBox.DisplayMemberPath = "Nome"; GeneroComboBox.ItemsSource = context.Generos.ToList(); GeneroComboBox.DisplayMemberPath = "Nome"; } }
private void Button_Click(object sender, RoutedEventArgs e) { using (var context = new BooksAppContext()) { context.Autores.Add(new Entidades.Autor() { Nome = NomeTextBox.Text }); context.SaveChanges(); CarregarGrid(); NomeTextBox.Clear(); MessageBox.Show("Autor salvo com sucesso!"); } }