コード例 #1
0
    /// <summary>
    /// Saves currently selected products to bundle.
    /// </summary>
    public void SaveProductsSelectionChanges()
    {
        string newSelection        = ValidationHelper.GetString(this.productsUniSelector.Value, null);
        string selectionDifference = null;

        // Get deselected products
        selectionDifference = DataHelper.GetNewItemsInList(newSelection, this.selectedProducts);

        // Remove deselected products
        if (!String.IsNullOrEmpty(selectionDifference))
        {
            string[] items = selectionDifference.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (items != null)
            {
                // Remove products from bundle
                foreach (string item in items)
                {
                    int skuId = ValidationHelper.GetInteger(item, 0);
                    BundleInfoProvider.RemoveSKUFromBundle(this.BundleID, skuId);
                }
            }
        }

        // Get newly selected products
        selectionDifference = DataHelper.GetNewItemsInList(this.selectedProducts, newSelection);

        // Add newly selected products
        if (!String.IsNullOrEmpty(selectionDifference))
        {
            string[] items = selectionDifference.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (items != null)
            {
                // Add products to bundle
                foreach (string item in items)
                {
                    int skuId = ValidationHelper.GetInteger(item, 0);
                    BundleInfoProvider.AddSKUToBundle(this.BundleID, skuId);
                }
            }
        }

        if (this.OnProductsSelectionChangesSaved != null)
        {
            this.OnProductsSelectionChangesSaved(this, EventArgs.Empty);
        }
    }
コード例 #2
0
    /// <summary>
    /// Saves the currently selected bundle items to the database.
    /// </summary>
    public void SaveSelectionChanges()
    {
        var savedItems = GetSavedItemIds();

        var addedItems = DiffItemIds(savedItems, Items);

        foreach (var id in addedItems)
        {
            BundleInfoProvider.AddSKUToBundle(SKUID, id);
        }

        var removedItems = DiffItemIds(Items, savedItems);

        foreach (var id in removedItems)
        {
            BundleInfoProvider.RemoveSKUFromBundle(SKUID, id);
        }
    }