private List<SalesOrderDetail> RetrieveOrderDetail(Int32 salesOrderId) { List<SalesOrderDetail> result = new List<SalesOrderDetail>(); using (AdventureWorksDataContext dc = new AdventureWorksDataContext()) { var salesDetail = (from sd in dc.SalesOrderDetails where sd.SalesOrderID == salesOrderId select sd).ToList(); if (salesDetail != null && salesDetail.Count > 0) { result = salesDetail; } } return result; }
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(); } } }
// If your activity returns a value, derive from CodeActivity<TResult> // and return the value from the Execute method. protected override void Execute(CodeActivityContext context) { SalesOrderDetail salesDetail = SalesDetail.Get(context); using (AdventureWorksDataContext dc = new AdventureWorksDataContext()) { var historyRow = new TransactionHistory(); historyRow.ProductID = salesDetail.ProductID; historyRow.ModifiedDate = DateTime.Now; historyRow.Quantity = salesDetail.OrderQty; historyRow.TransactionDate = salesDetail.ModifiedDate; historyRow.TransactionType = 'S'; historyRow.ReferenceOrderID = salesDetail.SalesOrderID; historyRow.ReferenceOrderLineID = salesDetail.SalesOrderDetailID; dc.TransactionHistories.InsertOnSubmit(historyRow); dc.SubmitChanges(); Console.WriteLine("Product {0}: Added history for Qty of {1} ",salesDetail.ProductID, salesDetail.OrderQty); } }
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")); } } }