Adding campaign action from docs example

[Question (in english) - remember to come back and check the answer that solves your question to mark it as resolved, formatting of messages with markdown]

Litium version: [Version number]

Hi,

I’ trying to add the campaign action in the exsample from docs Creating a custom action
but I cant get the ascx to work,
ReducePriceByAmountActionControl.ascx.cs
cant find the entities declared in
ReducePriceByAmountActionControl.ascx
since the ReducePriceByAmountActionControl.ascx.designer.cs
isn’t populated.

Is there a quickfix or will I have to rebuild the page?

br,
//Jennifer

Try deleting the designer.cs file, then selecting the ascx file and selecting Project > Convert to Web application

thanks,
But new problem, The add button for products, lists etc doesn’t work, any ideas?

Working with Litium 7.4.2

Try updating the control to

<%@ Control Language="C#" AutoEventWireup="True"
    Inherits="Web.Site.ECommerce.Campaigns.KC.ReducePriceByAmountActionControl" Codebehind="ReducePriceByAmountActionControl.ascx.cs" %>
<div style="float:left; margin-right: 25px;">
    <div>
        <div class="litBoldHeader">
            <Foundation:ModuleString ID="ModuleStringDiscountAmount" Name="ReducePriceByAmountActionAmount" runat="server" />
            <img src="~/LitiumStudio/ECommerce/Images/transparent.gif" runat="server" id="Img3"
                style="vertical-align: middle;" class="litIconRequired" alt="" />
        </div>
        <div>
            <div style="display: inline;">
                <asp:TextBox ID="c_textboxAmount" runat="server" Width="200" />&nbsp;
            </div>
            <div style="display: inline; margin-left: 10px;">
                <asp:CheckBox CssClass="litInputCheckbox" ID="c_applyOnCampaignCheckbox" runat="server" />
                <asp:Label ID="Label1" AssociatedControlID="c_applyOnCampaignCheckbox" runat="server">
                    <Foundation:ModuleString ID="ModuleStringApplyOnCampaignPrice" Name="ApplyOnCampaignPrice" runat="server" />
                </asp:Label>
            </div>
        </div>
        <div class="litBoldHeader">
            <Foundation:ModuleString ID="ModuleStringMaxDiscountsPerItemInOrder" Name="MaxDiscountsPerItemInOrder" runat="server" />            
        </div>
        <div>
            <div style="display: inline;">
                <asp:TextBox ID="c_textboxMaxDiscountsPerItemInOrder" runat="server" Width="200" />&nbsp;
            </div>            
        </div>
        <div>
            <asp:RequiredFieldValidator Display="Dynamic" ID="c_percentageRequiredValidator"
                ValidationGroup="addCampaign" ControlToValidate="c_textboxAmount" runat="server"
                ErrorMessage="*" />
            <asp:RegularExpressionValidator ID="c_percentageRegexValidator" ControlToValidate="c_textboxAmount"
                ValidationGroup="addCampaign" runat="server" ValidationExpression="^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$"
                ErrorMessage="*" />
        </div>
    </div>
    <div class="litBoldHeader" style="width: 450px;">
        <div style="float: left;" class="lsCampaignActionReducePriceByAPercentage">
            <asp:RadioButtonList RepeatDirection="Vertical" runat="server" RepeatColumns="4"
                AutoPostBack="true" ID="c_selectionRadiobuttonlist" OnSelectedIndexChanged="OnDialogSelectionSelectedIndexChanged">
            </asp:RadioButtonList>
        </div>
        <div style="float: right;">
            <asp:LinkButton CssClass="litIconPopUp litContentPager" runat="server" Style="float: right;
                font-size: 100%;" ID="c_buttonAdd"><foundation:ModuleString runat="server" Name="ButtonAdd"/></asp:LinkButton></div>
    </div>
    <div id="c_articlesDiv" runat="server">
        <div style="clear: both;">
        </div>
        <LS:GridHelperAjax runat="server" ID="m_articlesHelper" AssociatedControlID="c_articlesGrid"
            OnNeedData="ArticleRadGridGetData" DataKeyName="ID" PageSize="5" AllowSorting="true" />
        <Telerik:RadGrid ID="c_articlesGrid" CssClass="ArticleGrid" runat="server" Style="height: 168px;
            width: 450px; border: solid 1px #CFCDCC;" OnPageIndexChanged="GridPageIndexChanged" AllowMultiRowSelection="true" OnItemCommand="GridItemCommand">
            <MasterTableView runat="server" ClientDataKeyNames="ID" CssClass="AutoShrink">
                <Columns>
                    <Telerik:GridBoundColumn DataField="ID" Display="false" />
                    <Telerik:GridBoundColumn DataField="DisplayName" />
                    <Telerik:GridBoundColumn DataField="ArticleNumber" />
                    <Telerik:GridButtonColumn CommandName="Delete" CommandArgument="ID" ImageUrl="/Litium/Images/svg/times.svg"
                        ButtonType="ImageButton" UniqueName="DeleteColumn">
                        <HeaderStyle Width="27px" />
                    </Telerik:GridButtonColumn>
                </Columns>
            </MasterTableView>
        </Telerik:RadGrid>
    </div>
    <div id="c_productGroupDiv" runat="server">
        <div style="clear: both;">
        </div>
        <LS:GridHelperAjax runat="server" ID="m_productGroupHelper" AssociatedControlID="c_productGroupsGrid"
            OnNeedData="ProductGroupsGridGetData" DataKeyName="ID" PageSize="5" AllowSorting="true" />
        <Telerik:RadGrid ID="c_productGroupsGrid" CssClass="ArticleGrid" runat="server" Style="height: 168px;
            width: 450px; border: solid 1px #CFCDCC;" OnPageIndexChanged="GridPageIndexChanged" AllowMultiRowSelection="true" OnItemCommand="GridItemCommand">
            <MasterTableView runat="server" ClientDataKeyNames="ID" CssClass="AutoShrink">
                <Columns>
                    <Telerik:GridBoundColumn DataField="ID" Display="false" />
                    <Telerik:GridBoundColumn DataField="DisplayName" />
                    <Telerik:GridBoundColumn DataField="Location" />
                    <Telerik:GridButtonColumn CommandName="Delete" CommandArgument="ID" ImageUrl="/Litium/Images/svg/times.svg"
                        ButtonType="ImageButton" UniqueName="DeleteColumn">
                        <HeaderStyle Width="27px" />
                    </Telerik:GridButtonColumn>
                </Columns>
            </MasterTableView>
        </Telerik:RadGrid>
    </div>
    <div id="c_assortmentDiv" runat="server">
        <div style="clear: both;">
        </div>
        <LS:GridHelperAjax runat="server" ID="c_assortmentGridHelper" AssociatedControlID="c_assortmentGrid"
            OnNeedData="AssortmentGridGetData" DataKeyName="ID" PageSize="5" AllowSorting="true" />
        <Telerik:RadGrid ID="c_assortmentGrid" CssClass="ArticleGrid" runat="server" Style="height: 168px;
            width: 450px; border: solid 1px #CFCDCC;" OnPageIndexChanged="GridPageIndexChanged" AllowMultiRowSelection="true" OnItemCommand="GridItemCommand">
            <MasterTableView runat="server" ClientDataKeyNames="ID" CssClass="AutoShrink">
                <Columns>
                    <Telerik:GridBoundColumn DataField="ID" Display="false" />
                    <Telerik:GridBoundColumn DataField="DisplayName" />
                    <Telerik:GridButtonColumn CommandName="Delete" CommandArgument="ID" ImageUrl="/Litium/Images/svg/times.svg"
                        ButtonType="ImageButton" UniqueName="DeleteColumn">
                        <HeaderStyle Width="27px" />
                    </Telerik:GridButtonColumn>
                </Columns>
            </MasterTableView>
        </Telerik:RadGrid>
    </div>
    <div id="c_productSetDiv" runat="server">
        <div style="clear: both;">
        </div>
        <LS:GridHelperAjax runat="server" ID="m_productSetsHelper" AssociatedControlID="c_productSetsGrid"
            OnNeedData="ProductSetsGridGetData" DataKeyName="ID" PageSize="5" AllowSorting="true" />
        <Telerik:RadGrid ID="c_productSetsGrid" CssClass="ArticleGrid" runat="server" Style="height: 168px;
            width: 450px; border: solid 1px #CFCDCC;" OnPageIndexChanged="GridPageIndexChanged" AllowMultiRowSelection="true" OnItemCommand="GridItemCommand">
            <MasterTableView runat="server" ClientDataKeyNames="ID" CssClass="AutoShrink">
                <Columns>
                    <Telerik:GridBoundColumn DataField="ID" Display="false" />
                    <Telerik:GridBoundColumn DataField="DisplayName" />
                    <Telerik:GridBoundColumn DataField="Assortment" />
                    <Telerik:GridButtonColumn CommandName="Delete" CommandArgument="ID" ImageUrl="/Litium/Images/svg/times.svg"
                        ButtonType="ImageButton" UniqueName="DeleteColumn">
                        <HeaderStyle Width="27px" />
                    </Telerik:GridButtonColumn>
                </Columns>
            </MasterTableView>
        </Telerik:RadGrid>
    </div>
