public void CreateOrder(Order header, OrderDetail[] details) { using (var transaction = DbContext.Database.BeginTransaction()) { try { SalesRepository.AddOrder(header); foreach (var detail in details) { detail.OrderID = header.OrderID; SalesRepository.AddOrderDetail(detail); var productInventory = new ProductInventory { ProductID = detail.ProductID, EntryDate = DateTime.Now, Quantity = detail.Quantity }; ProductionRepository.AddProductInventory(productInventory); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }