コード例 #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
                }
            }
        }
コード例 #2
0
        // CUSTOMER METHODS
        public static int UpdateCustomer(Customer customer)
        {
            // Transaction to perform 4 inter-related data inserts on multiple database tables
            using (TransactionScope scope = new TransactionScope())
            {
                int returnValue = 1;

                // Write PERSON record to database
                BusinessObjects _personBusinessObject = new BusinessObjects();
                returnValue = _personBusinessObject.UpdatePersonFromCustomer(customer);
                if (returnValue == 1)
                {   // If insert fails, rollback transaction & display error message
                    scope.Dispose();
                    ApplicationObjects.DisplayDataStatus(returnValue);
                    return(1);
                }

                // Write MAILING ADDRESS record to database
                BusinessObjects _mailingAddressBusinessObject = new BusinessObjects();
                returnValue = _mailingAddressBusinessObject.UpdateAddress(customer.MailingAddress);
                if (returnValue == 1)
                {   // If insert fails, rollback transaction & display error message
                    scope.Dispose();
                    ApplicationObjects.DisplayDataStatus(returnValue);
                    return(1);
                }

                // Write BILLING ADDRESS record to database
                BusinessObjects _billingAddressBusinessObject = new BusinessObjects();
                returnValue = _billingAddressBusinessObject.UpdateAddress(customer.BillingAddress);
                if (returnValue == 1)
                {   // If insert fails, rollback transaction & display error message
                    scope.Dispose();
                    ApplicationObjects.DisplayDataStatus(returnValue);
                    return(1);
                }

                // Committ data transaction & display success message
                scope.Complete();
                ApplicationObjects.DisplayDataStatus(returnValue);
                return(0);
            }// End transaction
        }