/// <summary> /// Handles the SelectedIndexChanged event of the ddlTargetStatus 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> protected void cmdStatusChange_OnClick(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtSelectedTargetId.Value)) { ICampaignTarget target = EntityFactory.GetRepository <ICampaignTarget>().Get(txtSelectedTargetId.Value); if (target != null) { target.Status = txtNewStatusValue.Value; target.Save(); if (target.Status.Equals(GetLocalResourceObject("Status_Response").ToString())) { bool isLead = target.TargetType.Equals("Lead"); ITargetResponse targetResponse = EntityFactory.Create <ITargetResponse>(); targetResponse.CampaignTarget = target; targetResponse.Campaign = target.Campaign; if (isLead) { targetResponse.Lead = EntityFactory.GetById <ILead>(target.EntityId); } else { targetResponse.Contact = EntityFactory.GetById <IContact>(target.EntityId); } ShowResponseView(targetResponse, isLead); } } txtSelectedTargetId.Value = String.Empty; txtNewStatusValue.Value = String.Empty; } }
/// <summary> /// Handles the RowCommand event of the ContactMarketing control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewCommandEventArgs"/> instance containing the event data.</param> protected void ContactMarketing_RowCommand(object sender, GridViewCommandEventArgs e) { ITargetResponse targetResponse = null; string targetId = String.Empty; string responseId = String.Empty; try { int rowIndex = Convert.ToInt32(e.CommandArgument); targetId = grdContactMarketing.DataKeys[rowIndex].Values[0].ToString(); responseId = grdContactMarketing.DataKeys[rowIndex].Values[1].ToString(); if (!string.IsNullOrEmpty(responseId)) targetResponse = EntityFactory.GetRepository<ITargetResponse>().Get(responseId); } catch { } switch (e.CommandName.ToUpper()) { case "EDIT": if (String.IsNullOrEmpty(targetId)) { AddResponseAndTarget(); } else { if (targetResponse == null) { targetResponse = EntityFactory.Create<ITargetResponse>(); ICampaignTarget target = EntityFactory.GetRepository<ICampaignTarget>().Get(targetId); targetResponse.Campaign = target.Campaign; targetResponse.CampaignTarget = target; } ShowResponseView(targetResponse); } break; case "DELETE": if (targetResponse != null) { ICampaignTarget campaignTarget = targetResponse.CampaignTarget; if (campaignTarget.TargetResponses.Count <= 1) campaignTarget.Status = GetLocalResourceObject("TargetStatus_Removed").ToString(); campaignTarget.TargetResponses.Remove(targetResponse); targetResponse.Delete(); LoadMarketing(); } else { RemoveTargetAssociation(targetId); } break; case "REMOVE": RemoveTargetAssociation(targetId); break; case "SORT": break; } }
/// <summary> /// Removes the target association from the campaign by updating its status. /// </summary> /// <param name="targetId">The target id.</param> private void RemoveTargetAssociation(string targetId) { if (!String.IsNullOrEmpty(targetId)) { ICampaignTarget campaignTarget = EntityFactory.GetRepository <ICampaignTarget>().Get(targetId); if (campaignTarget != null) { campaignTarget.Status = GetLocalResourceObject("TargetStatus_Removed").ToString(); campaignTarget.Save(); LoadMarketing(); } } }
/// <summary> /// Handles the OnClick event of the cmdInitialTarget 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> protected void cmdInitialTarget_OnClick(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtSelectedTargetId.Value)) { ICampaignTarget target = EntityFactory.GetRepository <ICampaignTarget>().Get(txtSelectedTargetId.Value); if (target != null) { target.InitialTarget = Convert.ToBoolean(txtNewInitialTargetValue.Value); target.Save(); } txtSelectedTargetId.Value = String.Empty; txtNewInitialTargetValue.Value = String.Empty; } }
/// <summary> /// Handles the RowCommand event of the grdResponses control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewCommandEventArgs"/> instance containing the event data.</param> protected void grdResponses_RowCommand(object sender, GridViewCommandEventArgs e) { ITargetResponse targetResponse; string responseId = String.Empty; try { int rowIndex = Convert.ToInt32(e.CommandArgument); responseId = grdResponses.DataKeys[rowIndex].Values[0].ToString(); if (String.IsNullOrEmpty(responseId)) { return; } targetResponse = EntityFactory.GetRepository <ITargetResponse>().Get(responseId); if (targetResponse == null) { return; } } catch { return; } switch (e.CommandName.ToUpper()) { case "EDIT": ShowResponseView(targetResponse); break; case "DELETE": if (targetResponse != null) { ICampaignTarget campaignTarget = targetResponse.CampaignTarget; if (campaignTarget != null) { campaignTarget.Status = GetLocalResourceObject("TargetStatus_Removed").ToString(); campaignTarget.TargetResponses.Remove(targetResponse); } targetResponse.Delete(); LoadResponses(); } PanelRefresh.RefreshTabWorkspace(); break; case "SORT": break; } }
/// <summary> /// Assigns the campaign target. /// </summary> private void AssignCampaignTarget() { ITargetResponse targetResponse = BindingSource.Current as ITargetResponse; if (targetResponse.Campaign != null) { ICampaignTarget campaignTarget = targetResponse.CampaignTarget; if (targetResponse.CampaignTarget == null) { ICampaign campaign = (ICampaign)lueCampaign.LookupResultValue; Object entityId; if (rdgTargetType.SelectedIndex == 1) { entityId = targetResponse.Lead.Id; } else { entityId = targetResponse.Contact.Id; } IRepository <ICampaignTarget> repository = EntityFactory.GetRepository <ICampaignTarget>(); IQueryable query = (IQueryable)repository; IExpressionFactory expFactory = query.GetExpressionFactory(); ICriteria criteria = query.CreateCriteria() .Add(expFactory.And( expFactory.Eq("EntityId", entityId), expFactory.Eq("Campaign.Id", campaign.Id))); IList <ICampaignTarget> targets = criteria.List <ICampaignTarget>(); if (targets.Count > 0) { campaignTarget = targets[0]; } else { campaignTarget = EntityFactory.Create <ICampaignTarget>(); campaignTarget.Stage = targetResponse.Stage; if (rdgTargetType.SelectedIndex == 1) { if (targetResponse.Lead != null) { campaignTarget.EntityId = targetResponse.Lead.Id.ToString(); campaignTarget.TargetType = "Lead"; } } else if (targetResponse.Contact != null) { campaignTarget.EntityId = targetResponse.Contact.Id.ToString(); campaignTarget.TargetType = "Contact"; } campaignTarget.Campaign = targetResponse.Campaign; campaignTarget.Status = GetLocalResourceObject("CampaignTargetStatus").ToString(); } } else { if (rdgTargetType.SelectedIndex == 1) { if (targetResponse.Lead != null) { campaignTarget.EntityId = targetResponse.Lead.Id.ToString(); campaignTarget.TargetType = "Lead"; } } else if (targetResponse.Contact != null) { campaignTarget.EntityId = targetResponse.Contact.Id.ToString(); campaignTarget.TargetType = "Contact"; } campaignTarget.Campaign = targetResponse.Campaign; campaignTarget.Status = GetLocalResourceObject("CampaignTargetStatus").ToString(); } targetResponse.CampaignTarget = campaignTarget; } else { //don't create a campaignTarget targetResponse.CampaignTarget = null; } }
/// <summary> /// Handles the RowCommand event of the grdResponses control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewCommandEventArgs"/> instance containing the event data.</param> protected void grdResponses_RowCommand(object sender, GridViewCommandEventArgs e) { ITargetResponse targetResponse = null; string responseId = String.Empty; int rowIndex = Convert.ToInt32(e.CommandArgument); try { responseId = grdResponses.DataKeys[rowIndex].Values[1].ToString(); if (!String.IsNullOrEmpty(responseId)) { targetResponse = EntityFactory.GetRepository <ITargetResponse>().Get(responseId); } } catch { return; } string targetType = grdResponses.DataKeys[rowIndex].Values[2].ToString(); if (e.CommandName.Equals("Delete")) { targetResponse.Delete(); } else if (e.CommandName.Equals("Add")) { bool isLead = false; ICampaignTarget campaignTarget = null; string targetId = grdResponses.DataKeys[rowIndex].Values[0].ToString(); if (!String.IsNullOrEmpty(targetId)) { campaignTarget = EntityFactory.GetRepository <ICampaignTarget>().Get(targetId); } if (campaignTarget != null) { targetResponse = EntityFactory.Create <ITargetResponse>(); if (targetType.ToUpper().Equals("LEAD")) { isLead = true; targetResponse.Lead = EntityFactory.GetRepository <ILead>().Get(campaignTarget.EntityId); } else { targetResponse.Contact = EntityFactory.GetRepository <IContact>().Get(campaignTarget.EntityId); } if (BindingSource.Current != null) { targetResponse.Campaign = BindingSource.Current as ICampaign; } targetResponse.CampaignTarget = campaignTarget; ShowResponseView(targetResponse, isLead); } } else if (e.CommandName.Equals("Edit")) { if (!string.IsNullOrEmpty(targetType)) { ShowResponseView(targetResponse, targetType.Equals("Lead")); } else { DialogService.ShowMessage(GetLocalResourceObject("error_InvalidTargetType").ToString()); } } }