/// <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;
        }
    }
Example #2
0
    /// <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());
            }
        }
    }