Exemple #1
0
 /// <summary>
 /// Creates a new language specific promotion.
 /// </summary>
 /// <param name="promotionLanguageRow">The language specific data.</param>
 /// <param name="promotionRow">The promotion specific data.</param>
 /// <param name="campaignRow">The campaign specific data.</param>
 public Promotion(PromotionDto.PromotionLanguageRow promotionLanguageRow, PromotionDto.PromotionRow promotionRow, CampaignDto.CampaignRow campaignRow)
 {
     if (promotionLanguageRow == null)
     {
         throw new ArgumentNullException("promotionLanguageRow");
     }
     if (promotionRow == null)
     {
         throw new ArgumentNullException("promotionRow");
     }
     if (campaignRow == null)
     {
         throw new ArgumentNullException("campaignRow");
     }
     PromotionLanguageRow = promotionLanguageRow;
     PromotionRow         = promotionRow;
     CampaignRow          = campaignRow;
 }
        /// <summary>
        /// Binds the languages repeater.
        /// </summary>
        /// <returns></returns>
        private void BindPromotionLanguagesList()
        {
            DataTable sourceTable = new DataTable();

            sourceTable.Columns.AddRange(new DataColumn[] {
                new DataColumn("LanguageCode", typeof(string)),
                new DataColumn("FriendlyName", typeof(string)),
                new DataColumn("DisplayName", typeof(string))
            });

            DataTable dtLanguages = Language.GetAllLanguagesDT();

            if (_promotion != null && _promotion.PromotionLanguage.Count > 0)
            {
                //first check permissions
                //if permissions not present, deny
                SecurityManager.CheckRolePermission("marketing:promotions:mng:edit");

                foreach (DataRow row in dtLanguages.Rows)
                {
                    string langCode = row["LangName"].ToString();

                    PromotionDto.PromotionLanguageRow promoLanguageRow = null;

                    // check if record for the current language already exists in TaxLanguage table
                    PromotionDto.PromotionLanguageRow[] promoLanguageRows = (PromotionDto.PromotionLanguageRow[])_promotion.PromotionLanguage.Select(String.Format("LanguageCode='{0}'", langCode));
                    if (promoLanguageRows != null && promoLanguageRows.Length > 0)
                    {
                        promoLanguageRow = promoLanguageRows[0];
                    }
                    else
                    {
                        promoLanguageRow = _promotion.PromotionLanguage.NewPromotionLanguageRow();
                        promoLanguageRow.LanguageCode = langCode;
                        promoLanguageRow.PromotionId  = _promotion.Promotion[0].PromotionId;
                        promoLanguageRow.DisplayName  = String.Empty;
                    }

                    // add taxLanguage to the source table
                    DataRow sourceTableRow = sourceTable.NewRow();
                    sourceTableRow["LanguageCode"] = promoLanguageRow.LanguageCode;
                    sourceTableRow["FriendlyName"] = (string)row["FriendlyName"];
                    sourceTableRow["DisplayName"]  = promoLanguageRow.DisplayName;
                    sourceTable.Rows.Add(sourceTableRow);
                }
            }
            else
            {
                //first check permissions
                //if permissions not present, deny
                SecurityManager.CheckRolePermission("marketing:promotions:mng:create");

                // this is a new tax, bind empty table
                foreach (DataRow row in dtLanguages.Rows)
                {
                    string langCode = row["LangName"].ToString();

                    DataRow sourceTableRow = sourceTable.NewRow();
                    sourceTableRow["LanguageCode"] = langCode;
                    sourceTableRow["FriendlyName"] = (string)row["FriendlyName"];
                    sourceTableRow["DisplayName"]  = String.Empty;
                    sourceTable.Rows.Add(sourceTableRow);
                }
            }

            LanguagesList.DataSource = sourceTable;
            LanguagesList.DataBind();
        }
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        public void SaveChanges(IDictionary context)
        {
            PromotionDto dto = (PromotionDto)context[_PromotionDtoString];

            PromotionDto.PromotionRow row = null;

            if (dto.Promotion.Count > 0)
            {
                row            = dto.Promotion[0];
                row.Modified   = DateTime.UtcNow;
                row.ModifiedBy = Page.User.Identity.Name;
            }
            else
            {
                row = dto.Promotion.NewPromotionRow();
                row.ApplicationId = MarketingConfiguration.Instance.ApplicationId;
                row.Created       = DateTime.UtcNow;
                row.ModifiedBy    = Page.User.Identity.Name;
            }

            row.Name             = PromotionName.Text;
            row.StartDate        = this.AvailableFrom.Value.ToUniversalTime();
            row.EndDate          = this.ExpiresOn.Value.ToUniversalTime();
            row.Priority         = Int32.Parse(Priority.Text);
            row.CouponCode       = CouponCode.Text;
            row.Status           = PromotionStatus.SelectedValue;
            row.ExclusivityType  = ExclusivityType.SelectedValue;
            row.CampaignId       = Int32.Parse(CampaignFilter.SelectedValue);
            row.ApplicationLimit = Int32.Parse(MaxTotalRedemptions.Text);
            row.CustomerLimit    = Int32.Parse(MaxCustomerRedemptions.Text);
            row.PerOrderLimit    = Int32.Parse(MaxOrderRedemptions.Text);

            if (row.RowState == DataRowState.Detached)
            {
                row.PromotionGroup = Mediachase.Commerce.Marketing.PromotionGroup.GetPromotionGroupValue(Mediachase.Commerce.Marketing.PromotionGroup.PromotionGroupKey.Entry);
                row.OfferType      = 0;
                row.OfferAmount    = 0;
                dto.Promotion.Rows.Add(row);
            }

            // save localized values
            foreach (RepeaterItem item in LanguagesList.Items)
            {
                HiddenField hfCtrl = item.FindControl("hfLangCode") as HiddenField;
                TextBox     tbCtrl = item.FindControl("tbDisplayName") as TextBox;

                if (hfCtrl != null && tbCtrl != null)
                {
                    PromotionDto.PromotionLanguageRow[] promoLanguageRows = (PromotionDto.PromotionLanguageRow[])dto.PromotionLanguage.Select(String.Format("LanguageCode='{0}'", hfCtrl.Value));
                    PromotionDto.PromotionLanguageRow   promoLanguageRow  = null;

                    if (promoLanguageRows != null && promoLanguageRows.Length > 0)
                    {
                        promoLanguageRow = promoLanguageRows[0];
                    }
                    else
                    {
                        // add a new record for the current language
                        promoLanguageRow              = dto.PromotionLanguage.NewPromotionLanguageRow();
                        promoLanguageRow.PromotionId  = row.PromotionId;
                        promoLanguageRow.LanguageCode = hfCtrl.Value;
                    }

                    promoLanguageRow.DisplayName = tbCtrl.Text;

                    if (promoLanguageRow.RowState == DataRowState.Detached)
                    {
                        dto.PromotionLanguage.Rows.Add(promoLanguageRow);
                    }
                }
            }

            Control ctrl = PromotionConfigPlaceholder.Controls[0];

            if (ctrl is IAdminTabControl)
            {
                // Find selected
                PromotionConfig selectedConfig = new PromotionConfig();
                if (_PromotionConfigs == null)
                {
                    _PromotionConfigs = LoadPromotionConfigs();
                }

                foreach (PromotionConfig config in _PromotionConfigs)
                {
                    if (config.Type == PromotionTypeList.SelectedValue)
                    {
                        selectedConfig = config;
                        break;
                    }
                }

                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic.Add(_PromotionDtoString, dto);
                dic.Add(_ConfigString, selectedConfig);
                ((IAdminTabControl)ctrl).SaveChanges(dic);
            }
        }