/// <summary> /// Binds the form. /// </summary> private void BindForm() { // Bind segments TargetSegments.DataSource = SegmentManager.GetSegmentDto(); TargetSegments.DataBind(); if (_campaign != null) { //first check permissions //if permissions not present, deny SecurityManager.CheckRolePermission("marketing:campaigns:mng:edit"); CampaignDto.CampaignRow row = _campaign.Campaign[0]; CampaignName.Text = row.Name; this.AvailableFrom.Value = ManagementHelper.GetUserDateTime(row.StartDate); this.ExpiresOn.Value = ManagementHelper.GetUserDateTime(row.EndDate); IsActive.IsSelected = row.IsActive; IsArchived.IsSelected = row.IsArchived; Comments.Text = row.Comments; foreach (CampaignDto.CampaignSegmentRow segmentRow in row.GetCampaignSegmentRows()) { ManagementHelper.SelectListItem(TargetSegments, segmentRow.SegmentId.ToString(), false); } } else { //first check permissions //if permissions not present, deny SecurityManager.CheckRolePermission("marketing:campaigns:mng:create"); this.AvailableFrom.Value = ManagementHelper.GetUserDateTimeNow(); this.ExpiresOn.Value = ManagementHelper.GetUserDateTimeNow().AddMonths(1); } }
/// <summary> /// Loads the fresh. /// </summary> /// <returns></returns> private SegmentDto LoadFresh() { SegmentDto segment = null; if (SegmentId == 0) { // Create an empty segment segment = new SegmentDto(); SegmentDto.SegmentRow row = segment.Segment.NewSegmentRow(); row.ApplicationId = MarketingConfiguration.Instance.ApplicationId; row.Name = ""; row.DisplayName = ""; row.Description = ""; if (row.RowState == DataRowState.Detached) { segment.Segment.Rows.Add(row); } } else { segment = SegmentManager.GetSegmentDto(SegmentId); } // persist in session Session[_SegmentDtoEditSessionKey] = segment; return(segment); }
/// <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]; List <int> expressionList = new List <int>(); SegmentDto dto = SegmentManager.GetSegmentDto(Int32.Parse(id)); if (dto.Segment.Count > 0) { SegmentDto.SegmentRow segmentRow = dto.Segment[0]; foreach (SegmentDto.SegmentConditionRow condition in segmentRow.GetSegmentConditionRows()) { expressionList.Add(condition.ExpressionId); } dto.Segment[0].Delete(); SegmentManager.SaveSegment(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); } } } } }
/// <summary> /// Loads the data and data bind. /// </summary> /// <param name="sortExpression">The sort expression.</param> private void LoadDataAndDataBind(string sortExpression) { SegmentDto dto = SegmentManager.GetSegmentDto(); if (dto.Segment != null) { DataView view = dto.Segment.DefaultView; view.Sort = sortExpression; MyListView.DataSource = view; } MyListView.CurrentListView.PrimaryKeyId = EcfListView.MakePrimaryKeyIdString("SegmentId"); MyListView.DataBind(); }
/// <summary> /// Handles the SaveChanges event of the EditSaveControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e) { // Validate form if (!this.Page.IsValid) { e.RunScript = false; return; } SegmentDto segment = (SegmentDto)Session[_SegmentDtoEditSessionKey]; ExpressionDto expression = (ExpressionDto)Session[_ExpressionDtoEditSessionKey]; if (segment == null && SegmentId > 0) { segment = SegmentManager.GetSegmentDto(SegmentId); } else if (segment == null && SegmentId == 0) { segment = new SegmentDto(); } if (expression == null && SegmentId > 0) { expression = ExpressionManager.GetExpressionBySegmentDto(SegmentId); } else if (expression == null && SegmentId == 0) { expression = new ExpressionDto(); } /* * // if we add a new segment, remove all other segments from Dto that is passed to control that saves changes * if (SegmentId == 0 && segment != null && segment.Segment.Count > 0) * { * SegmentDto.SegmentRow[] rows2del = (SegmentDto.SegmentRow[])segment.Segment.Select(String.Format("{0} <> {1}", _SegmentIdString, SegmentId)); * if (rows2del != null) * foreach (SegmentDto.SegmentRow row in rows2del) * segment.Segment.RemoveSegmentRow(row); * }*/ IDictionary context = new ListDictionary(); context.Add(_SegmentDtoString, segment); context.Add(_ExpressionDtoString, expression); ViewControl.SaveChanges(context); // save expressionDto if (expression.HasChanges()) { ExpressionManager.SaveExpression(expression); } // update segment conditions foreach (ExpressionDto.ExpressionRow tmpRow in expression.Expression.Rows) { // skip deleted rows if (tmpRow.RowState == DataRowState.Deleted) { continue; } // add SegmentConditionRow SegmentDto.SegmentConditionRow[] segmentConditionRows = (SegmentDto.SegmentConditionRow[])segment.SegmentCondition.Select(String.Format("ExpressionId={0}", tmpRow.ExpressionId)); if (segmentConditionRows == null || segmentConditionRows.Length == 0) { // add new expression SegmentDto.SegmentConditionRow newSCRow = segment.SegmentCondition.NewSegmentConditionRow(); newSCRow.ExpressionId = tmpRow.ExpressionId; newSCRow.SegmentId = segment.Segment[0].SegmentId; if (newSCRow.RowState == DataRowState.Detached) { segment.SegmentCondition.Rows.Add(newSCRow); } } } // save segmentDto if (segment.HasChanges()) { SegmentManager.SaveSegment(segment); } // we don't need to store Dto in session any more Session.Remove(_SegmentDtoEditSessionKey); Session.Remove(_ExpressionDtoEditSessionKey); }
/// <summary> /// Gets the marketing helper. /// </summary> /// <param name="useCache">if set to <c>true</c> [use cache].</param> /// <returns></returns> private MarketingHelper GetMarketingHelper(bool useCache) { MarketingHelper helper = null; string cacheKey = MarketingCache.CreateCacheKey("MarketingHelper"); if (useCache) { object cachedObject = MarketingCache.Get(cacheKey); if (cachedObject != null) { helper = (MarketingHelper)cachedObject; } } // If marketing is not initialized, init it if (helper == null) { // Load promotion Dto PromotionDto promotionDto = PromotionManager.GetPromotionDto(FrameworkContext.Current.CurrentDateTime); // Get all the data from the database first helper = new MarketingHelper(CampaignManager.GetCampaignDto(), ExpressionManager.GetExpressionDto(), PolicyManager.GetPolicyDto(), promotionDto, SegmentManager.GetSegmentDto()); // Insert cache //if (useCache) MarketingCache.Insert(cacheKey, helper, MarketingConfiguration.Instance.CacheConfig.PromotionCollectionTimeout); } return(helper); }