</div>
<div style="float: left;">
        <div class="litBoldHeader">
            <Foundation:ModuleString ID="ModuleString3" Name="CampaignDescription" runat="server" />
            <img src="~/Litium/ECommerce/Images/transparent.gif" visible="false" runat="server"
                id="Img4" style="vertical-align: middle;" class="litIconRequired" alt="" /></div>
        <div class="litText" style="width: 280px;">
            <asp:Label ID="c_labelDescription" runat="server"></asp:Label>
        </div>
    </div>
    <div class="clearer" />
<asp:HiddenField runat="server" ID="c_hiddenFieldIDs" />

And the code-behind to:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using Litium;
using Litium.Foundation.Modules.ECommerce.Plugins.Campaigns;
using Litium.Foundation.Modules.ExtensionMethods;
using Litium.Foundation.Modules.ProductCatalog;
using Litium.Products;
using Litium.Studio.KC.Samples.Campaigns;
using Litium.Studio.UI.Common;
using Litium.Studio.UI.Common.Carriers;
using Litium.Studio.UI.ECommerce.Common;
using Litium.Studio.UI.ECommerce.Common.Constants;
using Litium.Web.Administration.FieldFramework;
using Telerik.Web.UI;
using SystemStringConstants = Litium.Foundation.GUI.Constants.SystemStringConstants;

