private void RemoveInvoice_Click(object sender, RoutedEventArgs e) { if (invoicesDataGrid.SelectedItem is Invoice s) { using (var db = new db.InvoiceDbContext()) { db.Invoices.Remove(db.Invoices.Single(x => x.Id == s.Id)); db.SaveChanges(); invoicesDataGrid.ItemsSource = db.Invoices.ToList(); } } invoicesDataGrid.Items.Refresh(); }
private void AddInvoice_Click(object sender, RoutedEventArgs e) { var dialog = new InvoiceWindow(); if (dialog.ShowDialog() == true) { using (var db = new db.InvoiceDbContext()) { db.Invoices.Add(dialog.inv); db.SaveChanges(); var dd = db.Invoices.ToList(); invoicesDataGrid.ItemsSource = db.Invoices.ToList(); } } }
private void EditInvoice_Click(object sender, RoutedEventArgs e) { if (invoicesDataGrid.SelectedItem is Invoice s) { using (var db = new db.InvoiceDbContext()) { var inv = db.Invoices.Include("Items").Single(x => x.Id == s.Id); var dialog = new InvoiceWindow(inv); if (dialog.ShowDialog() == true) { //db.Invoices.Include("items").ToList()[db.Invoices.Include("items").ToList().FindIndex(x => x.Id == s.Id)] = dialog.inv; db.SaveChanges(); invoicesDataGrid.ItemsSource = db.Invoices.ToList(); } } } }