private void UpdateInventory(DependentTransaction dt, SalesOrderDetail salesDetail) { try { using (AdventureWorksDataContext dc = new AdventureWorksDataContext()) { using (TransactionScope scope = (dt != null ?new TransactionScope(dt) :new TransactionScope(TransactionScopeOption.Suppress))) { var inventoryRow = (from pi in dc.ProductInventories where pi.ProductID == salesDetail.ProductID && pi.LocationID == 7 //finished goods storage select pi).SingleOrDefault(); if (inventoryRow != null) { inventoryRow.Quantity -= salesDetail.OrderQty; inventoryRow.ModifiedDate = DateTime.Now; Console.WriteLine( "Product {0}: Reduced by {1}", inventoryRow.ProductID, salesDetail.OrderQty); dc.SubmitChanges(); } scope.Complete(); } } } catch (Exception) { throw; } finally { //the ambient transaction will block on complete if (dt != null) { dt.Complete(); dt.Dispose(); } } }
private void DisplayInventory(SalesOrderDetail salesDetail, String desc) { using (AdventureWorksDataContext dc = new AdventureWorksDataContext()) { var inventoryRow =(from pi in dc.ProductInventories where pi.ProductID == salesDetail.ProductID && pi.LocationID == 7 //finished goods storage select pi).SingleOrDefault(); Boolean historyRowFound = (from th in dc.TransactionHistories where th.ProductID == salesDetail.ProductID && (DateTime.Now - th.ModifiedDate < new TimeSpan(0, 0, 3)) select th).Any(); if (inventoryRow != null) { Console.WriteLine("Product {0}: {1} - {2} - {3}", inventoryRow.ProductID, inventoryRow.Quantity, desc, (historyRowFound ? "History Row Found" : "No History")); } } }
private void detach_SalesOrderDetails(SalesOrderDetail entity) { this.SendPropertyChanging(); entity.SpecialOfferProduct = null; }
partial void DeleteSalesOrderDetail(SalesOrderDetail instance);
partial void UpdateSalesOrderDetail(SalesOrderDetail instance);
partial void InsertSalesOrderDetail(SalesOrderDetail instance);
private void detach_SalesOrderDetails(SalesOrderDetail entity) { this.SendPropertyChanging(); entity.SalesOrderHeader = null; }