public void InsertInvoice(Invoice.Repository.Migrations.Invoice invoice) { using (var transaction = _context.Database.BeginTransaction()) { { repository.Insert(invoice); try { foreach (InvoiceDetails detail in invoice.InvoiceDetails) { detail.InvoiceId = invoice.Id; invDetailsService.InsertInvoiceDetail(detail); } transaction.Commit(); } catch { transaction.Rollback(); } } repository.SaveChanges(); } }