Exemplo n.º 1
0
        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();
                }
            }
        }
Exemplo n.º 2
0
        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();
                    }
                }
            }
        }