namespace Web.Site.ECommerce.Campaigns.KC
{
    public partial class ReducePriceByAmountActionControl : UserBaseControl, IUIExtensionPanel
    {
        #region Control State

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Page.RegisterRequiresControlState(this);
            Controls.Add(LoadControl("~/Litium/ECommerce/WebUserControls/ProductCatalogDialog.ascx")); //
        }

        protected override object SaveControlState()
        {
            return _data;
        }

        protected override void LoadControlState(object state)
        {
            if (state != null)
            {
                _data = state as ReducePriceByAmountAction.Data;
            }
        }

        #endregion Control State

        #region Constants

        protected static class DialogType
        {
            public const string SELECT_ARTICLE = "7";
            public const string SELECT_ASSORTMENT = "3";
            public const string SELECT_PRODUCT_GROUP = "4";
            public const string SELECT_PRODUCT_SET = "5";
        }

        /// <summary>
        /// DataField name of display name column.
        /// </summary>
        private const string DISPLAY_NAME_COLUMN = "DisplayName";

        /// <summary>
        /// DataField name of article number column.
        /// </summary>
        private const string ARTICLE_NUMBER_COLUMN = "ArticleNumber";

        /// <summary>
        /// DataField name of location column.
        /// </summary>
        private const string LOCATION_COLUMN = "Location";

        /// <summary>
        /// DataField name of assortment column.
        /// </summary>
        private const string ASSORTMENT_COLUMN = "Assortment";

        private readonly Guid PROPERTY_ID = new Guid("61B3AB55-3B97-4B48-820C-E69C981ACB54");

        private CategoryService _categoryService = IoC.Resolve<CategoryService>();
        private AssortmentService _assortmentService = IoC.Resolve<AssortmentService>();
        #endregion

        #region Property

        ReducePriceByAmountAction.Data Data {
            set {
                _data = value;
            }
            get {
                if (_data == null)
                    return _data = new ReducePriceByAmountAction.Data { SelectedIDs = new List<Guid>(), SelectedIdType = ReducePriceByAmountAction.Data.SelectionCriteria.Articles, MaxDiscountsPerItemInOrder = -1 };
                return _data;
            }
        }

        private ReducePriceByAmountAction.Data _data;

        private Hashtable SelectedItemIds {
            set {
                Session[ProductCatalogItemCarrier.SESSION_KEY_SELECTED_ITEMS] = value;
                Session[ProductCatalogItemCarrier.SESSION_KEY_SELECTED_EXTRA_ITEMS] = value;
            }
        }

        private string CampaignSelectedWebSite {
            get {
                string result = string.Empty;
                if (Session[SessionConstants.ECOM_CAMPAIGNS_SELECTED_WEBSITE] != null)
                {
                    result = Session[SessionConstants.ECOM_CAMPAIGNS_SELECTED_WEBSITE] as string;
                }
                return result;
            }
        }

        #endregion Property

        #region Private Metods

