/// <summary> /// Binds the form. /// </summary> private void BindForm() { if (Config != null) { Description.Text = Config.Description; } OfferAmount.Text = "0"; if (PromotionDto != null && PromotionDto.Promotion.Count != 0) { PromotionDto.PromotionRow row = PromotionDto.Promotion[0]; object settingsObj = DeseralizeSettings(typeof(Settings)); if (settingsObj != null) { Settings settings = (Settings)settingsObj; EntryXFilter.SelectedEntryCode = settings.EntryXFilter; EntryYFilter.SelectedEntryCode = settings.EntryYFilter; SourceQuantity.Text = settings.SourceQuantity.ToString(); TargetQuantity.Text = settings.TargetQuantity.ToString(); } OfferAmount.Text = PromotionDto.Promotion[0].OfferAmount.ToString("N2"); ManagementHelper.SelectListItem(OfferType, PromotionDto.Promotion[0].OfferType); } }
/// <summary> /// Binds the form. /// </summary> private void BindForm() { LoadPolicyGroups(); LoadPromotionTypes(); if (_promotion != null) { PromotionDto.PromotionRow promo = _promotion.Promotion[0]; PromotionName.Text = promo.Name; this.AvailableFrom.Value = ManagementHelper.GetUserDateTime(promo.StartDate); this.ExpiresOn.Value = ManagementHelper.GetUserDateTime(promo.EndDate); Priority.Text = promo.Priority.ToString(); CouponCode.Text = promo.CouponCode; MaxTotalRedemptions.Text = promo.ApplicationLimit.ToString(); MaxCustomerRedemptions.Text = promo.CustomerLimit.ToString(); MaxOrderRedemptions.Text = promo.PerOrderLimit.ToString(); // Get existing statistics DataTable usageStatistics = PromotionManager.GetPromotionUsageStatistics(); // Get total used int totalUsed = 0; System.Data.DataRow[] rows = usageStatistics.Select(String.Format("PromotionId = {0}", promo.PromotionId)); if (rows != null && rows.Length > 0) { totalUsed = (int)rows[0]["TotalUsed"]; } MaxTotalRedemptionsUsed.Text = totalUsed.ToString(); //OfferAmount.Text = promo.OfferAmount.ToString(); ComboBoxItem item = CampaignFilter.Items.FindByValue(promo.CampaignId.ToString()); if (item != null) { CampaignFilter.SelectedItem = item; } //CampaignFilter.SelectedIndex = 0; //ManagementHelper.SelectListItem(OfferType, promo.OfferType); //ManagementHelper.SelectListItem(PromotionGroupsList, promo.PromotionGroup); ManagementHelper.SelectListItem(ExclusivityType, promo.ExclusivityType); ManagementHelper.SelectListItem(PromotionStatus, promo.Status); ManagementHelper.SelectListItem(PromotionTypeList, promo.PromotionType); PromotionTypeList.Enabled = false; } else { ManagementHelper.SelectListItem(PromotionTypeList, Request.QueryString["type"]); PromotionTypeList.Enabled = true; this.AvailableFrom.Value = ManagementHelper.GetUserDateTimeNow(); this.ExpiresOn.Value = ManagementHelper.GetUserDateTimeNow().AddMonths(1); Priority.Text = "1"; //OfferAmount.Text = "0"; } BindPromotionLanguagesList(); }
/// <summary> /// Deseralizes the settings. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> public object DeseralizeSettings(Type type) { if (_PromotionDto != null && _PromotionDto.Promotion.Count != 0) { PromotionDto.PromotionRow row = _PromotionDto.Promotion[0]; if (!row.IsParamsNull()) { XmlSerializer serializer = new XmlSerializer(type); MemoryStream stream = new MemoryStream(row.Params); return(serializer.Deserialize(stream)); } } return(null); }
/// <summary> /// Deseralizes the settings binary. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> public object DeseralizeSettingsBinary(Type type) { if (_PromotionDto != null && _PromotionDto.Promotion.Count != 0) { PromotionDto.PromotionRow row = _PromotionDto.Promotion[0]; if (!row.IsParamsNull()) { IFormatter formatter = new BinaryFormatter(); MemoryStream stream = new MemoryStream(row.Params); return(formatter.Deserialize(stream)); } } return(null); }
/// <summary> /// Saves the changes. /// </summary> /// <param name="context">The context.</param> public override void SaveChanges(IDictionary context) { base.SaveChanges(context); // Populate setting Settings settings = new Settings(); settings.EntryXFilter = EntryXFilter.SelectedEntryCode; settings.EntryYFilter = EntryYFilter.SelectedEntryCode; settings.SourceQuantity = Decimal.Parse(SourceQuantity.Text); settings.TargetQuantity = Decimal.Parse(TargetQuantity.Text); settings.AmountOff = Decimal.Parse(OfferAmount.Text); int offerType = Int32.Parse(OfferType.SelectedValue); settings.AmountType = offerType == 1 ? PromotionRewardAmountType.Percentage : PromotionRewardAmountType.Value; settings.RewardType = PromotionRewardType.EachAffectedEntry; // Create custom expression from template string expr = Replace(Config.Expression, settings); // save properties for promotion PromotionDto.PromotionRow promotion = PromotionDto.Promotion[0]; promotion.OfferAmount = Decimal.Parse(OfferAmount.Text); promotion.OfferType = Int32.Parse(OfferType.SelectedValue); promotion.Params = SerializeSettings(settings); // Create or modify expression ExpressionDto expressionDto = new ExpressionDto(); //PromotionDto.PromotionConditionRow row = null; ExpressionDto.ExpressionRow expressionRow = CreateExpressionRow(ref expressionDto); expressionRow.Category = ExpressionCategory.CategoryKey.Promotion.ToString(); expressionRow.ExpressionXml = expr; if (expressionRow.RowState == DataRowState.Detached) { expressionDto.Expression.Rows.Add(expressionRow); } // Save expression ExpressionManager.SaveExpression(expressionDto); // Assign expression id to our new condition PromotionDto.PromotionCondition[0].ExpressionId = expressionRow.ExpressionId; //if (row.RowState == DataRowState.Detached) //PromotionDto.PromotionCondition.Rows.Add(row); }
/// <summary> /// Gets the display name. /// </summary> /// <param name="row">The row.</param> /// <param name="languageCode">The language code.</param> /// <returns></returns> private string GetDisplayName(PromotionDto.PromotionRow row, string languageCode) { PromotionDto.PromotionLanguageRow[] langRows = row.GetPromotionLanguageRows(); if (langRows != null && langRows.Length > 0) { foreach (PromotionDto.PromotionLanguageRow lang in langRows) { if (lang.LanguageCode.Equals(languageCode, StringComparison.OrdinalIgnoreCase)) { return(lang.DisplayName); } } } return(row.Name); }
/// <summary> /// Saves the changes. /// </summary> /// <param name="context">The context.</param> public override void SaveChanges(IDictionary context) { base.SaveChanges(context); // Populate setting Settings settings = new Settings(); settings.TargetExpression = ApplyConditionFilter.NodeCollection[0].ChildNodes; settings.ConditionExpression = ConditionFilter.NodeCollection[0].ChildNodes; // save properties for promotion PromotionDto.PromotionRow promotion = PromotionDto.Promotion[0]; promotion.Params = SerializeSettingsBinary(settings); //// Create custom expression from template //string expr = Replace(Config.Expression, settings); //// Create or modify expression ExpressionDto expressionDto = new ExpressionDto(); ExpressionDto.ExpressionRow expressionRow = CreateExpressionRow(ref expressionDto); expressionRow.Category = ExpressionCategory.CategoryKey.Promotion.ToString(); expressionRow.ExpressionXml = string.Empty; if (expressionRow.RowState == DataRowState.Detached) { expressionDto.Expression.Rows.Add(expressionRow); } //Change DataSource from FilterNodeCollection to ExpressionDto ConditionFilter.Provider.DataSource = expressionDto; ConditionFilter.Provider.SaveFilters("PromotionCondition", expressionRow.ExpressionId.ToString(), settings.ConditionExpression); //// Save expression ExpressionManager.SaveExpression(expressionDto); ApplyConditionFilter.DataSource = expressionDto; ApplyConditionFilter.Provider.SaveFilters("PromotionAction", expressionRow.ExpressionId.ToString(), settings.TargetExpression); //// Save expression ExpressionManager.SaveExpression(expressionDto); //// Assign expression id to our new condition PromotionDto.PromotionCondition[0].ExpressionId = expressionRow.ExpressionId; }
/// <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 form. /// </summary> private void BindForm() { if (Config != null) { Description.Text = Config.Description; } if (PromotionDto != null && PromotionDto.Promotion.Count != 0) { PromotionDto.PromotionRow row = PromotionDto.Promotion[0]; object settingsObj = DeseralizeSettings(typeof(Settings)); if (settingsObj != null) { Settings settings = (Settings)settingsObj; EntryXFilter.SelectedEntryCode = settings.EntryXFilter; EntryYFilter.SelectedEntryCode = settings.EntryYFilter; } } }
/// <summary> /// Processes the delete command. /// </summary> /// <param name="items">The items.</param> void ProcessDeleteCommand(string[] items) { for (int i = 0; i < items.Length; i++) { string[] keys = EcfListView.GetPrimaryKeyIdStringItems(items[i]); if (keys != null) { string id = keys[0]; using (TransactionScope scope = new TransactionScope()) { // delete selected sites PromotionDto dto = PromotionManager.GetPromotionDto(Int32.Parse(id)); List <int> expressionList = new List <int>(); if (dto.Promotion.Count > 0) { PromotionDto.PromotionRow promotionRow = dto.Promotion[0]; foreach (PromotionDto.PromotionConditionRow condition in promotionRow.GetPromotionConditionRows()) { expressionList.Add(condition.ExpressionId); } dto.Promotion[0].Delete(); PromotionManager.SavePromotion(dto); // Delete corresponding expressions foreach (int expressionId in expressionList) { ExpressionDto expressionDto = ExpressionManager.GetExpressionDto(expressionId); if (expressionDto != null && expressionDto.Expression.Count > 0) { expressionDto.Expression[0].Delete(); ExpressionManager.SaveExpression(expressionDto); } } } scope.Complete(); } } } }
/// <summary> /// Saves the changes. /// </summary> /// <param name="context">The context.</param> public override void SaveChanges(IDictionary context) { base.SaveChanges(context); // Populate setting Settings settings = new Settings(); settings.EntryXFilter = EntryXFilter.SelectedEntryCode; settings.EntryYFilter = EntryYFilter.SelectedEntryCode; // Create custom expression from template string expr = Replace(Config.Expression, settings); // save properties for promotion PromotionDto.PromotionRow promotion = PromotionDto.Promotion[0]; promotion.OfferAmount = 100; promotion.OfferType = 0; //undef not use promotion.Params = SerializeSettings(settings); // Create or modify expression ExpressionDto expressionDto = new ExpressionDto(); //PromotionDto.PromotionConditionRow row = null; ExpressionDto.ExpressionRow expressionRow = CreateExpressionRow(ref expressionDto); expressionRow.Category = ExpressionCategory.CategoryKey.Promotion.ToString(); expressionRow.ExpressionXml = expr; if (expressionRow.RowState == DataRowState.Detached) { expressionDto.Expression.Rows.Add(expressionRow); } // Save expression ExpressionManager.SaveExpression(expressionDto); // Assign expression id to our new condition PromotionDto.PromotionCondition[0].ExpressionId = expressionRow.ExpressionId; //if (row.RowState == DataRowState.Detached) //PromotionDto.PromotionCondition.Rows.Add(row); }
/// <summary> /// Binds the form. /// </summary> private void BindForm() { if (Config != null) { Description.Text = Config.Description; } OfferAmount.Text = "0"; MinOrderAmount.Text = "0"; if (PromotionDto != null && PromotionDto.Promotion.Count != 0) { PromotionDto.PromotionRow row = PromotionDto.Promotion[0]; object settingsObj = DeseralizeSettings(typeof(Settings)); if (settingsObj != null) { Settings settings = (Settings)settingsObj; MinOrderAmount.Text = settings.MinOrderAmount.ToString(); } OfferAmount.Text = PromotionDto.Promotion[0].OfferAmount.ToString("N2"); ManagementHelper.SelectListItem(OfferType, PromotionDto.Promotion[0]); } }
/// <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); } }