예제 #1
0
        public static void RemoveOrderItemsFromInventory(Order order)
        {
            BusinessObjects _businessObjects = new BusinessObjects();

            using (TransactionScope scope = new TransactionScope())
            {
                int returnValue = 1;
                foreach (OrderItem orderItem in order.ItemList)
                {
                    //Get list of items in the inventory that match the catalog id and are on hold by this order
                    List <InventoryItem> inventoryList = (List <InventoryItem>)ApplicationObjects.GetInventoryItemByCatalogItemId(orderItem.CatalogItem
                                                                                                                                  ).Where(o => o.OrderId == order.OrderId);

                    returnValue = _businessObjects.DeleteInventoryItems(inventoryList);
                    if (returnValue == 1)
                    {
                        scope.Dispose(); //kick transactionscope thus rolling back transaction.
                        break;
                    }
                }

                if (returnValue == 0)
                {
                    scope.Complete(); //commit transaction
                }
            }
        }