        /// <summary>
        /// Initializes the validation on page.
        /// </summary>
        private void InitializeValidation()
        {
            c_percentageRegexValidator.CssClass = ParameterConstants.VALIDATOR_STYLE_NAME;
            c_percentageRegexValidator.Text = String.Format("{0} {1}", ParameterConstants.VALIDATOR_IMAGE,
                SystemStrings.GetValue(SystemStringConstants.VALIDATION_MESSAGE_INVALID_INPUT,
                    FoundationContext.LanguageID, true));

            string requiredMessage = String.Format("{0} {1}", ParameterConstants.VALIDATOR_IMAGE,
                SystemStrings.GetValue(SystemStringConstants.VALIDATION_MESSAGE_REQUIRED_FIELD,
                    FoundationContext.LanguageID, true));

            c_percentageRequiredValidator.CssClass = ParameterConstants.VALIDATOR_STYLE_NAME;
            c_percentageRequiredValidator.Text = requiredMessage;
        }

        /// <summary>
        /// Initialize description of the action.
        /// </summary>
        private void InitializeDescription()
        {
            string description = CurrentModule.Strings.GetValue("ReducePriceByAmountActionDescriptionGeneral",
                                                                FoundationContext.LanguageID, true);
            string selectedType = string.Empty;
            switch (Data.SelectedIdType)
            {
                case ReducePriceByAmountAction.Data.SelectionCriteria.Assortments:
                    selectedType = CurrentModule.Strings.GetValue("CampaignAssortments", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
                    break;
                case ReducePriceByAmountAction.Data.SelectionCriteria.ProductGroups:
                    selectedType = CurrentModule.Strings.GetValue("CampaignProductGroups", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
                    break;
                case ReducePriceByAmountAction.Data.SelectionCriteria.ProductSets:
                    selectedType = CurrentModule.Strings.GetValue("CampaignProductSets", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
                    break;
                default:
                    selectedType = CurrentModule.Strings.GetValue("CampaignProducts", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
                    break;
            }

            c_labelDescription.Text = string.Format(description, selectedType);
        }

        /// <summary>
        /// Initializes the grids columns.
        /// </summary>
        private void InitializeGridsColumns()
        {
            ModuleProductCatalog pcModule = ModuleProductCatalog.Instance;

            string columnName = FoundationContext.SystemStrings.GetValue("Name", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            if (!string.IsNullOrEmpty(columnName))
                c_articlesGrid.MasterTableView.Columns.FindByDataField(DISPLAY_NAME_COLUMN).HeaderText = columnName;

            columnName = pcModule.Strings.GetValue("ArticleNumber", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            if (!string.IsNullOrEmpty(columnName))
                c_articlesGrid.MasterTableView.Columns.FindByDataField(ARTICLE_NUMBER_COLUMN).HeaderText = columnName;

            columnName = pcModule.Strings.GetValue("Name", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            if (!string.IsNullOrEmpty(columnName))
                c_productGroupsGrid.MasterTableView.Columns.FindByDataField(DISPLAY_NAME_COLUMN).HeaderText = columnName;

            columnName = pcModule.Strings.GetValue("Location", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            if (!string.IsNullOrEmpty(columnName))
                c_productGroupsGrid.MasterTableView.Columns.FindByDataField(LOCATION_COLUMN).HeaderText = columnName;

            columnName = pcModule.Strings.GetValue("Name", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            if (!string.IsNullOrEmpty(columnName))
                c_assortmentGrid.MasterTableView.Columns.FindByDataField(DISPLAY_NAME_COLUMN).HeaderText = columnName;

            columnName = pcModule.Strings.GetValue("Name", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            if (!string.IsNullOrEmpty(columnName))
                c_productSetsGrid.MasterTableView.Columns.FindByDataField(DISPLAY_NAME_COLUMN).HeaderText = columnName;

            columnName = pcModule.Strings.GetValue("Location", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            if (!string.IsNullOrEmpty(columnName))
                c_productSetsGrid.MasterTableView.Columns.FindByDataField(ASSORTMENT_COLUMN).HeaderText = columnName;
        }

        /// <summary>
        /// Initializes the popup window dialog.
        /// </summary>
        private void InitializePopupWindowsDialog()
        {
            HideGrids();
            String gridClientId = ConfigureGrids();

            if (ModuleProductCatalog.ExistsInstance)
            {
                c_buttonAdd.Attributes.Add(ParameterConstants.JAVASCRIPT_ON_CLICK,
                                                                String.Format("OpenSelectFromProductCatalogGridResult('', '{0}', '', '{1}', '1', '0', '', '', '{2}','','{3}','{4}'); return false;",
                                                                              c_hiddenFieldIDs.ClientID, c_selectionRadiobuttonlist.SelectedValue, gridClientId, PROPERTY_ID, CampaignSelectedWebSite));
            }
            else
            {
                c_buttonAdd.Visible = false;
            }
        }

        /// <summary>
        /// Initializes the radio button list control.
        /// </summary>
        private void InitializeRadioButtonListControl()
        {
            c_selectionRadiobuttonlist.Items.Clear();

            var item = new ListItem();
            item.Value = DialogType.SELECT_ARTICLE;
            item.Text = CurrentModule.Strings.GetValue("CampaignProducts", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            c_selectionRadiobuttonlist.Items.Add(item);

            item = new ListItem();
            item.Value = DialogType.SELECT_PRODUCT_GROUP;
            item.Text = CurrentModule.Strings.GetValue("CampaignProductGroups", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            c_selectionRadiobuttonlist.Items.Add(item);

            item = new ListItem();
            item.Value = DialogType.SELECT_ASSORTMENT;
            item.Text = CurrentModule.Strings.GetValue("CampaignAssortments", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            c_selectionRadiobuttonlist.Items.Add(item);

            item = new ListItem();
            item.Value = DialogType.SELECT_PRODUCT_SET;
            item.Text = CurrentModule.Strings.GetValue("CampaignProductSets", FoundationContext.LanguageID, true).Replace(" ", "&nbsp;");
            c_selectionRadiobuttonlist.Items.Add(item);

            switch (Data.SelectedIdType)
            {
                case ReducePriceByAmountAction.Data.SelectionCriteria.Assortments:
                    c_selectionRadiobuttonlist.Items.FindByValue(DialogType.SELECT_ASSORTMENT).Selected = true;
                    break;
                case ReducePriceByAmountAction.Data.SelectionCriteria.ProductGroups:
                    c_selectionRadiobuttonlist.Items.FindByValue(DialogType.SELECT_PRODUCT_GROUP).Selected = true;
                    break;
                case ReducePriceByAmountAction.Data.SelectionCriteria.ProductSets:
                    c_selectionRadiobuttonlist.Items.FindByValue(DialogType.SELECT_PRODUCT_SET).Selected = true;
                    break;
                default:
                    c_selectionRadiobuttonlist.Items.FindByValue(DialogType.SELECT_ARTICLE).Selected = true;
                    break;
            }
        }

        /// <summary>
        /// Configures the grids on page.
        /// </summary>
        /// <param name="selectedIdType">Type of the selection criteria.</param>
        /// <returns>Grid client ID and popup dialog type</returns>
        private string ConfigureGrids()
        {
            switch (c_selectionRadiobuttonlist.SelectedValue)
            {
                case DialogType.SELECT_PRODUCT_SET:
                    {
                        Data.SelectedIdType = ReducePriceByAmountAction.Data.SelectionCriteria.ProductSets;
                        c_productSetDiv.Attributes.CssStyle.Add("display", "block");
                        return c_productSetsGrid.ClientID;
                    }
                case DialogType.SELECT_ASSORTMENT:
                    {
                        Data.SelectedIdType = ReducePriceByAmountAction.Data.SelectionCriteria.Assortments;
                        c_assortmentDiv.Attributes.CssStyle.Add("display", "block");
                        return c_assortmentGrid.ClientID;
                    }
                case DialogType.SELECT_PRODUCT_GROUP:
                    {
                        Data.SelectedIdType = ReducePriceByAmountAction.Data.SelectionCriteria.ProductGroups;
                        c_productGroupDiv.Attributes.CssStyle.Add("display", "block");
                        return c_productGroupsGrid.ClientID;
                    }
                default:
                    {
                        Data.SelectedIdType = ReducePriceByAmountAction.Data.SelectionCriteria.Articles;
                        c_articlesDiv.Attributes.CssStyle.Add("display", "block");
                        return c_articlesGrid.ClientID;
                    }
            }
        }

        /// <summary>
        /// Hides the grids div.
        /// </summary>
        private void HideGrids()
        {
            c_articlesDiv.Attributes.CssStyle.Add("display", "none");
            c_productGroupDiv.Attributes.CssStyle.Add("display", "none");
            c_assortmentDiv.Attributes.CssStyle.Add("display", "none");
            c_productSetDiv.Attributes.CssStyle.Add("display", "none");
        }

        /// <summary>
        /// Rebinds (clearing) the grids when Selection type is changed.
        /// </summary>
        private void RebindGrids()
        {
            Data.SelectedIDs.Clear();
            if (c_selectionRadiobuttonlist.SelectedValue == DialogType.SELECT_ASSORTMENT)
                c_assortmentGrid.Rebind();
            if (c_selectionRadiobuttonlist.SelectedValue == DialogType.SELECT_PRODUCT_GROUP)
                c_productGroupsGrid.Rebind();
            if (c_selectionRadiobuttonlist.SelectedValue == DialogType.SELECT_PRODUCT_SET)
                c_productSetsGrid.Rebind();
            if (c_selectionRadiobuttonlist.SelectedValue == DialogType.SELECT_ARTICLE)
                c_articlesGrid.Rebind();
        }

        /// <summary>
        /// Processing the hidden field.
        /// Retrieve data from hidden field and setting them to Data object.
        /// </summary>
        private void ProcessingHiddenField()
        {
            var selectedIDs = new List<Guid>(GetGuidValueList(c_hiddenFieldIDs.Value));

            if (selectedIDs.Count != 0)
            {
                Data.SelectedIDs.Clear();
                Data.SelectedIDs.AddRange(selectedIDs.Distinct().ToList());

                var hashtable = new Hashtable { { PROPERTY_ID, selectedIDs } };
                SelectedItemIds = hashtable;
            }
            else
            {
                SelectedItemIds = null;
            }
        }

        /// <summary>
        /// Sorting ProductsSet collection.
        /// </summary>
        /// <param name="productSets">The product sets.</param>
        /// <param name="sortexpressions">The sort expressions.</param>
        /// <returns>Sorted collection.</returns>
        private List<ProductList> ProductSetSorting(List<ProductList> productSets, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
        {
            switch (sortexpressions[0].FieldName)
            {
                case DISPLAY_NAME_COLUMN:
                    productSets.Sort((a, b) => string.Compare(a.GetEntityName(), b.GetEntityName()));
                    break;
            }

            if (sortexpressions[0].SortDirection == SortDirection.Descending)
                productSets.Reverse();

            return productSets;
        }

        /// <summary>
        /// Sorting Assortment collection.
        /// </summary>
        /// <param name="assortments">The assortment collection.</param>
        /// <param name="sortexpressions">The sort expressions.</param>
        /// <returns> Sorted collection. </returns>
        private List<Assortment> AssortmenSorting(List<Assortment> assortments, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
        {
            switch (sortexpressions[0].FieldName)
            {
                case DISPLAY_NAME_COLUMN:
                    assortments.Sort((a, b) => string.Compare(a.GetEntityName(), b.GetEntityName()));
                    break;
            }

            if (sortexpressions[0].SortDirection == SortDirection.Descending)
                assortments.Reverse();

            return assortments;
        }

        /// <summary>
        /// Sorting for ProductGroup collection.
        /// </summary>
        /// <param name="productGroups">The product groups.</param>
        /// <param name="sortexpressions">The sort expressions.</param>
        /// <returns>Sorted collection.</returns>
        private List<Category> ProductGroupSorting(List<Category> productGroups, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
        {
            switch (sortexpressions[0].FieldName)
            {
                case DISPLAY_NAME_COLUMN:
                    productGroups.Sort((a, b) => string.Compare(a.GetEntityName(), b.GetEntityName()));
                    break;
                case ASSORTMENT_COLUMN:
                    productGroups.Sort((a, b) => string.Compare(a.GetEntityName(), b.GetEntityName()));
                    break;
            }

            if (sortexpressions[0].SortDirection == SortDirection.Descending)
                productGroups.Reverse();

            return productGroups;
        }

        /// <summary>
        /// Sorting Articles collection.
        /// </summary>
        /// <param name="articles">The articles.</param>
        /// <param name="sortexpressions">The sort expressions.</param>
        /// <returns>Sorted collection.</returns>
        private List<Variant> ArticleSorting(List<Variant> articles, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
        {
            switch (sortexpressions[0].FieldName)
            {
                case DISPLAY_NAME_COLUMN:
                    articles.Sort((a, b) => string.Compare(a.GetEntityName(), b.GetEntityName()));
                    break;
                case ARTICLE_NUMBER_COLUMN:
                    articles.Sort((a, b) => a.Id.CompareTo(b.Id));
                    break;
            }

            if (sortexpressions[0].SortDirection == SortDirection.Descending)
                articles.Reverse();

            return articles;
        }

        #endregion Private Metods

        #region Protected Methods

        protected override void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitializePageControls();
            }
        }

        /// <summary>
        /// Initializes the page controls.
        /// </summary>
        private void InitializePageControls()
        {
            InitializeRadioButtonListControl();
            InitializeValidation();
            InitializeGridsColumns();
            InitializePopupWindowsDialog();
            InitializeDescription();
        }

        /// <summary>
        /// Articles the RAD grid getting data.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="startrowindex">The start row index.</param>
        /// <param name="pagesize">The page size.</param>
        /// <param name="sortexpressions">The sort expressions.</param>
        /// <returns>PageResult object.</returns>
        protected PagedResult ArticleRadGridGetData(object sender, int startrowindex, int pagesize, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
        {
            ProcessingHiddenField();
            var articlesCollection = new List<Variant>();

            if (Data.SelectedIDs.Count > 0)
            {
                var variantService = IoC.Resolve<VariantService>();
                foreach (Guid articleID in Data.SelectedIDs)
                {
                    var article = variantService.Get(articleID);
                    if (article != null)
                    {
                        articlesCollection.Add(article);
                    }
                }
            }

            if (sortexpressions != null && sortexpressions.Count > 0)
                articlesCollection = ArticleSorting(articlesCollection, sortexpressions);

            return new PagedResult
            {
                Count = articlesCollection.Count,
                Data = articlesCollection.Select(x => new { ID = x.SystemId, DisplayName = x.GetEntityName(), ArticleNumber = x.Id }).ToList(),
                Reset = pagesize > startrowindex
            };
        }

        /// <summary>
        /// Products groups grid get data.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="startrowindex">The start row index.</param>
        /// <param name="pagesize">The page size.</param>
        /// <param name="sortexpressions">The sort expressions.</param>
        /// <returns>PageResult object.</returns>
        protected PagedResult ProductGroupsGridGetData(object sender, int startrowindex, int pagesize, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
        {
            ProcessingHiddenField();
            var productGroups = new List<Category>();

            if (Data.SelectedIDs.Count > 0)
            {
                foreach (Guid id in Data.SelectedIDs)
                {
                    var item = _categoryService.Get(id);
                    if (item != null)
                        productGroups.Add(item);
                }
            }

            if (sortexpressions != null && sortexpressions.Count > 0)
                productGroups = ProductGroupSorting(productGroups, sortexpressions);

            var pageResult = new PagedResult
            {
                Count = productGroups.Count,
                Reset = pagesize > startrowindex
            };

            pageResult.Data = productGroups.Select(x =>
            new {
                ID = x.SystemId,
                DisplayName = x.GetEntityName(),
                Assortment = x.GetCategoryPath()
            }).ToList();

            return pageResult;
        }

        /// <summary>
        /// Assortment grid get data.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="startrowindex">The start row index.</param>
        /// <param name="pagesize">The page size.</param>
        /// <param name="sortexpressions">The sort expressions.</param>
        /// <returns>PageResult object.</returns>
        protected PagedResult AssortmentGridGetData(object sender, int startrowindex, int pagesize, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
        {
            ProcessingHiddenField();
            var assortments = new List<Assortment>();

            if (Data.SelectedIDs.Count > 0)
            {
                foreach (Guid id in Data.SelectedIDs)
                {
                    var item = _assortmentService.Get(id);
                    if (item != null)
                        assortments.Add(item);
                }
            }

            if (sortexpressions != null && sortexpressions.Count > 0)
                assortments = AssortmenSorting(assortments, sortexpressions);

            return new PagedResult
            {
                Count = assortments.Count,
                Reset = pagesize > startrowindex,
                Data = assortments.Select(x => new ReducePriceByPercentageResult { ID = x.SystemId, DisplayName = x.GetEntityName() }).ToList()
            };
        }

        /// <summary>
        /// ProductSet grid get data.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="startrowindex">The start row index.</param>
        /// <param name="pagesize">The page size.</param>
        /// <param name="sortexpressions">The sort expressions.</param>
        /// <returns>PageResult object.</returns>
        protected PagedResult ProductSetsGridGetData(object sender, int startrowindex, int pagesize, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
        {
            ProcessingHiddenField();
            var productSets = new List<ProductList>();

            if (Data.SelectedIDs.Count > 0)
            {
                var productSetService = IoC.Resolve<ProductListService>();

                foreach (Guid id in Data.SelectedIDs)
                {
                    var productSet = productSetService.Get<ProductList>(id);
                    if (productSet != null)
                        productSets.Add(productSet);
                }
            }

            if (sortexpressions != null && sortexpressions.Count > 0)
                productSets = ProductSetSorting(productSets, sortexpressions);

            return new PagedResult
            {
                Count = productSets.Count,
                Reset = pagesize > startrowindex,
                Data = productSets.Select(x => new 
                {
                    ID = x.SystemId,
                    DisplayName = x.GetEntityName()
                }).ToList()
            };
        }

        /// <summary>
        /// Called when GridItemCommand event raised.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="e">The <see cref="Telerik.Web.UI.GridCommandEventArgs"/> instance containing the event data.</param>
        protected void GridItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "RebindGrid")
			{
                return;
			}

            if (e.CommandName == "Delete")
            {
                Guid deletableItemID = Guid.Empty;
                switch (Data.SelectedIdType)
                {
                    case ReducePriceByAmountAction.Data.SelectionCriteria.Assortments:
                        deletableItemID = (Guid)c_assortmentGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
                        break;
                    case ReducePriceByAmountAction.Data.SelectionCriteria.ProductGroups:
                        deletableItemID = (Guid)c_productGroupsGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
                        break;
                    case ReducePriceByAmountAction.Data.SelectionCriteria.ProductSets:
                        deletableItemID = (Guid)c_productSetsGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
                        break;
                    default:
                        deletableItemID = (Guid)c_articlesGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
                        break;
                }
                if (deletableItemID != Guid.Empty)
                    Data.SelectedIDs.Remove(deletableItemID);
            }

            c_hiddenFieldIDs.Value = string.Join(",", Data.SelectedIDs.ToList().ConvertAll(x => x.ToString()).ToArray());
        }

        /// <summary>
        /// Gets the GUID value list.
        /// </summary>
        /// <param name="originalValue">The comma separated Guid-string value.</param>
        /// <returns>IEnumerable Guid collection.</returns>
        private static IEnumerable<Guid> GetGuidValueList(string originalValue)
        {
            string[] values = originalValue.Split(ParameterConstants.VALUE_SEPERATOR_COMMA);
            return (values.Where(value => !string.IsNullOrEmpty(value)).Select(value => new Guid(value))).ToList();
        }

        /// <summary>
        /// Called when [select type checked changed] event raised.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void OnDialogSelectionSelectedIndexChanged(object sender, EventArgs e)
        {
            c_hiddenFieldIDs.Value = String.Empty;
            RebindGrids();
            InitializePopupWindowsDialog();
            InitializeDescription();
            SelectedItemIds = null;
        }


        protected void GridPageIndexChanged(object source, GridPageChangedEventArgs e)
        {
            c_hiddenFieldIDs.Value = string.Join(",", Data.SelectedIDs.ToList().ConvertAll(x => x.ToString()).ToArray());
        }

        [Serializable]
        internal sealed class ReducePriceByPercentageResult
        {
            public Guid ID { get; set; }

            public string DisplayName { get; set; }

            public string ArticleNumber { get; set; }
        }

        #endregion Protected Methods

        #region Implementation of IUIExtensionPanel

        /// <summary>
        /// Gets the panel data.
        /// </summary>
        /// <returns>Return an object with the panel data.</returns>
        object IUIExtensionPanel.GetPanelData()
        {
            decimal amount;
            Data.ApplyOnCampaignPriceCumulatively = c_applyOnCampaignCheckbox.Checked;
            decimal.TryParse(c_textboxAmount.Text, out amount);
            Data.DiscountAmountWithVAT = amount;
            int maxDiscountsPerItemInOrder;
            if (int.TryParse(c_textboxMaxDiscountsPerItemInOrder.Text, out maxDiscountsPerItemInOrder))
                Data.MaxDiscountsPerItemInOrder = maxDiscountsPerItemInOrder;
            else
                Data.MaxDiscountsPerItemInOrder = -1;
            return Data;
        }

        /// <summary>
        /// Sets the panel data.
        /// </summary>
        /// <param name="data">The data.</param>
        void IUIExtensionPanel.SetPanelData(object data)
        {
            if (data is ReducePriceByAmountAction.Data)
                Data = (ReducePriceByAmountAction.Data)data;

            InitializePageControls();

            if (data is ReducePriceByAmountAction.Data)
            {
                c_applyOnCampaignCheckbox.Checked = Data.ApplyOnCampaignPriceCumulatively;
                c_textboxAmount.Text = Data.DiscountAmountWithVAT.ToString();
                c_textboxMaxDiscountsPerItemInOrder.Text = (Data.MaxDiscountsPerItemInOrder > 0) ? Data.MaxDiscountsPerItemInOrder.ToString() : string.Empty;
                switch (Data.SelectedIdType)
                {
                    case ReducePriceByAmountAction.Data.SelectionCriteria.Assortments:
                        c_assortmentGrid.Rebind();
                        break;
                    case ReducePriceByAmountAction.Data.SelectionCriteria.ProductGroups:
                        c_productGroupsGrid.Rebind();
                        break;
                    case ReducePriceByAmountAction.Data.SelectionCriteria.ProductSets:
                        c_productSetsGrid.Rebind();
                        break;
                    default:
                        c_articlesGrid.Rebind();
                        break;
                }
            }
        }

        #endregion
    }
}```

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.