protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["ContactID"] != null && Request.QueryString["CampaignID"] != null && Request.QueryString["Username"] != null)
            {
                ContactMasters contemail = ContactMaster.SelectByField("EmailAddress", txtEmailAddress.Text, connectionString);
                contMasters = ContactMaster.SelectByField("ContactId", Convert.ToInt64(Request.QueryString["ContactID"]), connectionString);

                contactBase = new ContactMaster(connectionString);
                contactBase.FirstName = txtFirstName.Text;
                contactBase.LastName = txtLastName.Text;
                contactBase.EmailAddress = txtEmailAddress.Text;
                contactBase.City = txtCity.Text;
                contactBase.Country = txtCountry.Text;
                contactBase.MobilePhone = txtMobilePhone.Text;
                contactBase.PostalCode = txtZipCode.Text;
                contactBase.State = txtState.Text;
                contactBase.Address1 = txtAddress1.Text;
                contactBase.Address2 = txtAddress2.Text;
                contactBase.ModifiedDate = DateTime.Now;

                if (contMasters.Count > 0)
                {
                    List<ContactMaster> cm1 = contemail.ToList().FindAll(delegate(ContactMaster contact) { return (contact.IsDeleted == false || contact.IsDeleted == null); });
                    if (cm1.Count == 0)
                    {
                        update();
                    }
                    else
                    {
                        List<ContactMaster> cm2 = cm1.FindAll(delegate(ContactMaster contact) { return (contact.ContactId == contMasters[0].ContactId); });
                        if (cm2.Count > 0)
                        {
                            update();
                        }
                        else
                        {
                            statusmessage.Append(string.Format("Contact already exists with EmailAddress - {0}", txtEmailAddress.Text));
                            lbMsg.Text = statusmessage.ToString();
                            lbMsg.ForeColor = System.Drawing.Color.Red;
                        }
                    }
                }

            }
        }
        public XmlDocument AddRecipient(string UserID, string Password, string EmailID)
        {
            XmlDocument doc = new System.Xml.XmlDocument();
            StringBuilder str = new StringBuilder();
            string Con = GetConnectionString(UserID, Password);
            if (Con.Trim().Length != 0 && EmailID.Trim().Length != 0)
            {
                if (IsEmail(EmailID) == true)
                {
                    str.Append("<RecipientInfo>");
                    ContactMasters contemail = ContactMaster.SelectByField("EmailAddress", EmailID, Con);

                    if (contemail.Count > 0)
                    {
                        str.Append("<Message> Already existd Email. Please enter Another valid EmailID</Message>");
                    }
                    else
                    {
                        ContactMaster objContactMaster = new ContactMaster(Con);
                        objContactMaster.EmailAddress = EmailID;
                        objContactMaster.IsActive = true;
                        objContactMaster.IsVerified = true;
                        objContactMaster.CreatedDate = DateTime.Now;
                        objContactMaster.InsertWithDefaultValues(true);

                        str.Append("<Message>Recipient Added Successfully</Message>");
                    }

                }
                else
                {
                    str.Append("<Message>Please Enter Valid Email Format ex:([email protected])</Message>");
                }
            }
            else
            {
                str.Append("<Message>Please Enter Valid Inputs</Message>");
            }
            str.Append("</RecipientInfo>");
            doc.LoadXml(str.ToString());
            return doc;
        }
 public void SaveRecipient()
 {
     try
     {
         //create new contact, initializing new object.
         contactBase = new ContactMaster(connectionString);
         contactBase.FirstName = txtFirstName.Text;
         contactBase.LastName = txtLastName.Text;
         contactBase.EmailAddress = txtEmailAddress.Text;
         //contactBase.City = txtCity.Text;
         contactBase.EmailContentType = "Html";
         contactBase.IsActive = true;
         contactBase.CreatedDate = DateTime.Now;
         DataTable contselect = ContactMaster.SelectEmailAddressInNonDeletedContacts(connectionString, txtEmailAddress.Text.ToString());
         ListMasters objList = ListMasterBase.SelectByField("ListMasterID", listId, connectionString);
         if (contselect.Rows.Count == 0)
         {
             addContactsToList();
         }
         else
         {
             statusmessage.Append(string.Format("Your email \"{0}\" already subscribed to our Newsletters.", txtEmailAddress.Text));
             //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Success", "alert('" + statusmessage.ToString() + "')", true);
             lblMsg.ForeColor = System.Drawing.Color.Red;
             lblMsg.Text = statusmessage.ToString();
             txtEmailAddress.Text = string.Empty;
             txtFirstName.Text = string.Empty;
             txtLastName.Text = string.Empty;
             //txtCity.Text = string.Empty;
             //txtArea.Text = string.Empty;
             txtEmailAddress.Focus();
         }
     }
     catch (Exception ex)
     {
     }
 }
Beispiel #4
0
        protected void btnSubscribe_Click(object sender, EventArgs e)
        {
            //get campaign details
            CampaignMasterPrimaryKey objCampaignMasterPrimaryKey = new CampaignMasterPrimaryKey(Convert.ToInt64(Request.QueryString["CampaignID"]));
            CampaignMaster objCampaignMaster = CampaignMaster.SelectOneWithCampaignJobUsingCampaignMasterID(objCampaignMasterPrimaryKey, connectionString);
            DataTable contselect = ContactMaster.SelectEmailAddressInNonDeletedContacts(connectionString, txtSubscriberEmail.Text.ToString());

            if (contselect.Rows.Count == 0)
            {
                if (objCampaignMaster.SelectCondition != "")
                {
                    string[] selectedList = objCampaignMaster.SelectCondition.Split(',');
                    ContactMaster objContactMaster = new ContactMaster(connectionString);

                    string EmailAddress = txtSubscriberEmail.Text;

                    //create the recipient
                    foreach (string listid in selectedList)
                    {
                        Status = objContactMaster.InsertNewSubscriber(Convert.ToInt64(listid), EmailAddress);
                    }

                    if (Status != -1)
                        divSubscribe.InnerHtml = "<b>You have been successfully subscribed to list.</b> ";
                    else
                        divSubscribe.InnerHtml = "<b>Email Alredy subscribed to list.</b> ";
                }
                else
                    divSubscribe.InnerHtml = "<b>List you want subscribe that already removed.</b> ";
            }
            else
            {

                divSubscribe.InnerHtml = "<b>Already existed Email - {0} </b> " + txtSubscriberEmail.Text;
            }
        }
Beispiel #5
0
        protected void LBAddanothercontact_Click(object sender, EventArgs e)
        {
            try
            {
                //create new contact, initializing new object.
                contactBase = new ContactMaster(ConnectionString);
                contactBase.FirstName = txtContactfirstname.Text;
                contactBase.LastName = txtContactLastname.Text;
                contactBase.EmailAddress = txtEmailAddress1.Text;
                contactBase.EmailContentType = "Html";
                contactBase.IsActive = true;
                contactBase.CreatedDate = DateTime.Now;

                //Add New Recipient
                DataTable contselect = ContactMaster.SelectEmailAddressInNonDeletedContacts(ConnectionString, txtEmailAddress1.Text.ToString());
                hdEcontactstatus.Value = "1";
                bool IsSeedList = false;
                ListMasters objList = ListMasterBase.SelectByField("ListMasterID", hiddenEditID.Value, ConnectionString);
                if (objList[0].IsSeedList != null)
                    IsSeedList = (bool)objList[0].IsSeedList;

                if (contselect.Rows.Count == 0)
                {
                    if (objList.Count > 0 && IsSeedList == true)
                    {
                        DataTable memberCount = ListMasterBase.SelectListNamesWithContactCount(hiddenEditID.Value, ConnectionString);
                        int ListMemberCount = Convert.ToInt32(memberCount.Rows[0]["members"].ToString());
                        if (ListMemberCount <= 15)
                        {
                            addMoreContactsToList();
                        }
                        else
                        {
                            lblMainMsg.ForeColor = System.Drawing.Color.Red;
                            statusmessage.Append(string.Format("You can add only 15 contacts to seed list"));
                            lblMainMsg.Text = statusmessage.ToString();
                            lblMainMsg.Visible = true;
                            bindGrid("", "ASC", "ListName");
                            udpnlListGridview.Update();
                        }
                    }
                    else
                    {
                        addMoreContactsToList();
                    }
                }
                else
                {
                    if (IsSeedList == true)
                    {
                        DataTable memberCount = ListMasterBase.SelectListNamesWithContactCount(hiddenEditID.Value, ConnectionString);
                        int ListMemberCount = Convert.ToInt32(memberCount.Rows[0]["members"].ToString());
                        if (ListMemberCount <= 15)
                        {
                            addMoreContactsToList();
                        }
                        else
                        {
                            lblMainMsg.ForeColor = System.Drawing.Color.Red;
                            statusmessage.Append(string.Format("You can add only 15 contacts to seed list"));
                            lblMainMsg.Text = statusmessage.ToString();
                            lblMainMsg.Visible = true;
                            bindGrid("", "ASC", "ListName");
                            udpnlListGridview.Update();
                        }
                    }
                    else
                    {
                        statusmessage.Append(string.Format("Already existed Email - {0}", txtEmailAddress1.Text));
                        status = false;
                        lbCMsg.Text = statusmessage.ToString();
                        lbCMsg.Visible = true;
                        hdEcontactId.Value = contselect.Rows[0][0].ToString();
                        contactID = Convert.ToInt64(hdEcontactId.Value);
                        lblcontactconformation.Text = statusmessage.ToString() + " Do you want add the contact to list ?";
                        ECCExtender.Show();
                    }
                }
            }
            catch (Exception ex)
            {
                lbCMsg.Visible = true;
                lbCMsg.Style.Add("color", "Red");
                lbCMsg.Text = ex.Message;
            }
        }
Beispiel #6
0
        public XmlDocument GetAllRecipients(string UserID, string Password)
        {
            try
            {
                StringBuilder str = new StringBuilder();
                str.Append("<RecipientInfo>");
                string Con = GetConnectionString(UserID, Password);
                if (Con.Trim().Length != 0)
                {
                    ContactMaster objContactMasters = new ContactMaster(Con);
                    DataTable dtContactMaster = new DataTable();
                    dtContactMaster = objContactMasters.SelectAllNonDeletedContacts(Con, "CreatedDate", "desc");
                    if (dtContactMaster != null)
                    {
                        for (int i = 0; i < dtContactMaster.Rows.Count; i++)
                        {
                            str.Append("<Recipient Row=\"" + i.ToString() + "\"> ");
                            str.Append("<RecipientID>" + dtContactMaster.Rows[i]["ContactId"].ToString() + "</RecipientID>");
                            str.Append("<EmailAddress>" + dtContactMaster.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                            str.Append("<CreatedDate>" + dtContactMaster.Rows[i]["CreatedDate"].ToString() + "</CreatedDate> ");
                            str.Append("<RecipientErrormessage></RecipientErrormessage>");
                            str.Append("</Recipient>");
                        }
                    }
                }
                else
                {
                    str.Append("<Message>Please Enter Valid Credentials or check your Connection</Message>");
                    Logger.logdata(logforRpService, "Please Enter Valid Credentials or check your Connection");
                }
                str.Append("</RecipientInfo>");
                LogEndInfo("GetAllRecipients");
                doc.LoadXml(str.ToString());
            }
            catch (Exception ex)
            {
                Logger.logError(logforRpService, ex);
            }

            return doc;
        }
Beispiel #7
0
        public XmlDocument LaunchMailingWithSuppressList(string UserID, string Password, string CampaignName, string Subject, string FromName, string ReplyToAddress, string FromAddress, DataSet Recipients, DataSet SuppressList, DataSet SeedList, string SchedulteDate, string sendType, string TemplateContent, string toReportMailID, string ApproverMailID)
        {
            string mailingId = string.Empty;
            string templateName = "SBTemplate" + DateTime.Now;
            StringBuilder mailContent = new StringBuilder();
            mailContent.Append("<table  width=\"700\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
            //mailContent.Append("<tr><td align=\"left\" valign=\"top\" ><table width=\"700\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"-webkit-border-radius: 10px;	-moz-border-radius: 10px;	border-radius: 10px;	border:solid #0167b5; 	border-width:1px 1px 1px 1px; background:#e8f3f7;\"><tr><td width=\"248\" align=\"left\" valign=\"top\" style=\"padding:5px;\"><img src=\"http://mta1.1pointinteractive.com/1Point/images/Logo-Login.png\" width=\"81\" height=\"44\" /></td><td width=\"250\" align=\"right\" valign=\"bottom\" style=\"padding:5px; font-family:arial; font-size:13px; color:#039; font-weight:bold;\">API Log Report_" + CampaignName + " </td></tr></table></td></tr>");
            List<string> emailColumns = new List<string>();
            emailColumns.Add("Email Address");
            emailColumns.Add("emailaddress");
            emailColumns.Add("email");
            emailColumns.Add("e-mail");
            emailColumns.Add("Email");
            emailColumns.Add("e-mailaddress");
            emailColumns.Add("emailaddress");
            emailColumns.Add("emailadd");
            emailColumns.Add("e-mailadd");
            emailColumns.Add("emailaddress");

            List<string> fnameColumns = new List<string>();
            fnameColumns.Add("firstname");
            fnameColumns.Add("first name");
            fnameColumns.Add("fname");

            List<string> lnameColumns = new List<string>();
            lnameColumns.Add("lastname");
            lnameColumns.Add("last name");
            lnameColumns.Add("lname");


            foreach (DataColumn clm in Recipients.Tables[0].Columns)
            {
                if (emailColumns.Contains(clm.ToString().ToLower()))
                    Recipients.Tables[0].Columns[clm.ToString()].ColumnName = "EmailAddress";
                else if (fnameColumns.Contains(clm.ToString().ToLower()))
                    Recipients.Tables[0].Columns[clm.ToString()].ColumnName = "FirstName";
                else if (lnameColumns.Contains(clm.ToString().ToLower()))
                    Recipients.Tables[0].Columns[clm.ToString()].ColumnName = "LastName";

            }
            if (SuppressList != null && SuppressList.Tables.Count > 0)
            {
                foreach (DataColumn clm in SuppressList.Tables[0].Columns)
                {
                    if (emailColumns.Contains(clm.ToString().ToLower()))
                        SuppressList.Tables[0].Columns[clm.ToString()].ColumnName = "EmailAddress";
                    else if (fnameColumns.Contains(clm.ToString().ToLower()))
                        SuppressList.Tables[0].Columns[clm.ToString()].ColumnName = "FirstName";
                    else if (lnameColumns.Contains(clm.ToString().ToLower()))
                        SuppressList.Tables[0].Columns[clm.ToString()].ColumnName = "LastName";
                }
            }
            if (SeedList != null && SeedList.Tables.Count > 0)
            {
                foreach (DataColumn clm in SeedList.Tables[0].Columns)
                {
                    if (emailColumns.Contains(clm.ToString().ToLower()))
                        SeedList.Tables[0].Columns[clm.ToString()].ColumnName = "EmailAddress";
                    else if (fnameColumns.Contains(clm.ToString().ToLower()))
                        SeedList.Tables[0].Columns[clm.ToString()].ColumnName = "FirstName";
                    else if (lnameColumns.Contains(clm.ToString().ToLower()))
                        SeedList.Tables[0].Columns[clm.ToString()].ColumnName = "LastName";
                }
            }

            int subMailVertion = 1;
            StringBuilder str = new StringBuilder();
            StringBuilder unDeleverdInfo = new StringBuilder();
            str.Append("<MailingInfo>");
            str.Append("<MailingList>");
            try
            {
                string Con = GetConnectionString(UserID, Password);
                string validEmailIds = string.Empty;
                string unsubEmailIds = string.Empty;
                string hardBounceEmailIds = string.Empty;
                string softBounceEmailIds = string.Empty;
                string duplicateEmailids = string.Empty;

                DataTable contacts = Recipients.Tables[0];
                Hashtable contatcInfo = new Hashtable();
                if (Con.Trim().Length != 0)
                {
                    LogStartInfo("LaunchMailingWithSuppressList", Con, UserID);
                    Logger.logdata(logforRpService, "Input Paramiters :Camapign Name = " + CampaignName + "; No.of Contacts=" + Recipients.Tables[0].Rows.Count);
                    if (!(contacts.Columns.IndexOf("EmailAddress") == -1))
                    {
                        string QueryString = "";
                        #region Template

                        TemplateMaster templateMaster = new TemplateMaster(Con);
                        templateMaster.TemplateName = templateName;
                        TemplateMasters tempMasters = TemplateMaster.SelectByField("TemplateName", templateName, Con);
                        if (tempMasters.Count > 0)
                        {
                            str.Append("<Message>Template Name Already Existed</Message>");
                            //mailContent.Append("<tr><td colspan=\"2\">Template Name Already Existed</td></tr>");
                        }
                        else
                        {
                            if (TemplateContent != "" && templateName != "")
                            {
                                TemplateContent = TemplateContent + "<br />If you no longer wish to receive these emails, simply click on the following link:<a href=\"[!RPLINK:GLOBALUNSUBSCRIBE!]\">Unsubscribe</a><br />";
                                templateMaster.HTMLContent = ExtractLinks(TemplateContent, Con);
                                templateMaster.CreatedDate = DateTime.Now;
                                int templateid = templateMaster.InsertReturnID();
                                //templateMaster.InsertWithDefaultValues(true);
                                str.Append("<Message>Template Added Successfully</Message>");
                                //mailContent.Append("<tr><td colspan=\"2\">Template created successfully</td></tr>");

                                str.Append("<TemplateId>" + templateid.ToString() + "</TemplateId>");
                                //mailContent.Append("<tr><td>Template ID</td><td>" + templateid.ToString() + "</td></tr>");
                                //mailContent.Append("<tr><td>Template Name</td><td>" + templateName + "</td></tr>");

                            }
                            else
                            {
                                str.Append("<Error>Please Enter Valid Inputs</Error>");
                                //mailContent.Append("<tr><td colspan=\"2\">No data found in uploaded template</td></tr>");
                            }
                        }
                        #endregion
                        Int64 listid = 0, SupListId = 0, SeedListId = 0;

                        ListMasterBase listMaster = null;
                        #region TargetList
                        if (contacts.Rows.Count > 0 && templateMaster != null)
                        {
                            string[] EmailIds = contacts.AsEnumerable().Select(row => row.Field<string>("EmailAddress")).ToArray();
                            string eidsString = String.Join(",", EmailIds);
                            Logger.logdata(logforRpService, "EmailIds from User :"******"<UndeliveredList>");

                            foreach (DataRow contact in contacts.Rows)
                            {
                                ContactMasters contemail = ContactMaster.SelectByField("EmailAddress", contact["EmailAddress"].ToString(), Con);

                                DataTable unSubDetails = new DataTable();
                                DataTable contactMasters = ContactMaster.GetBouceStatusByEmailIds(Con, contact["EmailAddress"].ToString());

                                if (contemail.Count > 0)
                                {
                                    unSubDetails = UnSubscribeDetail.GetUnSubDetailsByContactId(Con, contemail[0].ContactId.ToString(), string.Empty);
                                }
                                if (unSubDetails.Rows.Count > 0)
                                {
                                    unDeleverdInfo.Append("<Undelivered>");
                                    if (unSubDetails.Rows[0]["Reason"].ToString() == "GlobalUnSub")
                                    {
                                        unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                        unDeleverdInfo.Append("<RecipientStatus>Unsubscribe</RecipientStatus>");
                                        unsubEmailIds = unsubEmailIds + contact["EmailAddress"].ToString() + ";";
                                    }
                                    else if (unSubDetails.Rows[0]["Reason"].ToString() == "bad-mailbox" || unSubDetails.Rows[0]["Reason"].ToString() == "bad-domain")
                                    {
                                        unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                        unDeleverdInfo.Append("<RecipientStatus>HardBounce</RecipientStatus>");
                                        hardBounceEmailIds = hardBounceEmailIds + contact["EmailAddress"].ToString() + ";";
                                    }
                                    unDeleverdInfo.Append("</Undelivered>");
                                }
                                else if (contactMasters.Rows.Count > 0 && contactMasters.Rows[0]["IsActive"].ToString() == "False" && Convert.ToInt32(contactMasters.Rows[0]["SoftBounceCount"].ToString()) >= SoftBounceCount)
                                {
                                    unDeleverdInfo.Append("<Undelivered>");
                                    unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                    unDeleverdInfo.Append("<RecipientStatus>SoftBounce</RecipientStatus>");
                                    unDeleverdInfo.Append("</Undelivered>");
                                    softBounceEmailIds = softBounceEmailIds + contact["EmailAddress"].ToString() + ";";
                                }

                                else if (contemail.Count > 0 && contemail[0].EmailAddress.Trim().Length > 0)
                                {
                                    try
                                    {
                                        if (contemail[0].IsActive == true)
                                        {
                                            QueryString = "";
                                            for (int i = 0; i < contact.ItemArray.Length; i++)
                                            {
                                                QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!";
                                            }
                                            if (!contatcInfo.ContainsKey(contemail[0].ContactId))
                                            {
                                                contatcInfo.Add(contemail[0].ContactId, QueryString);
                                                validEmailIds = validEmailIds + contemail[0].EmailAddress + ";";
                                            }
                                            else
                                                duplicateEmailids = duplicateEmailids + contemail[0].EmailAddress + ";";
                                            ContactMasterPrimaryKey pk = new ContactMasterPrimaryKey(Convert.ToInt64(contemail[0].ContactId.ToString()));
                                            ContactMaster objContactMaster = ContactMaster.SelectOne(pk, Con);

                                            #region Handling Custom fields

                                            foreach (DataColumn column in contacts.Columns)
                                            {
                                                DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con);
                                                string custField = "";
                                                if (customFieldDt.Rows.Count > 0)
                                                {
                                                    custField = customFieldDt.Rows[0]["ContactFieldName"].ToString();
                                                }
                                                else
                                                    custField = column.ColumnName;

                                                if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString()))
                                                {

                                                    switch (custField)
                                                    {
                                                        case "EmailAddress":
                                                            objContactMaster.EmailAddress = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "FirstName":
                                                            objContactMaster.FirstName = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "LastName":
                                                            objContactMaster.LastName = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "Address1":
                                                            objContactMaster.Address1 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "City":
                                                            objContactMaster.City = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "State":
                                                            objContactMaster.State = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "PostalCode":
                                                            objContactMaster.PostalCode = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "Country":
                                                            objContactMaster.Country = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "WorkPhone":
                                                            objContactMaster.WorkPhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "HomePhone":
                                                            objContactMaster.HomePhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "MobilePhone":
                                                            objContactMaster.MobilePhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField1":
                                                            objContactMaster.CustomField1 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField2":
                                                            objContactMaster.CustomField2 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField3":
                                                            objContactMaster.CustomField3 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField4":
                                                            objContactMaster.CustomField4 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField5":
                                                            objContactMaster.CustomField5 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField6":
                                                            objContactMaster.CustomField6 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField7":
                                                            objContactMaster.CustomField7 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField8":
                                                            objContactMaster.CustomField8 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField9":
                                                            objContactMaster.CustomField9 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField10":
                                                            objContactMaster.CustomField10 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField11":
                                                            objContactMaster.CustomField11 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField12":
                                                            objContactMaster.CustomField12 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField13":
                                                            objContactMaster.CustomField13 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField14":
                                                            objContactMaster.CustomField14 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField15":
                                                            objContactMaster.CustomField15 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField16":
                                                            objContactMaster.CustomField16 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField17":
                                                            objContactMaster.CustomField17 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField18":
                                                            objContactMaster.CustomField18 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField19":
                                                            objContactMaster.CustomField19 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField20":
                                                            objContactMaster.CustomField20 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField21":
                                                            objContactMaster.CustomField21 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField22":
                                                            objContactMaster.CustomField22 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField23":
                                                            objContactMaster.CustomField23 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField24":
                                                            objContactMaster.CustomField24 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField25":
                                                            objContactMaster.CustomField25 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField26":
                                                            objContactMaster.CustomField26 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField27":
                                                            objContactMaster.CustomField27 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField28":
                                                            objContactMaster.CustomField28 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField29":
                                                            objContactMaster.CustomField29 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField30":
                                                            objContactMaster.CustomField30 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField31":
                                                            objContactMaster.CustomField31 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField32":
                                                            objContactMaster.CustomField32 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField33":
                                                            objContactMaster.CustomField33 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField34":
                                                            objContactMaster.CustomField34 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField35":
                                                            objContactMaster.CustomField35 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField36":
                                                            objContactMaster.CustomField36 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField37":
                                                            objContactMaster.CustomField37 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField38":
                                                            objContactMaster.CustomField38 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField39":
                                                            objContactMaster.CustomField39 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField40":
                                                            objContactMaster.CustomField40 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField41":
                                                            objContactMaster.CustomField41 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField42":
                                                            objContactMaster.CustomField42 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField43":
                                                            objContactMaster.CustomField43 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField44":
                                                            objContactMaster.CustomField44 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField45":
                                                            objContactMaster.CustomField45 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField46":
                                                            objContactMaster.CustomField46 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField47":
                                                            objContactMaster.CustomField47 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField48":
                                                            objContactMaster.CustomField48 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField49":
                                                            objContactMaster.CustomField49 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField50":
                                                            objContactMaster.CustomField50 = contact[column.ColumnName].ToString();
                                                            break;
                                                    }
                                                }


                                            }

                                            #endregion
                                            if (objContactMaster.Update() == true)
                                            {
                                                //str.Append("<Message>Recipient Updated Successfully</Message>");
                                            }
                                            else
                                            {
                                                //str.Append("<Error>Recipient  Update Failed</Error>");
                                                Logger.logdata(logforRpService, "Recipient  Update Failed");
                                            }
                                        }

                                    }
                                    catch (Exception ex)
                                    {
                                        str.Append("<Error>Edit Contact: Problem at updating contact</Error>");
                                        Logger.logdata(logforRpService, "Update Contact :" + ex.Message);

                                    }

                                }
                                else if (contact["EmailAddress"] != null && contact["EmailAddress"].ToString().Trim().Length > 0)
                                {
                                    try
                                    {
                                        ContactMaster objContactMaster = new ContactMaster(Con);
                                        objContactMaster.EmailAddress = contact["EmailAddress"].ToString();
                                        objContactMaster.EmailContentType = "Html";
                                        objContactMaster.CreatedDate = DateTime.Now;

                                        #region Handling Custom fields

                                        foreach (DataColumn column in contacts.Columns)
                                        {
                                            DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con);
                                            string custField = "";
                                            if (customFieldDt.Rows.Count > 0)
                                            {
                                                custField = customFieldDt.Rows[0]["ContactFieldName"].ToString();
                                            }
                                            else
                                                custField = column.ColumnName;

                                            if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString()))
                                            {
                                                switch (custField)
                                                {
                                                    case "EmailAddress":
                                                        objContactMaster.EmailAddress = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "FirstName":
                                                        objContactMaster.FirstName = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "LastName":
                                                        objContactMaster.LastName = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "Address1":
                                                        objContactMaster.Address1 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "City":
                                                        objContactMaster.City = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "State":
                                                        objContactMaster.State = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "PostalCode":
                                                        objContactMaster.PostalCode = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "Country":
                                                        objContactMaster.Country = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "WorkPhone":
                                                        objContactMaster.WorkPhone = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "HomePhone":
                                                        objContactMaster.HomePhone = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "MobilePhone":
                                                        objContactMaster.MobilePhone = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField1":
                                                        objContactMaster.CustomField1 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField2":
                                                        objContactMaster.CustomField2 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField3":
                                                        objContactMaster.CustomField3 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField4":
                                                        objContactMaster.CustomField4 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField5":
                                                        objContactMaster.CustomField5 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField6":
                                                        objContactMaster.CustomField6 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField7":
                                                        objContactMaster.CustomField7 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField8":
                                                        objContactMaster.CustomField8 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField9":
                                                        objContactMaster.CustomField9 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField10":
                                                        objContactMaster.CustomField10 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField11":
                                                        objContactMaster.CustomField11 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField12":
                                                        objContactMaster.CustomField12 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField13":
                                                        objContactMaster.CustomField13 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField14":
                                                        objContactMaster.CustomField14 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField15":
                                                        objContactMaster.CustomField15 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField16":
                                                        objContactMaster.CustomField16 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField17":
                                                        objContactMaster.CustomField17 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField18":
                                                        objContactMaster.CustomField18 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField19":
                                                        objContactMaster.CustomField19 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField20":
                                                        objContactMaster.CustomField20 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField21":
                                                        objContactMaster.CustomField21 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField22":
                                                        objContactMaster.CustomField22 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField23":
                                                        objContactMaster.CustomField23 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField24":
                                                        objContactMaster.CustomField24 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField25":
                                                        objContactMaster.CustomField25 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField26":
                                                        objContactMaster.CustomField26 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField27":
                                                        objContactMaster.CustomField27 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField28":
                                                        objContactMaster.CustomField28 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField29":
                                                        objContactMaster.CustomField29 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField30":
                                                        objContactMaster.CustomField30 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField31":
                                                        objContactMaster.CustomField31 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField32":
                                                        objContactMaster.CustomField32 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField33":
                                                        objContactMaster.CustomField33 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField34":
                                                        objContactMaster.CustomField34 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField35":
                                                        objContactMaster.CustomField35 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField36":
                                                        objContactMaster.CustomField36 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField37":
                                                        objContactMaster.CustomField37 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField38":
                                                        objContactMaster.CustomField38 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField39":
                                                        objContactMaster.CustomField39 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField40":
                                                        objContactMaster.CustomField40 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField41":
                                                        objContactMaster.CustomField41 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField42":
                                                        objContactMaster.CustomField42 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField43":
                                                        objContactMaster.CustomField43 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField44":
                                                        objContactMaster.CustomField44 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField45":
                                                        objContactMaster.CustomField45 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField46":
                                                        objContactMaster.CustomField46 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField47":
                                                        objContactMaster.CustomField47 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField48":
                                                        objContactMaster.CustomField48 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField49":
                                                        objContactMaster.CustomField49 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField50":
                                                        objContactMaster.CustomField50 = contact[column.ColumnName].ToString();
                                                        break;
                                                }
                                            }


                                        }

                                        #endregion
                                        objContactMaster.IsActive = true;
                                        objContactMaster.InsertWithDefaultValues(true);
                                        Int64 ContactId = Convert.ToInt64(objContactMaster.ContactId);
                                        // ContactIds = ContactIds + ContactId + ",";
                                        QueryString = "";
                                        for (int i = 0; i < contact.ItemArray.Length; i++)
                                        {
                                            QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!";

                                        }
                                        if (!contatcInfo.ContainsKey(ContactId))
                                        {
                                            contatcInfo.Add(ContactId, QueryString);
                                            validEmailIds = validEmailIds + contact["EmailAddress"].ToString() + ";";
                                        }
                                        else
                                            duplicateEmailids = duplicateEmailids + contact["EmailAddress"].ToString() + ";";

                                    }
                                    catch (Exception ex)
                                    {
                                        str.Append("<Error>Add New Contact: Problem at adding contact</Error>");
                                        Logger.logdata(logforRpService, "Add New Contact: " + ex.Message);

                                    }

                                }

                            }
                            unDeleverdInfo.Append("</UndeliveredList>");

                        }

                        try
                        {

                            if (str.ToString().IndexOf("<Error>") == -1 && templateMaster != null && contatcInfo.Count > 0)
                            {

                                listMaster = new ListMasterBase(Con);
                                listMaster.ListName = "TL_" + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                                listMaster.CreatedDate = System.DateTime.Now;
                                listMaster.InsertWithDefaultValues(true);
                                listid = Convert.ToInt64(listMaster.ListMasterID);
                                //ContactIds = ContactIds.Substring(0, ContactIds.Length - 1);
                                //string[] selectContact = ContactIds.Split(',');
                                if (listid > 0)
                                {

                                    DataTable dtListContactMaster = new DataTable();
                                    dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string)));
                                    dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string)));
                                    dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string)));
                                    dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string)));
                                    dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool)));
                                    StringBuilder strbAddedContacts = new StringBuilder();

                                    foreach (DictionaryEntry item in contatcInfo)
                                    {
                                        DataRow rowListContactMaster = dtListContactMaster.NewRow();
                                        rowListContactMaster["ListMasterID"] = listid;
                                        rowListContactMaster["ContactId"] = item.Key;
                                        rowListContactMaster["CreatedDate"] = DateTime.Now.ToString();
                                        rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString();
                                        rowListContactMaster["IsActive"] = true;
                                        dtListContactMaster.Rows.Add(rowListContactMaster);
                                    }

                                    string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                                    string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                                    ListContactMaster.BulkCopy(dtListContactMaster, "ListContactMaster", SourceColumn, DestinationColumn, Con);

                                }
                            }


                        }
                        catch (Exception ex)
                        {
                            str.Append("<Error>List: Problem at ListCreation contact</Error>");
                            Logger.logdata(logforRpService, "List: " + ex.Message);
                        }


                        #endregion

                        ListMasterBase SuplistMaster = null;
                        #region SuppressList
                        contatcInfo = new Hashtable();
                        if (SuppressList.Tables.Count > 0 && SuppressList.Tables[0].Rows.Count > 0 && SuppressList.Tables[0].Columns.Contains("EmailAddress"))
                        {
                            contacts = SuppressList.Tables[0];
                            string[] EmailIds = contacts.AsEnumerable().Select(row => row.Field<string>("EmailAddress")).ToArray();
                            string eidsString = String.Join(",", EmailIds);
                            Logger.logdata(logforRpService, "EmailIds from User :"******"EmailAddress", contact["EmailAddress"].ToString(), Con);

                                DataTable unSubDetails = new DataTable();
                                DataTable contactMasters = ContactMaster.GetBouceStatusByEmailIds(Con, contact["EmailAddress"].ToString());

                                if (contemail.Count > 0)
                                {
                                    unSubDetails = UnSubscribeDetail.GetUnSubDetailsByContactId(Con, contemail[0].ContactId.ToString(), string.Empty);
                                }
                                if (unSubDetails.Rows.Count > 0)
                                {
                                    //unDeleverdInfo.Append("<Undelivered>");
                                    //unDeleverdInfo.Append("<ListType>Suppress</ListType>");
                                    if (unSubDetails.Rows[0]["Reason"].ToString() == "GlobalUnSub")
                                    {
                                        //unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                        //unDeleverdInfo.Append("<RecipientStatus>Unsubscribe</RecipientStatus>");
                                        unsubEmailIds = unsubEmailIds + contact["EmailAddress"].ToString() + ";";
                                    }
                                    else if (unSubDetails.Rows[0]["Reason"].ToString() == "bad-mailbox" || unSubDetails.Rows[0]["Reason"].ToString() == "bad-domain")
                                    {
                                        //unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                        //unDeleverdInfo.Append("<RecipientStatus>HardBounce</RecipientStatus>");
                                        hardBounceEmailIds = hardBounceEmailIds + contact["EmailAddress"].ToString() + ";";
                                    }
                                    //unDeleverdInfo.Append("</Undelivered>");
                                }
                                else if (contactMasters.Rows.Count > 0 && contactMasters.Rows[0]["IsActive"].ToString() == "False" && Convert.ToInt32(contactMasters.Rows[0]["SoftBounceCount"].ToString()) >= SoftBounceCount)
                                {
                                    //unDeleverdInfo.Append("<Undelivered>");
                                    //unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                    //unDeleverdInfo.Append("<RecipientStatus>SoftBounce</RecipientStatus>");
                                    //unDeleverdInfo.Append("</Undelivered>");
                                    softBounceEmailIds = softBounceEmailIds + contact["EmailAddress"].ToString() + ";";
                                }

                                else if (contemail.Count > 0 && contemail[0].EmailAddress.Trim().Length > 0)
                                {
                                    try
                                    {
                                        if (contemail[0].IsActive == true)
                                        {
                                            QueryString = "";
                                            for (int i = 0; i < contact.ItemArray.Length; i++)
                                            {
                                                QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!";
                                            }
                                            if (!contatcInfo.ContainsKey(contemail[0].ContactId))
                                            {
                                                contatcInfo.Add(contemail[0].ContactId, QueryString);
                                                validEmailIds = validEmailIds + contemail[0].EmailAddress + ";";
                                            }
                                            else
                                                duplicateEmailids = duplicateEmailids + contemail[0].EmailAddress + ";";
                                            ContactMasterPrimaryKey pk = new ContactMasterPrimaryKey(Convert.ToInt64(contemail[0].ContactId.ToString()));
                                            ContactMaster objContactMaster = ContactMaster.SelectOne(pk, Con);

                                            #region Handling Custom fields

                                            foreach (DataColumn column in contacts.Columns)
                                            {
                                                DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con);
                                                string custField = "";
                                                if (customFieldDt.Rows.Count > 0)
                                                {
                                                    custField = customFieldDt.Rows[0]["ContactFieldName"].ToString();
                                                }
                                                else
                                                    custField = column.ColumnName;

                                                if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString()))
                                                {

                                                    switch (custField)
                                                    {
                                                        case "EmailAddress":
                                                            objContactMaster.EmailAddress = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "FirstName":
                                                            objContactMaster.FirstName = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "LastName":
                                                            objContactMaster.LastName = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "Address1":
                                                            objContactMaster.Address1 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "City":
                                                            objContactMaster.City = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "State":
                                                            objContactMaster.State = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "PostalCode":
                                                            objContactMaster.PostalCode = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "Country":
                                                            objContactMaster.Country = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "WorkPhone":
                                                            objContactMaster.WorkPhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "HomePhone":
                                                            objContactMaster.HomePhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "MobilePhone":
                                                            objContactMaster.MobilePhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField1":
                                                            objContactMaster.CustomField1 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField2":
                                                            objContactMaster.CustomField2 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField3":
                                                            objContactMaster.CustomField3 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField4":
                                                            objContactMaster.CustomField4 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField5":
                                                            objContactMaster.CustomField5 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField6":
                                                            objContactMaster.CustomField6 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField7":
                                                            objContactMaster.CustomField7 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField8":
                                                            objContactMaster.CustomField8 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField9":
                                                            objContactMaster.CustomField9 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField10":
                                                            objContactMaster.CustomField10 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField11":
                                                            objContactMaster.CustomField11 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField12":
                                                            objContactMaster.CustomField12 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField13":
                                                            objContactMaster.CustomField13 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField14":
                                                            objContactMaster.CustomField14 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField15":
                                                            objContactMaster.CustomField15 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField16":
                                                            objContactMaster.CustomField16 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField17":
                                                            objContactMaster.CustomField17 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField18":
                                                            objContactMaster.CustomField18 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField19":
                                                            objContactMaster.CustomField19 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField20":
                                                            objContactMaster.CustomField20 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField21":
                                                            objContactMaster.CustomField21 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField22":
                                                            objContactMaster.CustomField22 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField23":
                                                            objContactMaster.CustomField23 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField24":
                                                            objContactMaster.CustomField24 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField25":
                                                            objContactMaster.CustomField25 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField26":
                                                            objContactMaster.CustomField26 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField27":
                                                            objContactMaster.CustomField27 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField28":
                                                            objContactMaster.CustomField28 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField29":
                                                            objContactMaster.CustomField29 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField30":
                                                            objContactMaster.CustomField30 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField31":
                                                            objContactMaster.CustomField31 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField32":
                                                            objContactMaster.CustomField32 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField33":
                                                            objContactMaster.CustomField33 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField34":
                                                            objContactMaster.CustomField34 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField35":
                                                            objContactMaster.CustomField35 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField36":
                                                            objContactMaster.CustomField36 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField37":
                                                            objContactMaster.CustomField37 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField38":
                                                            objContactMaster.CustomField38 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField39":
                                                            objContactMaster.CustomField39 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField40":
                                                            objContactMaster.CustomField40 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField41":
                                                            objContactMaster.CustomField41 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField42":
                                                            objContactMaster.CustomField42 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField43":
                                                            objContactMaster.CustomField43 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField44":
                                                            objContactMaster.CustomField44 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField45":
                                                            objContactMaster.CustomField45 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField46":
                                                            objContactMaster.CustomField46 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField47":
                                                            objContactMaster.CustomField47 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField48":
                                                            objContactMaster.CustomField48 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField49":
                                                            objContactMaster.CustomField49 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField50":
                                                            objContactMaster.CustomField50 = contact[column.ColumnName].ToString();
                                                            break;
                                                    }
                                                }


                                            }

                                            #endregion
                                            if (objContactMaster.Update() == true)
                                            {
                                                //str.Append("<Message>Recipient Updated Successfully</Message>");
                                            }
                                            else
                                            {
                                                //str.Append("<Error>Recipient  Update Failed</Error>");
                                                Logger.logdata(logforRpService, "Recipient  Update Failed");
                                            }
                                        }

                                    }
                                    catch (Exception ex)
                                    {
                                        str.Append("<Error>Edit Contact: Problem at updating contact</Error>");
                                        Logger.logdata(logforRpService, "Update Contact :" + ex.Message);

                                    }

                                }
                                else if (contact["EmailAddress"] != null && contact["EmailAddress"].ToString().Trim().Length > 0)
                                {
                                    try
                                    {
                                        ContactMaster objContactMaster = new ContactMaster(Con);
                                        objContactMaster.EmailAddress = contact["EmailAddress"].ToString();
                                        objContactMaster.EmailContentType = "Html";
                                        objContactMaster.CreatedDate = DateTime.Now;

                                        #region Handling Custom fields

                                        foreach (DataColumn column in contacts.Columns)
                                        {
                                            DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con);
                                            string custField = "";
                                            if (customFieldDt.Rows.Count > 0)
                                            {
                                                custField = customFieldDt.Rows[0]["ContactFieldName"].ToString();
                                            }
                                            else
                                                custField = column.ColumnName;

                                            if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString()))
                                            {
                                                switch (custField)
                                                {
                                                    case "EmailAddress":
                                                        objContactMaster.EmailAddress = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "FirstName":
                                                        objContactMaster.FirstName = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "LastName":
                                                        objContactMaster.LastName = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "Address1":
                                                        objContactMaster.Address1 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "City":
                                                        objContactMaster.City = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "State":
                                                        objContactMaster.State = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "PostalCode":
                                                        objContactMaster.PostalCode = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "Country":
                                                        objContactMaster.Country = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "WorkPhone":
                                                        objContactMaster.WorkPhone = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "HomePhone":
                                                        objContactMaster.HomePhone = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "MobilePhone":
                                                        objContactMaster.MobilePhone = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField1":
                                                        objContactMaster.CustomField1 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField2":
                                                        objContactMaster.CustomField2 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField3":
                                                        objContactMaster.CustomField3 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField4":
                                                        objContactMaster.CustomField4 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField5":
                                                        objContactMaster.CustomField5 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField6":
                                                        objContactMaster.CustomField6 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField7":
                                                        objContactMaster.CustomField7 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField8":
                                                        objContactMaster.CustomField8 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField9":
                                                        objContactMaster.CustomField9 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField10":
                                                        objContactMaster.CustomField10 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField11":
                                                        objContactMaster.CustomField11 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField12":
                                                        objContactMaster.CustomField12 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField13":
                                                        objContactMaster.CustomField13 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField14":
                                                        objContactMaster.CustomField14 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField15":
                                                        objContactMaster.CustomField15 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField16":
                                                        objContactMaster.CustomField16 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField17":
                                                        objContactMaster.CustomField17 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField18":
                                                        objContactMaster.CustomField18 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField19":
                                                        objContactMaster.CustomField19 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField20":
                                                        objContactMaster.CustomField20 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField21":
                                                        objContactMaster.CustomField21 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField22":
                                                        objContactMaster.CustomField22 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField23":
                                                        objContactMaster.CustomField23 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField24":
                                                        objContactMaster.CustomField24 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField25":
                                                        objContactMaster.CustomField25 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField26":
                                                        objContactMaster.CustomField26 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField27":
                                                        objContactMaster.CustomField27 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField28":
                                                        objContactMaster.CustomField28 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField29":
                                                        objContactMaster.CustomField29 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField30":
                                                        objContactMaster.CustomField30 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField31":
                                                        objContactMaster.CustomField31 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField32":
                                                        objContactMaster.CustomField32 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField33":
                                                        objContactMaster.CustomField33 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField34":
                                                        objContactMaster.CustomField34 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField35":
                                                        objContactMaster.CustomField35 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField36":
                                                        objContactMaster.CustomField36 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField37":
                                                        objContactMaster.CustomField37 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField38":
                                                        objContactMaster.CustomField38 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField39":
                                                        objContactMaster.CustomField39 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField40":
                                                        objContactMaster.CustomField40 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField41":
                                                        objContactMaster.CustomField41 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField42":
                                                        objContactMaster.CustomField42 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField43":
                                                        objContactMaster.CustomField43 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField44":
                                                        objContactMaster.CustomField44 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField45":
                                                        objContactMaster.CustomField45 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField46":
                                                        objContactMaster.CustomField46 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField47":
                                                        objContactMaster.CustomField47 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField48":
                                                        objContactMaster.CustomField48 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField49":
                                                        objContactMaster.CustomField49 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField50":
                                                        objContactMaster.CustomField50 = contact[column.ColumnName].ToString();
                                                        break;
                                                }
                                            }


                                        }

                                        #endregion
                                        objContactMaster.IsActive = true;
                                        objContactMaster.InsertWithDefaultValues(true);
                                        Int64 ContactId = Convert.ToInt64(objContactMaster.ContactId);
                                        // ContactIds = ContactIds + ContactId + ",";
                                        QueryString = "";
                                        for (int i = 0; i < contact.ItemArray.Length; i++)
                                        {
                                            QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!";

                                        }
                                        if (!contatcInfo.ContainsKey(ContactId))
                                        {
                                            contatcInfo.Add(ContactId, QueryString);
                                            validEmailIds = validEmailIds + contact["EmailAddress"].ToString() + ";";
                                        }
                                        else
                                            duplicateEmailids = duplicateEmailids + contact["EmailAddress"].ToString() + ";";

                                    }
                                    catch (Exception ex)
                                    {
                                        str.Append("<Error>Add New Contact: Problem at adding contact</Error>");
                                        Logger.logdata(logforRpService, "Add New Contact: " + ex.Message);

                                    }

                                }

                            }

                        }

                        if (contatcInfo.Count > 0)
                        {
                            SuplistMaster = new ListMasterBase(Con);
                            SuplistMaster.ListName = "SL_" + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                            SuplistMaster.CreatedDate = System.DateTime.Now;
                            SuplistMaster.Active = false;
                            SuplistMaster.InsertWithDefaultValues(true);
                            SupListId = Convert.ToInt64(SuplistMaster.ListMasterID);

                            ArrayList selectContact = new ArrayList();
                            ContactMasters contemail;
                            foreach (DataRow recipient in SuppressList.Tables[0].Rows)
                            {
                                contemail = ContactMaster.SelectByField("EmailAddress", recipient["EmailAddress"].ToString(), Con);
                                if (contemail.Count > 0)
                                    selectContact.Add(contemail[0].ContactId.ToString());
                            }

                            if (SupListId > 0)
                            {

                                DataTable dtListContactMaster = new DataTable();
                                dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string)));
                                dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string)));
                                dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string)));
                                dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string)));
                                dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool)));
                                StringBuilder strbAddedContacts = new StringBuilder();

                                foreach (DictionaryEntry item in contatcInfo)
                                {
                                    DataRow rowListContactMaster = dtListContactMaster.NewRow();
                                    rowListContactMaster["ListMasterID"] = SupListId;
                                    rowListContactMaster["ContactId"] = item.Key;
                                    rowListContactMaster["CreatedDate"] = DateTime.Now.ToString();
                                    rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString();
                                    rowListContactMaster["IsActive"] = true;
                                    dtListContactMaster.Rows.Add(rowListContactMaster);
                                }

                                string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                                string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                                ListContactMaster.BulkCopy(dtListContactMaster, "ListContactMaster", SourceColumn, DestinationColumn, Con);

                            }

                        }

                        #endregion

                        ListMasterBase SeedlistMaster = null;
                        #region SeedList
                        contatcInfo = new Hashtable();
                        if (SeedList.Tables.Count > 0 && SeedList.Tables[0].Rows.Count > 0 && SeedList.Tables[0].Columns.Contains("EmailAddress"))
                        {
                            contacts = SeedList.Tables[0];
                            //DataRow dr;
                            //if (ApproverMailID.Contains(','))
                            //{
                            //    string[] MailIds = ApproverMailID.Split(',');
                            //    foreach (string mail in MailIds)
                            //    {
                            //        dr = contacts.NewRow();
                            //        dr["EmailAddress"] = mail;
                            //        contacts.Rows.Add(dr);
                            //    }
                            //}
                            //else
                            //{
                            //    dr = contacts.NewRow();
                            //    dr["EmailAddress"] = ApproverMailID;
                            //    contacts.Rows.Add(dr);
                            //}

                            string[] EmailIds = contacts.AsEnumerable().Select(row => row.Field<string>("EmailAddress")).ToArray();
                            string eidsString = String.Join(",", EmailIds);
                            Logger.logdata(logforRpService, "EmailIds from User :"******"EmailAddress", contact["EmailAddress"].ToString(), Con);

                                DataTable unSubDetails = new DataTable();
                                DataTable contactMasters = ContactMaster.GetBouceStatusByEmailIds(Con, contact["EmailAddress"].ToString());

                                if (contemail.Count > 0)
                                {
                                    unSubDetails = UnSubscribeDetail.GetUnSubDetailsByContactId(Con, contemail[0].ContactId.ToString(), string.Empty);
                                }
                                if (unSubDetails.Rows.Count > 0)
                                {
                                    //unDeleverdInfo.Append("<Undelivered>");
                                    // unDeleverdInfo.Append("<ListType>Seed</ListType>");
                                    if (unSubDetails.Rows[0]["Reason"].ToString() == "GlobalUnSub")
                                    {
                                        // unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                        //unDeleverdInfo.Append("<RecipientStatus>Unsubscribe</RecipientStatus>");
                                        unsubEmailIds = unsubEmailIds + contact["EmailAddress"].ToString() + ";";
                                    }
                                    else if (unSubDetails.Rows[0]["Reason"].ToString() == "bad-mailbox" || unSubDetails.Rows[0]["Reason"].ToString() == "bad-domain")
                                    {
                                        //unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                        //unDeleverdInfo.Append("<RecipientStatus>HardBounce</RecipientStatus>");
                                        hardBounceEmailIds = hardBounceEmailIds + contact["EmailAddress"].ToString() + ";";
                                    }
                                    //unDeleverdInfo.Append("</Undelivered>");
                                }
                                else if (contactMasters.Rows.Count > 0 && contactMasters.Rows[0]["IsActive"].ToString() == "False" && Convert.ToInt32(contactMasters.Rows[0]["SoftBounceCount"].ToString()) >= SoftBounceCount)
                                {
                                    //unDeleverdInfo.Append("<Undelivered>");
                                    //unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                    //unDeleverdInfo.Append("<RecipientStatus>SoftBounce</RecipientStatus>");
                                    //unDeleverdInfo.Append("</Undelivered>");
                                    softBounceEmailIds = softBounceEmailIds + contact["EmailAddress"].ToString() + ";";
                                }

                                else if (contemail.Count > 0 && contemail[0].EmailAddress.Trim().Length > 0)
                                {
                                    try
                                    {
                                        if (contemail[0].IsActive == true)
                                        {
                                            QueryString = "";
                                            for (int i = 0; i < contact.ItemArray.Length; i++)
                                            {
                                                QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!";
                                            }
                                            if (!contatcInfo.ContainsKey(contemail[0].ContactId))
                                            {
                                                contatcInfo.Add(contemail[0].ContactId, QueryString);
                                                validEmailIds = validEmailIds + contemail[0].EmailAddress + ";";
                                            }
                                            else
                                                duplicateEmailids = duplicateEmailids + contemail[0].EmailAddress + ";";
                                            ContactMasterPrimaryKey pk = new ContactMasterPrimaryKey(Convert.ToInt64(contemail[0].ContactId.ToString()));
                                            ContactMaster objContactMaster = ContactMaster.SelectOne(pk, Con);

                                            #region Handling Custom fields

                                            foreach (DataColumn column in contacts.Columns)
                                            {
                                                DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con);
                                                string custField = "";
                                                if (customFieldDt.Rows.Count > 0)
                                                {
                                                    custField = customFieldDt.Rows[0]["ContactFieldName"].ToString();
                                                }
                                                else
                                                    custField = column.ColumnName;

                                                if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString()))
                                                {

                                                    switch (custField)
                                                    {
                                                        case "EmailAddress":
                                                            objContactMaster.EmailAddress = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "FirstName":
                                                            objContactMaster.FirstName = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "LastName":
                                                            objContactMaster.LastName = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "Address1":
                                                            objContactMaster.Address1 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "City":
                                                            objContactMaster.City = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "State":
                                                            objContactMaster.State = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "PostalCode":
                                                            objContactMaster.PostalCode = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "Country":
                                                            objContactMaster.Country = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "WorkPhone":
                                                            objContactMaster.WorkPhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "HomePhone":
                                                            objContactMaster.HomePhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "MobilePhone":
                                                            objContactMaster.MobilePhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField1":
                                                            objContactMaster.CustomField1 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField2":
                                                            objContactMaster.CustomField2 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField3":
                                                            objContactMaster.CustomField3 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField4":
                                                            objContactMaster.CustomField4 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField5":
                                                            objContactMaster.CustomField5 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField6":
                                                            objContactMaster.CustomField6 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField7":
                                                            objContactMaster.CustomField7 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField8":
                                                            objContactMaster.CustomField8 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField9":
                                                            objContactMaster.CustomField9 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField10":
                                                            objContactMaster.CustomField10 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField11":
                                                            objContactMaster.CustomField11 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField12":
                                                            objContactMaster.CustomField12 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField13":
                                                            objContactMaster.CustomField13 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField14":
                                                            objContactMaster.CustomField14 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField15":
                                                            objContactMaster.CustomField15 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField16":
                                                            objContactMaster.CustomField16 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField17":
                                                            objContactMaster.CustomField17 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField18":
                                                            objContactMaster.CustomField18 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField19":
                                                            objContactMaster.CustomField19 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField20":
                                                            objContactMaster.CustomField20 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField21":
                                                            objContactMaster.CustomField21 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField22":
                                                            objContactMaster.CustomField22 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField23":
                                                            objContactMaster.CustomField23 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField24":
                                                            objContactMaster.CustomField24 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField25":
                                                            objContactMaster.CustomField25 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField26":
                                                            objContactMaster.CustomField26 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField27":
                                                            objContactMaster.CustomField27 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField28":
                                                            objContactMaster.CustomField28 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField29":
                                                            objContactMaster.CustomField29 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField30":
                                                            objContactMaster.CustomField30 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField31":
                                                            objContactMaster.CustomField31 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField32":
                                                            objContactMaster.CustomField32 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField33":
                                                            objContactMaster.CustomField33 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField34":
                                                            objContactMaster.CustomField34 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField35":
                                                            objContactMaster.CustomField35 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField36":
                                                            objContactMaster.CustomField36 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField37":
                                                            objContactMaster.CustomField37 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField38":
                                                            objContactMaster.CustomField38 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField39":
                                                            objContactMaster.CustomField39 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField40":
                                                            objContactMaster.CustomField40 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField41":
                                                            objContactMaster.CustomField41 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField42":
                                                            objContactMaster.CustomField42 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField43":
                                                            objContactMaster.CustomField43 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField44":
                                                            objContactMaster.CustomField44 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField45":
                                                            objContactMaster.CustomField45 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField46":
                                                            objContactMaster.CustomField46 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField47":
                                                            objContactMaster.CustomField47 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField48":
                                                            objContactMaster.CustomField48 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField49":
                                                            objContactMaster.CustomField49 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField50":
                                                            objContactMaster.CustomField50 = contact[column.ColumnName].ToString();
                                                            break;
                                                    }
                                                }


                                            }

                                            #endregion
                                            if (objContactMaster.Update() == true)
                                            {
                                                //str.Append("<Message>Recipient Updated Successfully</Message>");
                                            }
                                            else
                                            {
                                                //str.Append("<Error>Recipient  Update Failed</Error>");
                                                Logger.logdata(logforRpService, "Recipient  Update Failed");
                                            }
                                        }

                                    }
                                    catch (Exception ex)
                                    {
                                        str.Append("<Error>Edit Contact: Problem at updating contact</Error>");
                                        Logger.logdata(logforRpService, "Update Contact :" + ex.Message);

                                    }

                                }
                                else if (contact["EmailAddress"] != null && contact["EmailAddress"].ToString().Trim().Length > 0)
                                {
                                    try
                                    {
                                        ContactMaster objContactMaster = new ContactMaster(Con);
                                        objContactMaster.EmailAddress = contact["EmailAddress"].ToString();
                                        objContactMaster.EmailContentType = "Html";
                                        objContactMaster.CreatedDate = DateTime.Now;

                                        #region Handling Custom fields

                                        foreach (DataColumn column in contacts.Columns)
                                        {
                                            DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con);
                                            string custField = "";
                                            if (customFieldDt.Rows.Count > 0)
                                            {
                                                custField = customFieldDt.Rows[0]["ContactFieldName"].ToString();
                                            }
                                            else
                                                custField = column.ColumnName;

                                            if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString()))
                                            {
                                                switch (custField)
                                                {
                                                    case "EmailAddress":
                                                        objContactMaster.EmailAddress = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "FirstName":
                                                        objContactMaster.FirstName = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "LastName":
                                                        objContactMaster.LastName = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "Address1":
                                                        objContactMaster.Address1 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "City":
                                                        objContactMaster.City = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "State":
                                                        objContactMaster.State = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "PostalCode":
                                                        objContactMaster.PostalCode = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "Country":
                                                        objContactMaster.Country = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "WorkPhone":
                                                        objContactMaster.WorkPhone = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "HomePhone":
                                                        objContactMaster.HomePhone = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "MobilePhone":
                                                        objContactMaster.MobilePhone = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField1":
                                                        objContactMaster.CustomField1 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField2":
                                                        objContactMaster.CustomField2 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField3":
                                                        objContactMaster.CustomField3 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField4":
                                                        objContactMaster.CustomField4 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField5":
                                                        objContactMaster.CustomField5 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField6":
                                                        objContactMaster.CustomField6 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField7":
                                                        objContactMaster.CustomField7 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField8":
                                                        objContactMaster.CustomField8 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField9":
                                                        objContactMaster.CustomField9 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField10":
                                                        objContactMaster.CustomField10 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField11":
                                                        objContactMaster.CustomField11 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField12":
                                                        objContactMaster.CustomField12 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField13":
                                                        objContactMaster.CustomField13 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField14":
                                                        objContactMaster.CustomField14 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField15":
                                                        objContactMaster.CustomField15 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField16":
                                                        objContactMaster.CustomField16 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField17":
                                                        objContactMaster.CustomField17 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField18":
                                                        objContactMaster.CustomField18 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField19":
                                                        objContactMaster.CustomField19 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField20":
                                                        objContactMaster.CustomField20 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField21":
                                                        objContactMaster.CustomField21 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField22":
                                                        objContactMaster.CustomField22 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField23":
                                                        objContactMaster.CustomField23 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField24":
                                                        objContactMaster.CustomField24 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField25":
                                                        objContactMaster.CustomField25 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField26":
                                                        objContactMaster.CustomField26 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField27":
                                                        objContactMaster.CustomField27 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField28":
                                                        objContactMaster.CustomField28 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField29":
                                                        objContactMaster.CustomField29 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField30":
                                                        objContactMaster.CustomField30 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField31":
                                                        objContactMaster.CustomField31 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField32":
                                                        objContactMaster.CustomField32 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField33":
                                                        objContactMaster.CustomField33 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField34":
                                                        objContactMaster.CustomField34 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField35":
                                                        objContactMaster.CustomField35 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField36":
                                                        objContactMaster.CustomField36 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField37":
                                                        objContactMaster.CustomField37 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField38":
                                                        objContactMaster.CustomField38 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField39":
                                                        objContactMaster.CustomField39 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField40":
                                                        objContactMaster.CustomField40 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField41":
                                                        objContactMaster.CustomField41 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField42":
                                                        objContactMaster.CustomField42 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField43":
                                                        objContactMaster.CustomField43 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField44":
                                                        objContactMaster.CustomField44 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField45":
                                                        objContactMaster.CustomField45 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField46":
                                                        objContactMaster.CustomField46 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField47":
                                                        objContactMaster.CustomField47 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField48":
                                                        objContactMaster.CustomField48 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField49":
                                                        objContactMaster.CustomField49 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField50":
                                                        objContactMaster.CustomField50 = contact[column.ColumnName].ToString();
                                                        break;
                                                }
                                            }


                                        }

                                        #endregion
                                        objContactMaster.IsActive = true;
                                        objContactMaster.InsertWithDefaultValues(true);
                                        Int64 ContactId = Convert.ToInt64(objContactMaster.ContactId);
                                        // ContactIds = ContactIds + ContactId + ",";
                                        QueryString = "";
                                        for (int i = 0; i < contact.ItemArray.Length; i++)
                                        {
                                            QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!";

                                        }
                                        if (!contatcInfo.ContainsKey(ContactId))
                                        {
                                            contatcInfo.Add(ContactId, QueryString);
                                            validEmailIds = validEmailIds + contact["EmailAddress"].ToString() + ";";
                                        }
                                        else
                                            duplicateEmailids = duplicateEmailids + contact["EmailAddress"].ToString() + ";";

                                    }
                                    catch (Exception ex)
                                    {
                                        str.Append("<Error>Add New Contact: Problem at adding contact</Error>");
                                        Logger.logdata(logforRpService, "Add New Contact: " + ex.Message);

                                    }

                                }

                            }

                        }

                        if (contatcInfo.Count > 0)
                        {
                            SeedlistMaster = new ListMasterBase(Con);
                            SeedlistMaster.ListName = "SDL_" + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                            SeedlistMaster.CreatedDate = System.DateTime.Now;
                            SeedlistMaster.Active = true;
                            SeedlistMaster.IsSeedList = true;
                            SeedlistMaster.InsertWithDefaultValues(true);
                            SeedListId = Convert.ToInt64(SeedlistMaster.ListMasterID);

                            ArrayList selectContact = new ArrayList();
                            ContactMasters contemail;
                            foreach (DataRow recipient in SeedList.Tables[0].Rows)
                            {
                                contemail = ContactMaster.SelectByField("EmailAddress", recipient["EmailAddress"].ToString(), Con);
                                if (contemail.Count > 0)
                                    selectContact.Add(contemail[0].ContactId.ToString());
                            }

                            if (SeedListId > 0)
                            {

                                DataTable dtListContactMaster = new DataTable();
                                dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string)));
                                dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string)));
                                dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string)));
                                dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string)));
                                dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool)));
                                StringBuilder strbAddedContacts = new StringBuilder();

                                foreach (DictionaryEntry item in contatcInfo)
                                {
                                    DataRow rowListContactMaster = dtListContactMaster.NewRow();
                                    rowListContactMaster["ListMasterID"] = SeedListId;
                                    rowListContactMaster["ContactId"] = item.Key;
                                    rowListContactMaster["CreatedDate"] = DateTime.Now.ToString();
                                    rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString();
                                    rowListContactMaster["IsActive"] = true;
                                    dtListContactMaster.Rows.Add(rowListContactMaster);
                                }

                                string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                                string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                                ListContactMaster.BulkCopy(dtListContactMaster, "ListContactMaster", SourceColumn, DestinationColumn, Con);

                            }

                        }

                        #endregion

                        CampaignMasters camp = CampaignMaster.SelectByField("CampaignName", CampaignName, Con);
                        if (camp.Count > 0)
                        {
                            Logger.logdata(logforRpService, "LaunchMailingWithSuppressList():Mail sending failed,Mailing with name " + CampaignName + " allready exist");
                            str.Append("<Error>Mailing : " + CampaignName + " allready exist</Error>");
                        }
                        if (CampaignName.Length > 50)
                        {
                            Logger.logdata(logforRpService, "LaunchMailingWithSuppressList():Mail sending failed,MailingName name max length exided");
                            str.Append("<Error>Mailing : Mailing name exided max length of 75 chars </Error>");
                            //mailContent.Append("<tr><td colspan=\"2\">Mailing : Mailing name exided max length of 75 chars</td></tr>");
                        }
                        else if (templateMaster == null)
                        {
                            Logger.logdata(logforRpService, "LaunchMailingWithSuppressList():Mail sending failed,TemplateName with name " + templateName + " not exist");
                            str.Append("<Error>Tempalte : " + templateName + " not found</Error>");
                            //mailContent.Append("<tr><td colspan=\"2\">Tempalte : " + templateName + " not found</td></tr>");
                        }
                        else if (listid <= 0)
                        {
                            Logger.logdata(logforRpService, "LaunchMailingWithSuppressList():Mail sending failed,List with id " + listid.ToString() + " not exist");
                            str.Append("<Error>List :Zero records found(Check contact status)</Error>");
                            //mailContent.Append("<tr><td colspan=\"2\">List :Zero records found(Check contact status)</td></tr>");

                        }
                        #region Schedule Camapign

                        string CampainID = "False";
                        str.Append("<MailingDetails>");
                        if (str.ToString().IndexOf("<Error>") == -1)
                        {
                            CampainID = ScheduleMailingWithSuppressList(Con, CampaignName, Subject, FromName, ReplyToAddress, FromAddress, templateName, listid.ToString(), SupListId.ToString(), SeedListId.ToString(), SchedulteDate, sendType);

                            if (CampainID != "False")
                            {
                                string message = string.Empty;
                                SendTestMail(TemplateContent, CampainID, Convert.ToInt64(SeedListId), ApproverMailID, FromAddress, FromName, ReplyToAddress, Subject, Con);
                                mailingId = CampainID;
                                str.Append("<MailingID>" + CampainID + "</MailingID>");
                                str.Append("<TemplateName>" + templateName + "</TemplateName>");
                                str.Append("<TemplateID>" + templateMaster.TemplateId + "</TemplateID>");
                                str.Append("<ListName>" + listMaster.ListName + "</ListName>");
                                str.Append("<ListID>" + listMaster.ListMasterID + "</ListID>");
                                Logger.logdata(logforRpService, "Success ::Mailing ID: " + CampainID + " ;Mailing Name : " + CampaignName + ";List Name: " + listMaster.ListName);
                                Logger.logdata(logforRpService, "No. of valid Contacts found  : " + contatcInfo.Count);
                                Logger.logdata(logforRpService, "No. of invalid Contacts found: " + (contacts.Rows.Count - contatcInfo.Count));
                                Logger.logdata(logforRpService, "valid Contacts found         : " + validEmailIds);
                                Logger.logdata(logforRpService, "Unsubscribed Mails           :" + unsubEmailIds);
                                Logger.logdata(logforRpService, "HardBounce triggered Mails   :" + hardBounceEmailIds);
                                Logger.logdata(logforRpService, "SoftBounce triggered Mails   :" + softBounceEmailIds);
                                Logger.logdata(logforRpService, "Duplicate EmailIds           :" + duplicateEmailids);
                                string ApproverPagePath = ConfigurationManager.AppSettings["ApproverPagePath"];
                                if (ApproverPagePath.Trim().Length > 0)
                                    ApproverPagePath = ApproverPagePath + "?UserName="******"&MailingID=" + CampainID;
                                mailContent.Append("<tr><td colspan=\"2\" height=\"70\" align=\"left\" valign=\"middle\" style=\"padding-bottom:10px; font-family:arial; font-size:13px; color:#666; font-weight:bold;\">Dear Member,<br/><br/>Your request for Email campaign scheduling has been received to our system successfully via API Call.<br/> Have a look at the Email campaign data submitted to the system and click on Approve Email button provided at end of this email to approve this job.</td></tr>");
                                mailContent.Append("<tr><td align=\"center\" valign=\"top\" style=\"-webkit-border-radius: 10px;	-moz-border-radius: 10px;	border-radius: 10px; border:solid #016ab3; border-width:1px;-webkit-box-shadow: 2px 2px 4px #999;	-moz-box-shadow: 2px 2px 4px #999;	box-shadow: 2px 2px 4px #999;\">");
                                mailContent.Append("<table width=\"500\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" >");
                                mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">Client/User</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + UserID + "</td></tr>");
                                mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">Mailing Name</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + CampaignName + "</td></tr>");
                                mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">Mailing ID</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + mailingId + "</td></tr>");
                                mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">From Name </td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + FromName + "</td></tr>");
                                mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">From Mail</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + FromAddress + "</td></tr>");
                                mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">Subject</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + Subject + "</td></tr>");
                                mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">Reply To Mail</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + ReplyToAddress + "</td></tr>");
                                if (Recipients.Tables.Count > 0)
                                    mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">Mailing List File Quantity </td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + Recipients.Tables[0].Rows.Count + "</td></tr>");
                                if (SuppressList.Tables.Count > 0)
                                    mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">Suppress List File Quantity </td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + SuppressList.Tables[0].Rows.Count + "</td></tr>");
                                mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">Schedule Date/Time</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + SchedulteDate + "</td></tr>");
                                mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">Mailing List Name</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + listMaster.ListName + "</td></tr>");
                                mailContent.Append("<tr><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#0288cd;	font-weight:bold;\">Mailing List ID</td><td align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif;	font-size:13px;	color:#666;	font-weight:bold;\">" + listMaster.ListMasterID + "</td></tr>");
                                mailContent.Append("</table></td></tr>");
                                mailContent.Append("</table>");
                                mailContent.Append("<table width=\"700\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
                                mailContent.Append("<tr><td></td><td align=\"center\" valign=\"middle\" style=\"height: 50px\"><a href=\"" + ApproverPagePath + "\" onclick=\"window.open(this.href, 'ApproveMailing','left=20,top=20,width=550,height=200,toolbar=1,resizable=0'); return false;\"><img src=\"http://mta1.1pointinteractive.com/1Point/images/btn-approve-email.png\" /></a></td></tr>");
                                mailContent.Append("<tr><td colspan=\"2\" align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#666;	font-weight:bold;\">Thanks,</td></tr>");
                                mailContent.Append("<tr><td colspan=\"2\" align=\"left\" valign=\"middle\" style=\"font-family:Arial, Helvetica, sans-serif; font-size:13px;	color:#666;	font-weight:bold;\">1Point Support Team</td></tr>");
                                mailContent.Append("</table>");

                                if (toReportMailID.Trim().Length > 0)
                                {
                                    string fromMail = ConfigurationManager.AppSettings["ApiFromMail"];
                                    bool status = true;
                                    if (!ApproverMailID.Contains(','))
                                        status = sendEMail(fromMail, ApproverMailID, ReplyToAddress, "API Log Report_" + CampaignName, false, mailContent.ToString(), out message);
                                    else
                                    {
                                        status = sendEMail(fromMail, ApproverMailID, ReplyToAddress, "API Log Report_" + CampaignName, false, mailContent.ToString(), out message);
                                    }
                                    MailApproval objMailApproval = new MailApproval(Con);
                                    objMailApproval.MailingID = Convert.ToInt64(CampainID);
                                    objMailApproval.ApprovalMail = ApproverMailID;
                                    objMailApproval.ReportMailTo = toReportMailID;
                                    objMailApproval.ApprovalStatus = "NotApproved";
                                    objMailApproval.IsApprovalSent = status;
                                    objMailApproval.IsReportMailied = false;

                                    objMailApproval.IsActive = false;
                                    objMailApproval.OneHr = false;
                                    objMailApproval.TwoHr = false;
                                    objMailApproval.FourHr = false;
                                    objMailApproval.EightHr = false;
                                    objMailApproval.Insert();
                                }
                            }
                            else
                            {
                                str.Append("<Error>ScheduleMailing : Problem at scheduling a mailing</Error>");
                                Logger.logdata(logforRpService, "Problem at scheduling Mailing");
                            }

                        }
                        if (str.ToString().IndexOf("<Error>") == -1)
                            str.Append("<Status>True</Status>");
                        else
                            str.Append("<Status>False</Status>");
                        str.Append("</MailingDetails>");
                        LogEndInfo("LaunchMailingWithSuppressList");


                        #endregion
                    }
                    else
                    {
                        Logger.logdata(logforRpService, "LaunchMailingWithSuppressList():Column with name EmailAddress(and/or)FirstName(and/or)LastName not found in input DataSet");
                        str.Append("<Error>Input DataSet:Contact must contain EmailAddress Field</Error>");
                    }
                }
                else
                {
                    str.Append("<Error>Invalid UserID OR Password</Error>");
                    str.Append("<MailingDetails>");
                    str.Append("<Status>False</Status>");
                    str.Append("</MailingDetails>");
                    Logger.logdata(logforRpService, "Invalid UserID OR Password");
                }
            }
            catch (Exception ex)
            {
                str.Append("<Error>Failed to connect database</Error>");
                str.Append("<MailingDetails>");
                str.Append("<Status>False</Status>");
                str.Append("</MailingDetails>");
                Logger.logError(logforRpService, ex);
            }
            str.Append("</MailingList>");
            if (str.ToString().IndexOf("<Error>") == -1)
                str.Append("<SubMailingCount>" + subMailVertion + "</SubMailingCount>");
            str.Append(unDeleverdInfo);
            str.Append("</MailingInfo>");

            doc.LoadXml(str.ToString());
            return doc;
        }
Beispiel #8
0
        public XmlDocument SendMail(string UserID, string Password, string CampaignName, string Subject, string FromName, string ReplyToAddress, string FromAddress, string TemplateName, DataSet Recipients)
        {
            StringBuilder str = new StringBuilder();
            try
            {
                str.Append("<CampaignInfo>");
                string Con = GetConnectionString(UserID, Password);
                string validEmailIds = string.Empty;
                string unsubEmailIds = string.Empty;
                string hardBounceEmailIds = string.Empty;
                string softBounceEmailIds = string.Empty;
                string duplicateEmailids = string.Empty;



                DataTable contacts = Recipients.Tables[0];
                // string ContactIds = "";                
                Hashtable contatcInfo = new Hashtable();
                if (Con.Trim().Length != 0)
                {
                    LogStartInfo("SendMail", Con, UserID);
                    Logger.logdata(logforRpService, "Input Paramiters :Camapign Name = " + CampaignName + "; Template Name =" + TemplateName + "; No.of Contacts=" + Recipients.Tables[0].Rows.Count);
                    if (!(contacts.Columns.IndexOf("EmailAddress") == -1) && !(contacts.Columns.IndexOf("FirstName") == -1) && !(contacts.Columns.IndexOf("LastName") == -1))
                    {
                        string QueryString = "";
                        #region Template
                        TemplateMaster tempMaster = null;
                        try
                        {
                            TemplateMasters obj = TemplateMaster.SelectByField("TemplateName", TemplateName, Con);
                            if (obj.Count > 0)
                            {
                                TemplateMasterPrimaryKey template = new TemplateMasterPrimaryKey(Convert.ToInt64(obj[0].TemplateId.ToString()));
                                tempMaster = TemplateMaster.SelectOne(template, Con);
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.logdata(logforRpService, "Template region :" + ex.Message);
                        }

                        #endregion

                        #region Contacts

                        if (contacts.Rows.Count > 0 && tempMaster != null)
                        {
                            string[] EmailIds = contacts.AsEnumerable().Select(row => row.Field<string>("EmailAddress")).ToArray();
                            string eidsString = String.Join(",", EmailIds);
                            Logger.logdata(logforRpService, "EmailIds from User :"******"<RecipientInfo>");
                            foreach (DataRow contact in contacts.Rows)
                            {
                                ContactMasters contemail = ContactMaster.SelectByField("EmailAddress", contact["EmailAddress"].ToString(), Con);

                                DataTable unSubDetails = new DataTable();
                                DataTable contactMasters = ContactMaster.GetBouceStatusByEmailIds(Con, contact["EmailAddress"].ToString());

                                if (contemail.Count > 0)
                                {
                                    unSubDetails = UnSubscribeDetail.GetUnSubDetailsByContactId(Con, contemail[0].ContactId.ToString(), string.Empty);
                                }
                                if (unSubDetails.Rows.Count > 0)
                                {
                                    str.Append("<Undelivered>");
                                    if (unSubDetails.Rows[0]["Reason"].ToString() == "GlobalUnSub")
                                    {
                                        str.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                        str.Append("<FirstName>" + contact["FirstName"].ToString() + "</FirstName>");
                                        str.Append("<LastName>" + contact["LastName"].ToString() + "</LastName>");
                                        str.Append("<RecipientStatus>Unsubscribe</RecipientStatus>");
                                        unsubEmailIds = unsubEmailIds + contact["EmailAddress"].ToString() + ";";
                                    }
                                    else if (unSubDetails.Rows[0]["Reason"].ToString() == "bad-mailbox" || unSubDetails.Rows[0]["Reason"].ToString() == "bad-domain")
                                    {
                                        str.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                        str.Append("<FirstName>" + contact["FirstName"].ToString() + "</FirstName>");
                                        str.Append("<LastName>" + contact["LastName"].ToString() + "</LastName>");
                                        str.Append("<RecipientStatus>HardBounce</RecipientStatus>");
                                        hardBounceEmailIds = hardBounceEmailIds + contact["EmailAddress"].ToString() + ";";
                                    }
                                    str.Append("</Undelivered>");
                                }
                                else if (contactMasters.Rows.Count > 0 && contactMasters.Rows[0]["IsActive"].ToString() == "False" && Convert.ToInt32(contactMasters.Rows[0]["SoftBounceCount"].ToString()) >= SoftBounceCount)
                                {
                                    str.Append("<Undelivered>");
                                    str.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                    str.Append("<FirstName>" + contact["FirstName"].ToString() + "</FirstName>");
                                    str.Append("<LastName>" + contact["LastName"].ToString() + "</LastName>");
                                    str.Append("<RecipientStatus>SoftBounce</RecipientStatus>");
                                    str.Append("</Undelivered>");
                                    softBounceEmailIds = softBounceEmailIds + contact["EmailAddress"].ToString() + ";";
                                }

                                else if (contemail.Count > 0 && contemail[0].EmailAddress.Trim().Length > 0)
                                {
                                    try
                                    {
                                        if (contemail[0].IsActive == true)
                                        {
                                            QueryString = "";
                                            for (int i = 0; i < contact.ItemArray.Length; i++)
                                            {
                                                QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!";
                                            }
                                            if (!contatcInfo.ContainsKey(contemail[0].ContactId))
                                            {
                                                contatcInfo.Add(contemail[0].ContactId, QueryString);
                                                validEmailIds = validEmailIds + contemail[0].EmailAddress + ";";
                                            }
                                            else
                                                duplicateEmailids = duplicateEmailids + contemail[0].EmailAddress + ";";
                                            ContactMasterPrimaryKey pk = new ContactMasterPrimaryKey(Convert.ToInt64(contemail[0].ContactId.ToString()));
                                            ContactMaster objContactMaster = ContactMaster.SelectOne(pk, Con);
                                            objContactMaster.FirstName = contact["FirstName"].ToString();
                                            objContactMaster.LastName = contact["LastName"].ToString();
                                            #region Handling Custom fields

                                            foreach (DataColumn column in contacts.Columns)
                                            {
                                                DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con);
                                                string custField = "";
                                                if (customFieldDt.Rows.Count > 0)
                                                {
                                                    custField = customFieldDt.Rows[0]["ContactFieldName"].ToString();
                                                }
                                                if (custField != "" && customFieldDt.Rows.Count > 0 && !string.IsNullOrEmpty(contact[column.ColumnName].ToString()))
                                                {
                                                    switch (custField)
                                                    {
                                                        case "CustomField1":
                                                            objContactMaster.CustomField1 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField2":
                                                            objContactMaster.CustomField2 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField3":
                                                            objContactMaster.CustomField3 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField4":
                                                            objContactMaster.CustomField4 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField5":
                                                            objContactMaster.CustomField5 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField6":
                                                            objContactMaster.CustomField6 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField7":
                                                            objContactMaster.CustomField7 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField8":
                                                            objContactMaster.CustomField8 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField9":
                                                            objContactMaster.CustomField9 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField10":
                                                            objContactMaster.CustomField10 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField11":
                                                            objContactMaster.CustomField11 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField12":
                                                            objContactMaster.CustomField12 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField13":
                                                            objContactMaster.CustomField13 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField14":
                                                            objContactMaster.CustomField14 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField15":
                                                            objContactMaster.CustomField15 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField16":
                                                            objContactMaster.CustomField16 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField17":
                                                            objContactMaster.CustomField17 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField18":
                                                            objContactMaster.CustomField18 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField19":
                                                            objContactMaster.CustomField19 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField20":
                                                            objContactMaster.CustomField20 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField21":
                                                            objContactMaster.CustomField21 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField22":
                                                            objContactMaster.CustomField22 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField23":
                                                            objContactMaster.CustomField23 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField24":
                                                            objContactMaster.CustomField24 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField25":
                                                            objContactMaster.CustomField25 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField26":
                                                            objContactMaster.CustomField26 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField27":
                                                            objContactMaster.CustomField27 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField28":
                                                            objContactMaster.CustomField28 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField29":
                                                            objContactMaster.CustomField29 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField30":
                                                            objContactMaster.CustomField30 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField31":
                                                            objContactMaster.CustomField31 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField32":
                                                            objContactMaster.CustomField32 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField33":
                                                            objContactMaster.CustomField33 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField34":
                                                            objContactMaster.CustomField34 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField35":
                                                            objContactMaster.CustomField35 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField36":
                                                            objContactMaster.CustomField36 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField37":
                                                            objContactMaster.CustomField37 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField38":
                                                            objContactMaster.CustomField38 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField39":
                                                            objContactMaster.CustomField39 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField40":
                                                            objContactMaster.CustomField40 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField41":
                                                            objContactMaster.CustomField41 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField42":
                                                            objContactMaster.CustomField42 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField43":
                                                            objContactMaster.CustomField43 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField44":
                                                            objContactMaster.CustomField44 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField45":
                                                            objContactMaster.CustomField45 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField46":
                                                            objContactMaster.CustomField46 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField47":
                                                            objContactMaster.CustomField47 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField48":
                                                            objContactMaster.CustomField48 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField49":
                                                            objContactMaster.CustomField49 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField50":
                                                            objContactMaster.CustomField50 = contact[column.ColumnName].ToString();
                                                            break;
                                                    }
                                                }


                                            }

                                            #endregion
                                            if (objContactMaster.Update() == true)
                                            {
                                                //str.Append("<Message>Recipient Updated Successfully</Message>");
                                            }
                                            else
                                            {
                                                //str.Append("<Error>Recipient  Update Failed</Error>");
                                                Logger.logdata(logforRpService, "Recipient  Update Failed");
                                            }
                                        }

                                    }
                                    catch (Exception ex)
                                    {
                                        str.Append("<Error>Edit Contact: Problem at updating contact</Error>");
                                        Logger.logdata(logforRpService, "Update Contact :" + ex.Message);

                                    }

                                }
                                else if (contact["EmailAddress"] != null && contact["EmailAddress"].ToString().Trim().Length > 0)
                                {
                                    try
                                    {
                                        ContactMaster objContactMaster = new ContactMaster(Con);
                                        objContactMaster.EmailAddress = contact["EmailAddress"].ToString();
                                        objContactMaster.EmailContentType = "Html";
                                        objContactMaster.CreatedDate = DateTime.Now;
                                        objContactMaster.FirstName = contact["FirstName"].ToString();
                                        objContactMaster.LastName = contact["LastName"].ToString();
                                        #region Handling Custom fields

                                        foreach (DataColumn column in contacts.Columns)
                                        {
                                            DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, Con);
                                            string custField = "";
                                            if (customFieldDt.Rows.Count > 0)
                                            {
                                                custField = customFieldDt.Rows[0]["ContactFieldName"].ToString();
                                            }
                                            if (custField != "" && customFieldDt.Rows.Count > 0 && !string.IsNullOrEmpty(contact[column.ColumnName].ToString()))
                                            {
                                                switch (custField)
                                                {
                                                    case "CustomField1":
                                                        objContactMaster.CustomField1 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField2":
                                                        objContactMaster.CustomField2 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField3":
                                                        objContactMaster.CustomField3 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField4":
                                                        objContactMaster.CustomField4 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField5":
                                                        objContactMaster.CustomField5 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField6":
                                                        objContactMaster.CustomField6 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField7":
                                                        objContactMaster.CustomField7 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField8":
                                                        objContactMaster.CustomField8 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField9":
                                                        objContactMaster.CustomField9 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField10":
                                                        objContactMaster.CustomField10 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField11":
                                                        objContactMaster.CustomField11 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField12":
                                                        objContactMaster.CustomField12 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField13":
                                                        objContactMaster.CustomField13 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField14":
                                                        objContactMaster.CustomField14 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField15":
                                                        objContactMaster.CustomField15 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField16":
                                                        objContactMaster.CustomField16 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField17":
                                                        objContactMaster.CustomField17 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField18":
                                                        objContactMaster.CustomField18 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField19":
                                                        objContactMaster.CustomField19 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField20":
                                                        objContactMaster.CustomField20 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField21":
                                                        objContactMaster.CustomField21 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField22":
                                                        objContactMaster.CustomField22 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField23":
                                                        objContactMaster.CustomField23 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField24":
                                                        objContactMaster.CustomField24 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField25":
                                                        objContactMaster.CustomField25 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField26":
                                                        objContactMaster.CustomField26 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField27":
                                                        objContactMaster.CustomField27 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField28":
                                                        objContactMaster.CustomField28 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField29":
                                                        objContactMaster.CustomField29 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField30":
                                                        objContactMaster.CustomField30 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField31":
                                                        objContactMaster.CustomField31 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField32":
                                                        objContactMaster.CustomField32 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField33":
                                                        objContactMaster.CustomField33 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField34":
                                                        objContactMaster.CustomField34 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField35":
                                                        objContactMaster.CustomField35 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField36":
                                                        objContactMaster.CustomField36 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField37":
                                                        objContactMaster.CustomField37 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField38":
                                                        objContactMaster.CustomField38 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField39":
                                                        objContactMaster.CustomField39 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField40":
                                                        objContactMaster.CustomField40 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField41":
                                                        objContactMaster.CustomField41 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField42":
                                                        objContactMaster.CustomField42 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField43":
                                                        objContactMaster.CustomField43 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField44":
                                                        objContactMaster.CustomField44 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField45":
                                                        objContactMaster.CustomField45 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField46":
                                                        objContactMaster.CustomField46 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField47":
                                                        objContactMaster.CustomField47 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField48":
                                                        objContactMaster.CustomField48 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField49":
                                                        objContactMaster.CustomField49 = contact[column.ColumnName].ToString();
                                                        break;
                                                    case "CustomField50":
                                                        objContactMaster.CustomField50 = contact[column.ColumnName].ToString();
                                                        break;
                                                }
                                            }


                                        }

                                        #endregion
                                        objContactMaster.IsActive = true;
                                        objContactMaster.InsertWithDefaultValues(true);
                                        Int64 ContactId = Convert.ToInt64(objContactMaster.ContactId);
                                        // ContactIds = ContactIds + ContactId + ",";
                                        QueryString = "";
                                        for (int i = 0; i < contact.ItemArray.Length; i++)
                                        {
                                            QueryString = QueryString + contact.Table.Columns[i].ColumnName + "!RPFieldValue!" + contact[contact.Table.Columns[i].ColumnName] + "!RPDynamicField!";

                                        }
                                        if (!contatcInfo.ContainsKey(ContactId))
                                        {
                                            contatcInfo.Add(ContactId, QueryString);
                                            validEmailIds = validEmailIds + contact["EmailAddress"].ToString() + ";";
                                        }
                                        else
                                            duplicateEmailids = duplicateEmailids + contact["EmailAddress"].ToString() + ";";

                                    }
                                    catch (Exception ex)
                                    {
                                        str.Append("<Error>Add New Contact: Problem at adding contact</Error>");
                                        Logger.logdata(logforRpService, "Add New Contact: " + ex.Message);

                                    }

                                }

                            }
                            str.Append("</RecipientInfo>");

                        }


                        #endregion

                        #region List
                        ListMasterBase listMaster = null;
                        Int64 listid = 0;
                        try
                        {

                            if (str.ToString().IndexOf("<Error>") == -1 && tempMaster != null && contatcInfo.Count > 0)
                            {

                                listMaster = new ListMasterBase(Con);
                                listMaster.ListName = "4VL_" + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss:ffff");
                                listMaster.CreatedDate = System.DateTime.Now;
                                listMaster.InsertWithDefaultValues(true);
                                listid = Convert.ToInt64(listMaster.ListMasterID);
                                //ContactIds = ContactIds.Substring(0, ContactIds.Length - 1);
                                //string[] selectContact = ContactIds.Split(',');
                                if (listid > 0)
                                {

                                    DataTable dtListContactMaster = new DataTable();
                                    dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string)));
                                    dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string)));
                                    dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string)));
                                    dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string)));
                                    dtListContactMaster.Columns.Add(new DataColumn("QueryString", typeof(string)));
                                    dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool)));
                                    StringBuilder strbAddedContacts = new StringBuilder();

                                    foreach (DictionaryEntry item in contatcInfo)
                                    {

                                        DataRow rowListContactMaster = dtListContactMaster.NewRow();
                                        rowListContactMaster["ListMasterID"] = listid;
                                        rowListContactMaster["ContactId"] = item.Key;
                                        rowListContactMaster["CreatedDate"] = DateTime.Now.ToString();
                                        rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString();
                                        rowListContactMaster["QueryString"] = item.Value;
                                        rowListContactMaster["IsActive"] = true;
                                        dtListContactMaster.Rows.Add(rowListContactMaster);

                                    }

                                    string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "QueryString", "IsActive" };
                                    string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "QueryString", "IsActive" };
                                    ListContactMaster.BulkCopy(dtListContactMaster, "ListContactMaster", SourceColumn, DestinationColumn, Con);

                                }
                            }


                        }
                        catch (Exception ex)
                        {
                            str.Append("<Error>List: Problem at ListCreation contact</Error>");
                            Logger.logdata(logforRpService, "List: " + ex.Message);
                        }


                        #endregion

                        CampaignMasters camp = CampaignMaster.SelectByField("CampaignName", CampaignName, Con);
                        if (camp.Count > 0)
                        {
                            Logger.logdata(logforRpService, "SendMail():Campaign sending failed,CampaignName with name " + CampaignName + " allready exist");
                            str.Append("<Error>Camapign : " + CampaignName + " allready exist</Error>");

                        }
                        if (CampaignName.Length > 75)
                        {
                            Logger.logdata(logforRpService, "SendMail():Campaign sending failed,CampaignName name max length exided");
                            str.Append("<Error>Camapign : Campaign name exided max length of 75 chars </Error>");

                        }
                        else if (tempMaster == null)
                        {
                            Logger.logdata(logforRpService, "SendMail():Campaign sending failed,TemplateName with name " + TemplateName + " not exist");
                            str.Append("<Error>Tempalte : " + TemplateName + " not found</Error>");
                        }
                        else if (listid <= 0)
                        {
                            Logger.logdata(logforRpService, "SendMail():Campaign sending failed,List with id " + listid.ToString() + " not exist");
                            str.Append("<Error>List :Zero records found(Check contact status)</Error>");
                        }
                        #region Schedule Camapign

                        string CampainID = "False";
                        str.Append("<CampaignDetails>");
                        if (str.ToString().IndexOf("<Error>") == -1)
                        {
                            CampainID = ScheduleCampaign(Con, CampaignName, Subject, FromName, ReplyToAddress, FromAddress, TemplateName, listid.ToString());

                            if (CampainID != "False")
                            {
                                str.Append("<CampaignID>" + CampainID + "</CampaignID>");
                                str.Append("<TemplateName>" + TemplateName + "</TemplateName>");
                                str.Append("<TemplateID>" + tempMaster.TemplateId + "</TemplateID>");
                                str.Append("<ListName>" + listMaster.ListName + "</ListName>");
                                str.Append("<ListID>" + listMaster.ListMasterID + "</ListID>");
                                Logger.logdata(logforRpService, "Success ::Campaign ID: " + CampainID + " ;Camapign Name : " + CampaignName + " ;Template Name : " + TemplateName + " ;List Name: " + listMaster.ListName);
                                Logger.logdata(logforRpService, "No. of valid Contacts found  : " + contatcInfo.Count);
                                Logger.logdata(logforRpService, "No. of invalid Contacts found: " + (contacts.Rows.Count - contatcInfo.Count));
                                Logger.logdata(logforRpService, "valid Contacts found         : " + validEmailIds);
                                Logger.logdata(logforRpService, "Unsubscribed Mails           :" + unsubEmailIds);
                                Logger.logdata(logforRpService, "HardBounce triggered Mails   :" + hardBounceEmailIds);
                                Logger.logdata(logforRpService, "SoftBounce triggered Mails   :" + hardBounceEmailIds);
                                Logger.logdata(logforRpService, "Duplicate EmailIds           :" + duplicateEmailids);

                            }
                            else
                            {
                                str.Append("<Error>ScheduleCampaign : Problem at scheduling campaign</Error>");
                                Logger.logdata(logforRpService, "Problem at scheduling campaign");
                            }


                        }
                        str.Append("</CampaignDetails>");
                        if (str.ToString().IndexOf("<Error>") == -1)
                            str.Append("<Status>True</Status>");
                        else
                            str.Append("<Status>False</Status>");
                        LogEndInfo("SendMail");


                        #endregion
                    }
                    else
                    {
                        Logger.logdata(logforRpService, "SendMail():Column with name EmailAddress(and/or)FirstName(and/or)LastName not found in input DataSet");
                        str.Append("<Error>Input DataSet:Contact must contain EmailAddress,FirstName and LastName fields</Error>");
                    }

                }
                else
                {
                    str.Append("<Status>False</Status>");
                    str.Append("<Error>Invalid UserID OR Password</Error>");
                    Logger.logdata(logforRpService, "Invalid UserID OR Password");
                }


            }
            catch (Exception ex)
            {
                str.Append("<Status>False</Status>");
                str.Append("<Error>Failed to connect database</Error>");
                Logger.logError(logforRpService, ex);
            }
            str.Append("</CampaignInfo>");

            doc.LoadXml(str.ToString());
            return doc;

        }
Beispiel #9
0
        public XmlDocument AddRecipient(string UserID, string Password, string EmailAddress, string FirstName, string LastName)
        {
            try
            {
                StringBuilder str = new StringBuilder();
                string Con = GetConnectionString(UserID, Password);
                LogStartInfo("AddRecipient", Con, UserID);
                if (Con.Trim().Length != 0 && EmailAddress.Trim().Length != 0)
                {
                    if (IsEmail(EmailAddress) == true)
                    {
                        str.Append("<RecipientInfo>");
                        ContactMasters contemail = ContactMaster.SelectByField("EmailAddress", EmailAddress, Con);

                        if (contemail.Count > 0)
                        {
                            str.Append("<RecipientId>" + contemail[0].ContactId.ToString() + "</RecipientId>");
                            str.Append("<Message> Already existd Email. Please enter Another valid EmailID</Message>");
                            Logger.logdata(logforRpService, "Already existd Email with EmailId" + EmailAddress);
                        }
                        else
                        {
                            //ContactMaster objContactMaster = new ContactMaster(Con);
                            //objContactMaster.EmailAddress = EmailID;
                            //objContactMaster.CreatedDate = DateTime.Now;
                            //objContactMaster.InsertWithDefaultValues(true);
                            //str.Append("<Message>Recipient Added Successfully</Message>");
                            //Logger.logdata(logforRpService, "Recipient Added Successfully");
                            ContactMaster objContactMaster = new ContactMaster(Con);
                            objContactMaster.EmailAddress = EmailAddress;
                            objContactMaster.EmailContentType = "Html";
                            objContactMaster.CreatedDate = DateTime.Now;
                            objContactMaster.FirstName = FirstName;
                            objContactMaster.LastName = LastName;
                            objContactMaster.IsActive = true;
                            objContactMaster.InsertWithDefaultValues(true);
                            Int64 ContactId = Convert.ToInt64(objContactMaster.ContactId);
                            //DataTable contactMaster = ContactMasterBase.SelectByEmailAddress("EmailAddress", EmailAddress, Con);
                            str.Append("<Message>Recipient Added Successfully</Message>");
                            str.Append("<RecipientId>" + ContactId.ToString() + "</RecipientId>");
                            Logger.logdata(logforRpService, "Recipient Added Successfully");
                        }

                    }
                    else
                    {
                        str.Append("<Message>Please Enter Valid Email Format ex:([email protected])</Message>");
                        Logger.logdata(logforRpService, "Please Enter Valid Email Format ex:([email protected])");
                    }
                }
                else
                {
                    str.Append("<Message>Please Enter Valid Inputs</Message>");
                    Logger.logdata(logforRpService, "Please Enter Valid Inputs");
                }
                LogEndInfo("AddRecipient");
                str.Append("</RecipientInfo>");
                doc.LoadXml(str.ToString());
            }
            catch (Exception ex)
            {
                Logger.logError(logforRpService, ex);
            }
            return doc;
        }
        protected void lbtnImport_Click(object sender, EventArgs e)
        {
            try
            {
                if (lstBoxListNames.Items.Count > 0 && Session["IEImportFileByteData"] != null)
                {
                    DataTable dtFieldMap = buildDatatableFromGrid();
                    if (dtFieldMap.Rows.Count > 0)
                    {
                        //to check whether email address field mapped to one field or more
                        for (int i = 0; i < GridFieldmap.Rows.Count; i++)
                        {
                            DropDownList ddlContactMasterFields = (DropDownList)this.GridFieldmap.Rows[i].FindControl("ddlContactMasterFields");
                            if (ddlContactMasterFields.SelectedItem.Value == "EmailAddress")
                                count++;
                        }
                        if (count > 1)
                            throw new Exception("Cannot map two fields to Email  Address");
                        int EmailaddressColumnNo = Convert.ToInt32(Session["IEEmailaddressColumnNo"]);
                        DropDownList ddlContactMaster = (DropDownList)this.GridFieldmap.Rows[EmailaddressColumnNo].FindControl("ddlContactMasterFields");
                        if (ddlContactMaster.Items.Count == 0)
                        {
                            if (ddlContactMaster.SelectedItem.Text != "Email Address")
                                throw new Exception("Please select email address fieldmap correctly");
                        }
                        ContactMaster objContactMaster = new ContactMaster(Connectionstring);
                        FileInfo fileInfo = new FileInfo(hidFilename.Value);

                        string filenameWithGUID = System.Guid.NewGuid().ToString() + fileInfo.Extension;

                        for (int i = 0; i < lstBoxListNames.Items.Count; i++)
                        {
                            //insert importjob
                            Int64 ImportJobID = objContactMaster.InsertImportJob(hidFilename.Value, ddlFileType.SelectedItem.Text, string.Empty, chkSendNotification.Checked, lstBoxListNames.Items[i].Value, txtEmailAddress.Text, Common.ImportStatus.Pending.ToString(), filenameWithGUID, chkHasColumnNames.Checked);
                            //convert fieldmap datatable to xml.
                            string fieldmapXMLString = buildXmlFromDatatable(dtFieldMap, "FieldMap");
                            //insert Fieldmap
                            objContactMaster.InsertFieldmap(ImportJobID, fieldmapXMLString);
                        }

                        // get import path.
                        string importFilePath = ConfigurationManager.AppSettings["ImportFilePath"].ToString();
                        DirectoryInfo dirlogInfo = new DirectoryInfo(importFilePath);
                        if (!dirlogInfo.Exists)
                            dirlogInfo.Create();

                        //create and save file in import path by reading it from stream saved in session variable.
                        using (FileStream writeStream = new FileStream(Path.Combine(importFilePath, filenameWithGUID), FileMode.Create, FileAccess.ReadWrite))
                        {
                            byte[] byteData = (byte[])Session["IEImportFileByteData"];
                            writeStream.Write(byteData, 0, byteData.Length);
                            writeStream.Close();
                            Session["IEImportFileByteData"] = null;
                        }
                        lblMsg.Visible = true;
                        lblMsg.ForeColor = System.Drawing.Color.Green;
                        lblMsg.Text = "Successfully imported file: " + hidFilename.Value;
                        ModalPopupExtenderShowImportInfo.Show();
                    }
                }
                else
                {
                    lblMsg.Visible = true;
                    lblMsg.ForeColor = System.Drawing.Color.Red;
                    lblMsg.Text = "Please select Get field map and try";
                    trShowSelectedFile.Style.Add("display", "none");
                    fileUploadCSV.Style.Add("display", "block");
                }
            }
            catch (Exception ex)
            {
                lblMsg.Visible = true;
                if (lblMsg.Text == string.Empty)
                    lblMsg.Text = "Please map Email Address field since it is mandatory";
                else
                    lblMsg.Text = "Error: " + ex.Message;
            }
            finally
            {
                Session["IESelectedFileDataTable"] = null;
                upnlMainmsg.Update();
            }
        }
        private void displayingCustomControlValues(string id, ContactMaster cont, ref string value)
        {
            try
            {
                switch (id.ToLower())
                {
                    case "customfield1":
                        value = cont.CustomField1;
                        break;
                    case "customfield2":
                        value = cont.CustomField2;
                        break;
                    case "customfield3":
                        value = cont.CustomField3;
                        break;
                    case "customfield4":
                        value = cont.CustomField4;
                        break;
                    case "customfield5":
                        value = cont.CustomField5;
                        break;
                    case "customfield6":
                        value = cont.CustomField6;
                        break;
                    case "customfield7":
                        value = cont.CustomField7;
                        break;
                    case "customfield8":
                        value = cont.CustomField8;
                        break;
                    case "customfield9":
                        value = cont.CustomField9;
                        break;
                    case "customfield10":
                        value = cont.CustomField10;
                        break;

                    case "customfield11":
                        value = cont.CustomField11;
                        break;
                    case "customfield12":
                        value = cont.CustomField12;
                        break;
                    case "customfield13":
                        value = cont.CustomField13;
                        break;
                    case "customfield14":
                        value = cont.CustomField14;
                        break;
                    case "customfield15":
                        value = cont.CustomField15;
                        break;
                    case "customfield16":
                        value = cont.CustomField16;
                        break;
                    case "customfield17":
                        value = cont.CustomField17;
                        break;
                    case "customfield18":
                        value = cont.CustomField18;
                        break;
                    case "customfield19":
                        value = cont.CustomField19;
                        break;
                    case "customfield20":
                        value = cont.CustomField20;
                        break;

                    case "customfield21":
                        value = cont.CustomField21;
                        break;
                    case "customfield22":
                        value = cont.CustomField22;
                        break;
                    case "customfield23":
                        value = cont.CustomField23;
                        break;
                    case "customfield24":
                        value = cont.CustomField24;
                        break;
                    case "customfield25":
                        value = cont.CustomField25;
                        break;
                    case "customfield26":
                        value = cont.CustomField26;
                        break;
                    case "customfield27":
                        value = cont.CustomField27;
                        break;
                    case "customfield28":
                        value = cont.CustomField28;
                        break;
                    case "customfield29":
                        value = cont.CustomField29;
                        break;
                    case "customfield30":
                        value = cont.CustomField30;
                        break;

                    case "customfield31":
                        value = cont.CustomField31;
                        break;
                    case "customfield32":
                        value = cont.CustomField32;
                        break;
                    case "customfield33":
                        value = cont.CustomField33;
                        break;
                    case "customfield34":
                        value = cont.CustomField34;
                        break;
                    case "customfield35":
                        value = cont.CustomField35;
                        break;
                    case "customfield36":
                        value = cont.CustomField36;
                        break;
                    case "customfield37":
                        value = cont.CustomField37;
                        break;
                    case "customfield38":
                        value = cont.CustomField38;
                        break;
                    case "customfield39":
                        value = cont.CustomField39;
                        break;
                    case "customfield40":
                        value = cont.CustomField40;
                        break;

                    case "customfield41":
                        value = cont.CustomField41;
                        break;
                    case "customfield42":
                        value = cont.CustomField42;
                        break;
                    case "customfield43":
                        value = cont.CustomField43;
                        break;
                    case "customfield44":
                        value = cont.CustomField44;
                        break;
                    case "customfield45":
                        value = cont.CustomField45;
                        break;
                    case "customfield46":
                        value = cont.CustomField46;
                        break;
                    case "customfield47":
                        value = cont.CustomField47;
                        break;
                    case "customfield48":
                        value = cont.CustomField48;
                        break;
                    case "customfield49":
                        value = cont.CustomField49;
                        break;
                    case "customfield50":
                        value = cont.CustomField50;
                        break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Populates the fields for multiple objects from the columns found in an open reader.
        /// </summary>
        ///
        /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param>
        ///
        /// <returns>Object of ContactMasters</returns>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			1/11/2010 2:53:38 PM		Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        internal static ContactMasters PopulateObjectsFromReaderWithCheckingReader(IDataReader rdr, DatabaseHelper oDatabaseHelper, string ConnectionString)
        {
            ContactMasters list = new ContactMasters();

            if (rdr.Read())
            {
                ContactMaster obj = new ContactMaster(ConnectionString);
                PopulateObjectFromReader(obj, rdr);
                list.Add(obj);
                while (rdr.Read())
                {
                    obj = new ContactMaster(ConnectionString);
                    PopulateObjectFromReader(obj, rdr);
                    list.Add(obj);
                }
                oDatabaseHelper.Dispose();
                return list;
            }
            else
            {
                oDatabaseHelper.Dispose();
                return null;
            }
        }
Beispiel #13
0
        private void DisplayCustomControlValues(ContactMaster contact)
        {
            //alCustonFields
            DataTable dt = ManageFieldsBase.SelectCustomFields(connectionString);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                alCustonFields.Add(dt.Rows[i]["ContactFieldName"].ToString());
                if (dt.Rows[i]["FieldType"].ToString().ToLower() == "text box")
                {

                }
                if (dt.Rows[i]["FieldType"].ToString().ToLower() == "check box")
                {
                    switch (dt.Rows[i]["FieldName"].ToString())
                    {
                        case "Facebook":
                            //chkFacebook.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkFacebook.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkFacebook.Checked = true;
                                else
                                    chkFacebook.Checked = false;
                            }
                            break;
                        case "You News":
                            //chkAMMNews.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkYNews.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkYNews.Checked = true;
                                else
                                    chkYNews.Checked = false;
                            }
                            break;
                        case "Scholarship Information":
                            //chkScholarshipInfo.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkScholarshipInfo.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkScholarshipInfo.Checked = true;
                                else
                                    chkScholarshipInfo.Checked = false;
                            }
                            break;
                        case "Major/Academic Information":
                            //chkMajorInfo.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkMajorInfo.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkMajorInfo.Checked = true;
                                else
                                    chkMajorInfo.Checked = false;
                            }
                            break;
                        case "Student Blogs":
                            //chkStudentBlogs.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkStudentBlogs.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkStudentBlogs.Checked = true;
                                else
                                    chkStudentBlogs.Checked = false;
                            }
                            break;
                        case "Student Videos":
                            //chkStudentVideos.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkStudentVideos.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkStudentVideos.Checked = true;
                                else
                                    chkStudentVideos.Checked = false;
                            }
                            break;
                    }
                }
                if (dt.Rows[i]["FieldType"].ToString().ToLower() == "drop down list")
                {
                    switch (dt.Rows[i]["FieldName"].ToString())
                    {
                        case "Intended Major":
                            dtFieldsProps = ManageFieldsPropertyBase.SelectByFields(connectionString, "FieldId", Convert.ToInt32(dt.Rows[i]["FieldId"]));
                            for (int j = 0; j < dtFieldsProps.Rows.Count; j++)
                            {
                                ListItem item = new ListItem(dtFieldsProps.Rows[j]["Item"].ToString(), dtFieldsProps.Rows[j]["value"].ToString());
                                ddlMajor.Items.Add(item);
                            }
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            try
                            {
                                ListItem li = ddlMajor.Items.FindByValue(value);
                                if (li != null)
                                {
                                    li.Selected = true;
                                    hddIntendedMajor.Value = value.ToString();
                                }
                                else
                                {
                                    //ddlMajor.SelectedItem.Text = "--Select--";
                                    hddIntendedMajor.Value = "--Select--";
                                }
                                ddlMajor.Items.Insert(0, litem);
                            }
                            catch { }
                            break;

                    }
                }
                if (dt.Rows[i]["FieldType"].ToString().ToLower() == "radio button list")
                {
                    switch (dt.Rows[i]["FieldName"].ToString())
                    {
                        case "Can we contact you by text message?":
                            dtFieldsProps = ManageFieldsPropertyBase.SelectByFields(connectionString, "FieldId", Convert.ToInt32(dt.Rows[i]["FieldId"]));
                            //for (int j = 0; j < dtFieldsProps.Rows.Count; j++)
                            //{
                            //    ListItem item = new ListItem(dtFieldsProps.Rows[j]["Item"].ToString(), dtFieldsProps.Rows[j]["value"].ToString());
                            //    ddlMajor.Items.Add(item);
                            //}
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            try
                            {
                                ListItem li = RBLtextmsg.Items.FindByText(value);
                                if (li != null)
                                {
                                    li.Selected = true;
                                    hdRBLtextmsg.Value = value.ToString();
                                }
                            }
                            catch { }
                            break;

                    }
                }
            }
        }
        /// <summary>
        /// This method will get row(s) from the database using the value of the field specified 
        /// along with the details of the child table.
        /// </summary>
        ///
        /// <param name="pk" type="ContactMasterPrimaryKey">Primary Key information based on which data is to be fetched.</param>
        ///
        /// <returns>object of class ContactMaster</returns>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			1/11/2010 2:53:38 PM				Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        public static ContactMaster SelectOneWithUnSubscribeDetailsUsingContactID(ContactMasterPrimaryKey pk, String ConnectionString)
        {
            DatabaseHelper oDatabaseHelper = new DatabaseHelper(ConnectionString);
            bool ExecutionState = false;
            ContactMaster obj=null;

            // Pass the values of all key parameters to the stored procedure.
            System.Collections.Specialized.NameValueCollection nvc = pk.GetKeysAndValues();
            foreach (string key in nvc.Keys)
            {
                oDatabaseHelper.AddParameter("@" + key,nvc[key] );
            }

            // The parameter '@ErrorCode' will contain the status after execution of the stored procedure.
            oDatabaseHelper.AddParameter("@ErrorCode", -1, System.Data.ParameterDirection.Output);

            IDataReader dr=oDatabaseHelper.ExecuteReader("sp_ContactMaster_SelectOneWithUnSubscribeDetailsUsingContactID", ref ExecutionState);
            if (dr.Read())
            {
                obj= new ContactMaster(ConnectionString);
                PopulateObjectFromReader(obj,dr);

                dr.NextResult();

                //Get the child records.
                obj.UnSubscribeDetails=UnSubscribeDetail.PopulateObjectsFromReader(dr,ConnectionString);
            }
            dr.Close();
            oDatabaseHelper.Dispose();
            return obj;
        }
Beispiel #15
0
 protected void lbtnMultipleDeleteYes_Click(object sender, EventArgs e)
 {
     try
     {
         if (grdReceipients.Rows.Count > 0)
         {
             //Get contact Selection
             rememberContactSelection("grdaddchkSelectContact", "lblContactId", grdReceipients, "Checkedall");
             if (ViewState["SelectedContacts"] != null)
             {
                 StringBuilder strbDeletedContacts = new StringBuilder();
                 //adding selected contatIds to stringbuilder
                 for (int i = 0; i < contactsSelected.Count; i++)
                 {
                     strbDeletedContacts.Append(contactsSelected[i] + ", ");
                 }
                 strbDeletedContacts.Remove(strbDeletedContacts.Length - 2, 1);
                 ContactMaster ContMaster = new ContactMaster(ConnectionString);
                 ContMaster.RemoveMultipleContacts(strbDeletedContacts.ToString());
                 ViewState["SelectedContacts"] = null;
                 hdContacts.Value = "false";
                 hdrchkselected.Clear();
                 lblMsg.Text = "Contact(s) Deleted  with ids: " + strbDeletedContacts.ToString();
                 flagreset = true;
                 if (txtSearch.Text != "")
                 {
                     SearchCriteria(0);
                 }
                 else
                 {
                     flagreset = false;
                     if (ddlFilterByStatus.SelectedItem.Text != "--Select--")
                         bindGridFilteredContacts("sort", 0);
                     else
                         bindGridNew("", 0);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         lblMsg.Style.Add("color", "red");
         lblMsg.Text = ex.Message;
         throw ex;
     }
 }
Beispiel #16
0
 public void deleteRecipient()
 {
     try
     {
         if (hdfield.Value != "0")
         {
             flagreset = true;
             //This is the new  logic developed by ganesh on 29dec09
             ContactMaster objContactMaster = new ContactMaster(ConnectionString);
             //delete the contact from contactmaster and listcontactmaster table and insert a new record in contacdeleted table.
             objContactMaster.deleteContactFromContactMasterAndListContactMaster(Convert.ToInt64(hdfield.Value));
             ContactMasterPrimaryKey pk = new ContactMasterPrimaryKey(Convert.ToInt64(hdfield.Value));
             ContactMaster contMasterDeleted = ContactMaster.SelectOne(pk, ConnectionString);
             lblMsg.Text = string.Format("Succesfully deleted contact with id: {0}", hdfield.Value);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #17
0
        private void DisplayCustomControlValues(ContactMaster contact)
        {
            //alCustonFields
            DataTable dt = ManageFieldsBase.SelectCustomFields(connectionString);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                alCustonFields.Add(dt.Rows[i]["ContactFieldName"].ToString());
                if (dt.Rows[i]["FieldType"].ToString().ToLower() == "text box")
                {
                    switch (dt.Rows[i]["FieldName"].ToString())
                    {
                        case "Apt/Suite":
                            //txtApt.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            txtApt.Text = dt.Rows[i]["DefaultValue"].ToString();
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            txtApt.Text = value;
                            break;
                        case "Middle Name":
                            //txtMName.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            txtMName.Text = dt.Rows[i]["DefaultValue"].ToString();
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            txtMName.Text = value;
                            break;
                    }
                }
                if (dt.Rows[i]["FieldType"].ToString().ToLower() == "check box")
                {
                    switch (dt.Rows[i]["FieldName"].ToString())
                    {
                        case "Facebook":
                            //chkFacebook.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkFacebook.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkFacebook.Checked = true;
                                else
                                    chkFacebook.Checked = false;
                            }
                            break;
                        case "AMM U News":
                            //chkAMMNews.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkAMMNews.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkAMMNews.Checked = true;
                                else
                                    chkAMMNews.Checked = false;
                            }
                            break;
                        case "Scholarship Information":
                            //chkScholarshipInfo.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkScholarshipInfo.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkScholarshipInfo.Checked = true;
                                else
                                    chkScholarshipInfo.Checked = false;
                            }
                            break;
                        case "Major/Academic Information":
                            //chkMajorInfo.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkMajorInfo.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkMajorInfo.Checked = true;
                                else
                                    chkMajorInfo.Checked = false;
                            }
                            break;
                        case "Student Blogs":
                            //chkStudentBlogs.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkStudentBlogs.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkStudentBlogs.Checked = true;
                                else
                                    chkStudentBlogs.Checked = false;
                            }
                            break;
                        case "Student Videos":
                            //chkStudentVideos.ID = dt.Rows[i]["ContactFieldName"].ToString();
                            if (dt.Rows[i]["DefaultValue"].ToString() != "")
                                chkStudentVideos.Checked = Convert.ToBoolean(dt.Rows[i]["DefaultValue"]);
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            if (value != null)
                            {
                                if (value.ToLower() == "true")
                                    chkStudentVideos.Checked = true;
                                else
                                    chkStudentVideos.Checked = false;
                            }
                            break;
                    }
                }
                if (dt.Rows[i]["FieldType"].ToString().ToLower() == "drop down list")
                {
                    switch (dt.Rows[i]["FieldName"].ToString())
                    {
                        case "Major":
                            dtFieldsProps = ManageFieldsPropertyBase.SelectByFields(connectionString, "FieldId", Convert.ToInt32(dt.Rows[i]["FieldId"]));
                            for (int j = 0; j < dtFieldsProps.Rows.Count; j++)
                            {
                                ListItem item = new ListItem(dtFieldsProps.Rows[j]["Item"].ToString(), dtFieldsProps.Rows[j]["value"].ToString());
                                ddlMajor.Items.Add(item);
                            }
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            try
                            {
                                ListItem li = ddlMajor.Items.FindByText(value);
                                if (li != null)
                                {
                                    li.Selected = true;
                                    hddMajor.Value = value.ToString();
                                }
                                else
                                {
                                    //ddlMajor.SelectedItem.Text = "--Select--";
                                    hddMajor.Value = "--Select--";
                                }
                                ddlMajor.Items.Insert(0, litem);
                            }
                            catch { }
                            break;
                        case "Activities":
                            dtFieldsProps = ManageFieldsPropertyBase.SelectByFields(connectionString, "FieldId", Convert.ToInt32(dt.Rows[i]["FieldId"]));
                            for (int j = 0; j < dtFieldsProps.Rows.Count; j++)
                            {
                                ListItem item = new ListItem(dtFieldsProps.Rows[j]["Item"].ToString(), dtFieldsProps.Rows[j]["value"].ToString());
                                ddlActivities.Items.Add(item);
                            }

                            ddlActivities.DataSource = dtFieldsProps;
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            try
                            {
                                ListItem li = ddlActivities.Items.FindByText(value);
                                if (li != null)
                                {
                                    li.Selected = true;
                                    hddActivities.Value = value.ToString();
                                }
                                else
                                {
                                    //ddlActivities.Items.Insert(0, litem);
                                    hddActivities.Value = "--Select--";
                                }
                                ddlActivities.Items.Insert(0, litem);
                            }
                            catch { }
                            break;
                        case "Sports":
                            dtFieldsProps = ManageFieldsPropertyBase.SelectByFields(connectionString, "FieldId", Convert.ToInt32(dt.Rows[i]["FieldId"]));
                            for (int j = 0; j < dtFieldsProps.Rows.Count; j++)
                            {
                                ListItem item = new ListItem(dtFieldsProps.Rows[j]["Item"].ToString(), dtFieldsProps.Rows[j]["value"].ToString());
                                ddlSports.Items.Add(item);
                            }
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            try
                            {
                                ListItem li = ddlSports.Items.FindByText(value);
                                if (li != null)
                                {
                                    li.Selected = true;
                                    hddSports.Value = value.ToString();
                                }
                                else
                                {
                                    //ddlSports.SelectedItem.Text = "--Select--";
                                    hddSports.Value = "--Select--";
                                }
                                ddlSports.Items.Insert(0, litem);
                            }
                            catch { }
                            break;
                    }
                }
            }
        }
        public DataTable ImportRecordsToContactMaster(DataTable dtContacts, DataTable dtFieldMap, DataRow dr)
        {
            try
            {
                Logger.logdata(logforimportrecipients, "************** in ImportRecordsToContactMaster(..) method **************");
                Logger.logdata(logforimportrecipients, string.Format("ImportRecordsToContactMaster(..) has been started at {0}", DateTime.Now.ToString()));

                ContactMaster objContactMaster = new ContactMaster(connectionString);
                //convert csv datatable to xml.
                string contactmasterXMLString = buildXmlFromDatatable(dtContacts, "ContactMaster");
                //Batch insert and update contacts to contactmaster table and
                //save the return values in a datatable which contains contactIds of inserted and updated rows in contactmaster table.
                DataTable dtContactMasterData = objContactMaster.InsertOrUpdateContactMaster(Convert.ToInt64(dr["ID"].ToString()), contactmasterXMLString, Convert.ToInt32(dr["ListID"]), IsActiveField);

                return dtContactMasterData;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["PURL"] != null && Request.QueryString["Username"] != null)
            {
                //get cleint database credentials.
                userName = Request.QueryString["Username"].ToString();
                ProfileBase objProfileBase = ProfileBase.Create(userName, true);
                string dbName = objProfileBase.GetPropertyValue("DBName").ToString();
                string dbUserID = objProfileBase.GetPropertyValue("DBUserID").ToString();
                string dbPassword = objProfileBase.GetPropertyValue("DBPassword").ToString();
                string dbServerName = objProfileBase.GetPropertyValue("DBServerName").ToString();

                connectionString =
                   string.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3};Pooling=True",
                                 dbServerName, dbName, dbUserID, dbPassword);
                ConnectionStringHelper.ConStr = connectionString;

                purl = Request.QueryString["PURL"];

                if (!IsPostBack)
                {
                    //Check first in AMM Adv.(RecipientTable) then Search in 1Point Realted Database
                    #region 1Point
                    //Get the Contact Id, Based on ContactId get Recent Sent Mailing Id from(MailSent Table), Related CampaignId

                    //Checking PURL in 1point
                    ContactMaster objContactMaster = new ContactMaster(connectionString);
                    DataTable tblContacts = objContactMaster.GetContactByPURLandMailingID(purl, connectionString);
                    #endregion

                    #region AMM_Adv. (Recipent Table)

                    //Checking PURL in RecipientTable(AMM Adv.Data)
                    DataTable tblRecipientMaster = objContactMaster.GetContactByPURLandMailingIDFromRecipientMaster(purl, connectionString);

                    #endregion
                    string ContactId = string.Empty;
                    string MailingID = string.Empty;
                    string CompaignId = string.Empty;

                    if (tblRecipientMaster.Rows.Count > 0) //AMM Adv.
                    {
                        //As pragnesh said on 25thOct12 if you get empty values in MailingID,CompaignId bellow then use CampaignID=317&CampID=1

                        ContactId = tblRecipientMaster.Rows[0]["ContactId"].ToString();
                        MailingID = (tblRecipientMaster.Rows[0]["MailingID"].ToString().Trim().Length > 0) ? tblRecipientMaster.Rows[0]["MailingID"].ToString() : "317";
                        CompaignId = (tblRecipientMaster.Rows[0]["CampaignID"].ToString().Trim().Length > 0) ? tblRecipientMaster.Rows[0]["CampaignID"].ToString() : "1";
                        string weelockLink = "http://mta1.1pointinteractive.com/Marketer_EmailTracker/WheelockForm.aspx?ContactID=" + ContactId + "&CampaignID=" + MailingID + "&CampID=" + CompaignId + "&Username=wheelock&direct=yes";
                        Response.Redirect(weelockLink);
                    }
                    else if (tblContacts.Rows.Count > 0)  //1Point
                    {
                        ContactId = tblContacts.Rows[0]["ContactId"].ToString();
                        MailingID = tblContacts.Rows[0]["CampaignID"].ToString();
                        CompaignId = tblContacts.Rows[0]["AssignedCampaignID"].ToString();
                        string weelockLink = "http://mta1.1pointinteractive.com/Marketer_EmailTracker/WheelockForm.aspx?ContactID=" + ContactId + "&CampaignID=" + MailingID + "&CampID=" + CompaignId + "&Username=wheelock&direct=no";
                        Response.Redirect(weelockLink);
                    }
                    else
                    {
                        Response.Redirect("http://www.mywheelock.com/v1/pagenotfound.htm");
                    }

                }
            }
        }
Beispiel #20
0
        internal static ContactMasters PopulateelementsFromReader(IDataReader rdr, string ConnectionString)
        {
            ContactMasters list = new ContactMasters();

            while (rdr.Read())
            {
                ContactMaster obj = new ContactMaster(ConnectionString);
                PopulateelementFromReader(obj, rdr);
                list.Add(obj);
            }
            return list;
        }
        //when editing to display the values
        private void DisplayCustomControlValues(ContactMaster contact)
        {
            try
            {
                for (int i = 0; i < pnlCustomControls.Controls.Count; i++)
                {
                    string value = string.Empty;
                    if (pnlCustomControls.Controls[i].ToString().ToLower().Contains("textbox"))
                    {
                        TextBox tbx = (TextBox)pnlCustomControls.Controls[i];
                        displayingCustomControlValues(tbx.ID, contact, ref value);
                        string s = tbx.Text;
                        tbx.Text = value;
                        string r = tbx.Text;
                        if (tbx.Text == "")
                            tbx.Text = s;
                        else
                            tbx.Text = value;
                    }
                    if (pnlCustomControls.Controls[i].ToString().ToLower().Contains("checkbox"))
                    {
                        CheckBox cbx = (CheckBox)pnlCustomControls.Controls[i];
                        displayingCustomControlValues(cbx.ID, contact, ref value);
                        if (value != null)
                        {
                            if (value.ToLower() == "true")
                                cbx.Checked = true;
                            else
                                cbx.Checked = false;
                        }
                    }
                    if (pnlCustomControls.Controls[i].ToString().ToLower().Contains("dropdownlist"))
                    {
                        DropDownList ddl = (DropDownList)pnlCustomControls.Controls[i];
                        displayingCustomControlValues(ddl.ID, contact, ref value);
                        try
                        {
                            ListItem li = ddl.Items.FindByValue(value);
                            if (li != null)
                            {
                                li.Selected = true;
                            }
                            else
                            {
                                ddl.SelectedItem.Text = "--Select--";
                            }
                        }
                        catch
                        {

                        }

                    }
                    if (pnlCustomControls.Controls[i].ToString().ToLower().Contains("table"))
                    {
                        //to find out the radion button list from table
                        RadioButtonList rbl = (RadioButtonList)pnlCustomControls.Controls[i].Controls[0].Controls[1].Controls[0];
                        displayingCustomControlValues(rbl.ID, contact, ref value);
                        try
                        {
                            if (value != null)
                            {
                                ListItem li = rbl.Items.FindByText(value);
                                ListItem liValue = rbl.Items.FindByValue(value);
                                if (li != null)
                                {
                                    li.Selected = true;
                                }
                                else if (liValue != null)
                                {
                                    liValue.Selected = true;
                                }
                                else
                                {
                                    rbl.SelectedIndex = -1;
                                }
                            }
                        }
                        catch
                        {

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void DisplayCustomControlValues(ContactMaster contact)
        {
            //alCustonFields
            DataTable dt = ManageFieldsBase.SelectCustomFields(connectionString);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                alCustonFields.Add(dt.Rows[i]["ContactFieldName"].ToString());
                if (dt.Rows[i]["FieldType"].ToString().ToLower() == "text box")
                {
                    switch (dt.Rows[i]["FieldName"].ToString().ToLower())
                    {
                        case "lettercode":
                            hdLetterCode.Value = dt.Rows[i]["DefaultValue"].ToString();
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            hdLetterCode.Value = value;
                            break;
                        case "eid":
                            hdEID.Value = dt.Rows[i]["DefaultValue"].ToString();
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            hdEID.Value = value;
                            break;
                        case "rep":
                            hdRep.Value = dt.Rows[i]["DefaultValue"].ToString();
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            hdRep.Value = value;
                            break;
                        case "purl":
                            hdRep.Value = dt.Rows[i]["DefaultValue"].ToString();
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            hdRep.Value = value;
                            purlValue = value;
                            break;
                        case "parent/guardian email":
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            txtParentEmail.Text = value;
                            break;
                    }
                }

                if (dt.Rows[i]["FieldType"].ToString().ToLower() == "drop down list")
                {
                    switch (dt.Rows[i]["FieldName"].ToString().ToLower())
                    {
                        case "intended major":
                            dtFieldsProps = ManageFieldsPropertyBase.SelectByFields(connectionString, "FieldId", Convert.ToInt32(dt.Rows[i]["FieldId"]));
                            for (int j = 0; j < dtFieldsProps.Rows.Count; j++)
                            {
                                ListItem item = new ListItem(dtFieldsProps.Rows[j]["Item"].ToString(), dtFieldsProps.Rows[j]["value"].ToString());
                                ddlMajor.Items.Add(item);
                            }
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            try
                            {
                                ListItem li = ddlMajor.Items.FindByValue(value);
                                if (li != null)
                                {
                                    li.Selected = true;
                                    hddIntendedMajor.Value = value.ToString();
                                }
                                else
                                {
                                    //ddlMajor.SelectedItem.Text = "--Select--";
                                    hddIntendedMajor.Value = "--Select--";
                                }
                                ddlMajor.Items.Insert(0, litem);
                            }
                            catch { }
                            break;

                        case "sport":
                            dtFieldsProps = ManageFieldsPropertyBase.SelectByFields(connectionString, "FieldId", Convert.ToInt32(dt.Rows[i]["FieldId"]));
                            for (int j = 0; j < dtFieldsProps.Rows.Count; j++)
                            {
                                ListItem item = new ListItem(dtFieldsProps.Rows[j]["Item"].ToString(), dtFieldsProps.Rows[j]["value"].ToString());
                                ddlSports.Items.Add(item);
                            }
                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            try
                            {
                                ListItem li = ddlSports.Items.FindByValue(value);
                                if (li != null)
                                {
                                    li.Selected = true;
                                    hddSports.Value = value.ToString();
                                }
                                else
                                {
                                    //ddlSports.SelectedItem.Text = "--Select--";
                                    hddSports.Value = "--Select--";
                                }
                                ddlSports.Items.Insert(0, litem);
                            }
                            catch { }
                            break;
                    }
                }
                if (dt.Rows[i]["FieldType"].ToString().ToLower() == "radio button list")
                {
                    switch (dt.Rows[i]["FieldName"].ToString().ToLower())
                    {
                        case "can we contact you by text message?":
                            dtFieldsProps = ManageFieldsPropertyBase.SelectByFields(connectionString, "FieldId", Convert.ToInt32(dt.Rows[i]["FieldId"]));

                            displayingCustomControlValues(dt.Rows[i]["ContactFieldName"].ToString(), contact, ref value);
                            try
                            {
                                ListItem li = RBLtextmsg.Items.FindByText(value);
                                if (li != null)
                                {
                                    li.Selected = true;
                                    hdRBLtextmsg.Value = value.ToString();
                                }
                            }
                            catch { }
                            break;

                    }
                }
            }
        }
        //add recipient to selected lists
        public void SaveRecipient()
        {
            try
            {
                //collect selected lists, it is optional.
                foreach (ListItem item in lstBoxListNames.Items)
                {
                    list.Add(item.Value);
                }
                //create new contact, initializing new object.
                contactBase = new ContactMaster(ConnectionString);
                contactBase.FirstName = txtFirstName1.Text;
                contactBase.LastName = txtLastName1.Text;
                contactBase.EmailAddress = txtEmailAddress1.Text;
                contactBase.Address1 = txtAddress11.Text;
                contactBase.Address2 = txtAddress21.Text;
                contactBase.City = txtCity.Text;
                contactBase.Country = txtCountry.Text;
                contactBase.EmailContentType = ddlEmailContentType.SelectedItem.Text;
                contactBase.Fax = txtFax.Text;
                if (ddlGender.SelectedItem.Text != "--Select--")
                {
                    contactBase.Gender = ddlGender.SelectedItem.Text;
                }
                else
                {
                    contactBase.Gender = null;
                }
                contactBase.HomePhone = txtHomePhone.Text;
                if (ddlMaritalStatus.SelectedItem.Text != "--Select--")
                {
                    contactBase.MaritalStatus = ddlMaritalStatus.SelectedItem.Text;
                }
                else
                {
                    contactBase.MaritalStatus = null;
                }
                contactBase.MobilePhone = txtMobilePhone.Text;
                contactBase.PostalCode = txtPostalCode.Text;
                contactBase.State = txtState.Text;
                contactBase.WorkPhone = txtWorkPhone.Text;

                contactBase.IsActive = chkIsActive1.Checked;
                contactBase.IsVerified = chkMakeVerified1.Checked;

                //to get the values of the custom controls
                GetValuesOfCustomControls();

                //Edit Recipient
                if (Convert.ToInt64(Request.QueryString["id"]) > 0)
                {
                    ContactMasters contemail = ContactMaster.SelectByField("EmailAddress", txtEmailAddress1.Text, ConnectionString);
                    contMasters = ContactMaster.SelectByField("ContactId", Convert.ToInt64(Request.QueryString["id"]), ConnectionString);
                    if (contMasters[0].CreatedDate.ToString() == "")
                        contactBase.CreatedDate = DateTime.Now;
                    else
                        contactBase.CreatedDate = contMasters[0].CreatedDate;
                    contactBase.ModifiedDate = DateTime.Now;
                    if (contMasters.Count > 0)
                    {
                        List<ContactMaster> cm1 = contemail.ToList().FindAll(delegate(ContactMaster contact) { return (contact.IsDeleted == false || contact.IsDeleted == null); });
                        if (cm1.Count == 0)
                        {
                            update();
                            insert = false;
                            status = true;
                        }
                        else
                        {
                            List<ContactMaster> cm2 = cm1.FindAll(delegate(ContactMaster contact) { return (contact.ContactId == contMasters[0].ContactId); });
                            if (cm2.Count > 0)
                            {
                                update();
                                insert = false;
                                status = true;
                            }
                            else
                            {
                                statusmessage.Append(string.Format("Contact already exists with EmailAddress - {0}", txtEmailAddress1.Text));
                                lbMsg1.Text = statusmessage.ToString();
                                lbMsg1.ForeColor = System.Drawing.Color.Red;
                                lbMsg1.Visible = true;
                                status = false;
                            }
                        }
                    }
                }
                //Add New Recipient
                else
                {
                    //DataTable contselect = ContactMaster.SelectEmailAddressInNonDeletedContacts(ConnectionString, txtEmailAddress1.Text.ToString());

                    //The above line commented by Anwar to avoid duplicate mail ids(30/07/12)
                    ContactMasters contselect = ContactMaster.SelectByField("EmailAddress", txtEmailAddress1.Text, ConnectionString);
                    //Check email exist or not

                    if (contselect.Count == 0)
                    {
                        contactBase.CreatedDate = DateTime.Now;
                        contactBase.InsertWithDefaultValues(true);
                        contactID = Convert.ToInt64(contactBase.ContactId);
                        statusmessage.Append(string.Format("Contact has been inserted successfully. Email - {0}", txtEmailAddress1.Text));
                        lbMsg1.ForeColor = System.Drawing.Color.Green;
                        lbMsg1.Text = statusmessage.ToString();
                        lbMsg1.Visible = true;
                        checklistupdate();
                        ddlEmailContentType.SelectedItem.Text = contactBase.EmailContentType;
                        ddlGender.SelectedItem.Text = contactBase.Gender;
                        ddlMaritalStatus.SelectedItem.Text = contactBase.MaritalStatus;
                        insert = true;
                        status = true;
                    }
                    else
                    {
                        lbMsg1.ForeColor = System.Drawing.Color.Red;
                        statusmessage.Append(string.Format("Already existed Email - {0}", txtEmailAddress1.Text));
                        status = false;
                    }
                }
                lbMsg1.Text = statusmessage.ToString();
                lbMsg1.Visible = true;
                txtFirstName1.Text = contactBase.FirstName.ToString();
            }
            catch (Exception ex)
            {
                lbMsg1.Visible = true;
                lbMsg1.Style.Add("color", "Red");
                lbMsg1.Text = ex.Message;
            }
        }
        public XmlDocument AddMailingWithMinData(string UserID, string Password, string MailingName, string FromName, string FromAddress, string Subject, DataSet Recipients)
        {

            XmlDocument doc = new System.Xml.XmlDocument();
            StringBuilder str = new StringBuilder();
            StringBuilder unDeleverdInfo = new StringBuilder();
            bool isTargetListHavingEmailIds = false;
            List<string> emailColumns = new List<string>();
            emailColumns.Add("Email Address");
            emailColumns.Add("emailaddress");
            emailColumns.Add("email");
            emailColumns.Add("e-mail");
            emailColumns.Add("Email");
            emailColumns.Add("e-mailaddress");
            emailColumns.Add("emailaddress");
            emailColumns.Add("emailadd");
            emailColumns.Add("e-mailadd");
            emailColumns.Add("emailaddress");
            List<string> fnameColumns = new List<string>();
            fnameColumns.Add("firstname");
            fnameColumns.Add("first name");
            fnameColumns.Add("fname");
            List<string> lnameColumns = new List<string>();
            lnameColumns.Add("lastname");
            lnameColumns.Add("last name");
            lnameColumns.Add("lname");
            foreach (DataColumn clm in Recipients.Tables[0].Columns)
            {
                if (emailColumns.Contains(clm.ToString().ToLower()))
                {
                    Recipients.Tables[0].Columns[clm.ToString()].ColumnName = "EmailAddress";
                    isTargetListHavingEmailIds = true;
                }
                else if (fnameColumns.Contains(clm.ToString().ToLower()))
                    Recipients.Tables[0].Columns[clm.ToString()].ColumnName = "FirstName";
                else if (lnameColumns.Contains(clm.ToString().ToLower()))
                    Recipients.Tables[0].Columns[clm.ToString()].ColumnName = "LastName";
            }
            str.Append("<MailingInfo>");
            string ConnectionString = GetConnectionString(UserID, Password);

            string validEmailIds = string.Empty;
            string unsubEmailIds = string.Empty;
            string hardBounceEmailIds = string.Empty;
            string softBounceEmailIds = string.Empty;
            string duplicateEmailids = string.Empty;
            Hashtable contatcInfo = new Hashtable();
            if (ConnectionString.Trim().Length != 0)
            {
                LogStartInfo("AddMailingWithMinData", ConnectionString, UserID);
                Logger.logdata(logforRpService, "Input Paramiters :Mailing Name = " + MailingName + "; No.of Contacts=" + Recipients.Tables[0].Rows.Count);
                if (isTargetListHavingEmailIds)
                {
                    if (MailingName.Trim().Length != 0 && Recipients.Tables.Count > 0 && Recipients.Tables[0].Rows.Count > 0)
                    {
                        Int64 listid = 0;
                        ListMasterBase listMaster = null;
                        DataTable contacts = Recipients.Tables[0];

                        CampaignMasters camp = CampaignMaster.SelectByField("CampaignName", MailingName, ConnectionString);
                        if (camp.Count > 0)
                        {
                            str.Append("<Message>Mailing With Name " + MailingName + " Allready Exist,Please Enter Other Name</Message>");
                            Logger.logdata(logforRpService, "Mailing With Name " + MailingName + " Allready Exist,Please Enter Other Name");
                        }
                        else
                        {
                            #region TargetList
                            if (contacts.Rows.Count > 0)
                            {
                                //string[] EmailIds = contacts.AsEnumerable().Select(row => row.Field<string>("EmailAddress")).ToArray();                        
                                unDeleverdInfo.Append("<UndeliveredList>");
                                foreach (DataRow contact in contacts.Rows)
                                {
                                    ContactMasters contemail = ContactMaster.SelectByField("EmailAddress", contact["EmailAddress"].ToString(), ConnectionString);
                                    DataTable unSubDetails = new DataTable();
                                    DataTable contactMasters = ContactMaster.GetBouceStatusByEmailIds(ConnectionString, contact["EmailAddress"].ToString());
                                    if (contemail.Count > 0)
                                    {
                                        unSubDetails = UnSubscribeDetail.GetUnSubDetailsByContactId(ConnectionString, contemail[0].ContactId.ToString(), string.Empty);
                                    }
                                    if (unSubDetails.Rows.Count > 0)
                                    {
                                        unDeleverdInfo.Append("<Undelivered>");
                                        if (unSubDetails.Rows[0]["Reason"].ToString() == "GlobalUnSub")
                                        {
                                            unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                            unDeleverdInfo.Append("<RecipientStatus>Unsubscribe</RecipientStatus>");
                                            unsubEmailIds = unsubEmailIds + contact["EmailAddress"].ToString() + ";";
                                        }
                                        else if (unSubDetails.Rows[0]["Reason"].ToString() == "bad-mailbox" || unSubDetails.Rows[0]["Reason"].ToString() == "bad-domain")
                                        {
                                            unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                            unDeleverdInfo.Append("<RecipientStatus>HardBounce</RecipientStatus>");
                                            hardBounceEmailIds = hardBounceEmailIds + contact["EmailAddress"].ToString() + ";";
                                        }
                                        unDeleverdInfo.Append("</Undelivered>");
                                    }
                                    else if (contactMasters.Rows.Count > 0 && contactMasters.Rows[0]["IsActive"].ToString() == "False" && Convert.ToInt32(contactMasters.Rows[0]["SoftBounceCount"].ToString()) >= SoftBounceCount)
                                    {
                                        unDeleverdInfo.Append("<Undelivered>");
                                        unDeleverdInfo.Append("<EMailAddress>" + contact["EmailAddress"].ToString() + "</EMailAddress>");
                                        unDeleverdInfo.Append("<RecipientStatus>SoftBounce</RecipientStatus>");
                                        unDeleverdInfo.Append("</Undelivered>");
                                        softBounceEmailIds = softBounceEmailIds + contact["EmailAddress"].ToString() + ";";
                                    }
                                    else if (contemail.Count > 0 && contemail[0].EmailAddress.Trim().Length > 0)
                                    {
                                        try
                                        {
                                            if (contemail[0].IsActive == true)
                                            {

                                                if (!contatcInfo.ContainsKey(contemail[0].ContactId))
                                                {
                                                    contatcInfo.Add(contemail[0].ContactId, "");
                                                    validEmailIds = validEmailIds + contemail[0].EmailAddress + ";";
                                                }
                                                else
                                                    duplicateEmailids = duplicateEmailids + contemail[0].EmailAddress + ";";
                                                ContactMasterPrimaryKey pk = new ContactMasterPrimaryKey(Convert.ToInt64(contemail[0].ContactId.ToString()));
                                                ContactMaster objContactMaster = ContactMaster.SelectOne(pk, ConnectionString);

                                                #region Handling Custom fields

                                                foreach (DataColumn column in contacts.Columns)
                                                {
                                                    DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, ConnectionString);
                                                    string custField = "";
                                                    if (customFieldDt.Rows.Count > 0)
                                                    {
                                                        custField = customFieldDt.Rows[0]["ContactFieldName"].ToString();
                                                    }
                                                    else
                                                        custField = column.ColumnName;

                                                    if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString()))
                                                    {

                                                        switch (custField)
                                                        {
                                                            case "EmailAddress":
                                                                objContactMaster.EmailAddress = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "FirstName":
                                                                objContactMaster.FirstName = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "LastName":
                                                                objContactMaster.LastName = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "Address1":
                                                                objContactMaster.Address1 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "City":
                                                                objContactMaster.City = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "State":
                                                                objContactMaster.State = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "PostalCode":
                                                                objContactMaster.PostalCode = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "Country":
                                                                objContactMaster.Country = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "WorkPhone":
                                                                objContactMaster.WorkPhone = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "HomePhone":
                                                                objContactMaster.HomePhone = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "MobilePhone":
                                                                objContactMaster.MobilePhone = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField1":
                                                                objContactMaster.CustomField1 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField2":
                                                                objContactMaster.CustomField2 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField3":
                                                                objContactMaster.CustomField3 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField4":
                                                                objContactMaster.CustomField4 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField5":
                                                                objContactMaster.CustomField5 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField6":
                                                                objContactMaster.CustomField6 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField7":
                                                                objContactMaster.CustomField7 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField8":
                                                                objContactMaster.CustomField8 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField9":
                                                                objContactMaster.CustomField9 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField10":
                                                                objContactMaster.CustomField10 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField11":
                                                                objContactMaster.CustomField11 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField12":
                                                                objContactMaster.CustomField12 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField13":
                                                                objContactMaster.CustomField13 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField14":
                                                                objContactMaster.CustomField14 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField15":
                                                                objContactMaster.CustomField15 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField16":
                                                                objContactMaster.CustomField16 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField17":
                                                                objContactMaster.CustomField17 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField18":
                                                                objContactMaster.CustomField18 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField19":
                                                                objContactMaster.CustomField19 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField20":
                                                                objContactMaster.CustomField20 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField21":
                                                                objContactMaster.CustomField21 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField22":
                                                                objContactMaster.CustomField22 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField23":
                                                                objContactMaster.CustomField23 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField24":
                                                                objContactMaster.CustomField24 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField25":
                                                                objContactMaster.CustomField25 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField26":
                                                                objContactMaster.CustomField26 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField27":
                                                                objContactMaster.CustomField27 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField28":
                                                                objContactMaster.CustomField28 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField29":
                                                                objContactMaster.CustomField29 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField30":
                                                                objContactMaster.CustomField30 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField31":
                                                                objContactMaster.CustomField31 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField32":
                                                                objContactMaster.CustomField32 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField33":
                                                                objContactMaster.CustomField33 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField34":
                                                                objContactMaster.CustomField34 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField35":
                                                                objContactMaster.CustomField35 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField36":
                                                                objContactMaster.CustomField36 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField37":
                                                                objContactMaster.CustomField37 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField38":
                                                                objContactMaster.CustomField38 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField39":
                                                                objContactMaster.CustomField39 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField40":
                                                                objContactMaster.CustomField40 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField41":
                                                                objContactMaster.CustomField41 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField42":
                                                                objContactMaster.CustomField42 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField43":
                                                                objContactMaster.CustomField43 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField44":
                                                                objContactMaster.CustomField44 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField45":
                                                                objContactMaster.CustomField45 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField46":
                                                                objContactMaster.CustomField46 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField47":
                                                                objContactMaster.CustomField47 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField48":
                                                                objContactMaster.CustomField48 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField49":
                                                                objContactMaster.CustomField49 = contact[column.ColumnName].ToString();
                                                                break;
                                                            case "CustomField50":
                                                                objContactMaster.CustomField50 = contact[column.ColumnName].ToString();
                                                                break;
                                                        }
                                                    }


                                                }

                                                #endregion
                                                if (objContactMaster.Update() == true)
                                                {
                                                    //str.Append("<Message>Recipient Updated Successfully</Message>");
                                                }
                                                else
                                                {
                                                    //str.Append("<Error>Recipient  Update Failed</Error>");
                                                    Logger.logdata(logforRpService, "Recipient  Update Failed");
                                                }
                                            }

                                        }
                                        catch (Exception ex)
                                        {
                                            str.Append("<Error>Edit Contact: Problem at updating contact</Error>");
                                            Logger.logdata(logforRpService, "Update Contact :" + ex.Message);

                                        }

                                    }
                                    else if (contact["EmailAddress"] != null && contact["EmailAddress"].ToString().Trim().Length > 0)
                                    {
                                        try
                                        {
                                            ContactMaster objContactMaster = new ContactMaster(ConnectionString);
                                            objContactMaster.EmailAddress = contact["EmailAddress"].ToString();
                                            objContactMaster.EmailContentType = "Html";
                                            objContactMaster.CreatedDate = DateTime.Now;

                                            #region Handling Custom fields

                                            foreach (DataColumn column in contacts.Columns)
                                            {
                                                DataTable customFieldDt = ManageFieldsBase.SelectByField("FieldName", column.ColumnName, ConnectionString);
                                                string custField = "";
                                                if (customFieldDt.Rows.Count > 0)
                                                {
                                                    custField = customFieldDt.Rows[0]["ContactFieldName"].ToString();
                                                }
                                                else
                                                    custField = column.ColumnName;

                                                if (custField != "" && !string.IsNullOrEmpty(contact[column.ColumnName].ToString()))
                                                {
                                                    switch (custField)
                                                    {
                                                        case "EmailAddress":
                                                            objContactMaster.EmailAddress = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "FirstName":
                                                            objContactMaster.FirstName = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "LastName":
                                                            objContactMaster.LastName = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "Address1":
                                                            objContactMaster.Address1 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "City":
                                                            objContactMaster.City = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "State":
                                                            objContactMaster.State = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "PostalCode":
                                                            objContactMaster.PostalCode = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "Country":
                                                            objContactMaster.Country = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "WorkPhone":
                                                            objContactMaster.WorkPhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "HomePhone":
                                                            objContactMaster.HomePhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "MobilePhone":
                                                            objContactMaster.MobilePhone = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField1":
                                                            objContactMaster.CustomField1 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField2":
                                                            objContactMaster.CustomField2 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField3":
                                                            objContactMaster.CustomField3 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField4":
                                                            objContactMaster.CustomField4 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField5":
                                                            objContactMaster.CustomField5 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField6":
                                                            objContactMaster.CustomField6 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField7":
                                                            objContactMaster.CustomField7 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField8":
                                                            objContactMaster.CustomField8 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField9":
                                                            objContactMaster.CustomField9 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField10":
                                                            objContactMaster.CustomField10 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField11":
                                                            objContactMaster.CustomField11 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField12":
                                                            objContactMaster.CustomField12 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField13":
                                                            objContactMaster.CustomField13 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField14":
                                                            objContactMaster.CustomField14 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField15":
                                                            objContactMaster.CustomField15 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField16":
                                                            objContactMaster.CustomField16 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField17":
                                                            objContactMaster.CustomField17 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField18":
                                                            objContactMaster.CustomField18 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField19":
                                                            objContactMaster.CustomField19 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField20":
                                                            objContactMaster.CustomField20 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField21":
                                                            objContactMaster.CustomField21 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField22":
                                                            objContactMaster.CustomField22 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField23":
                                                            objContactMaster.CustomField23 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField24":
                                                            objContactMaster.CustomField24 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField25":
                                                            objContactMaster.CustomField25 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField26":
                                                            objContactMaster.CustomField26 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField27":
                                                            objContactMaster.CustomField27 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField28":
                                                            objContactMaster.CustomField28 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField29":
                                                            objContactMaster.CustomField29 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField30":
                                                            objContactMaster.CustomField30 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField31":
                                                            objContactMaster.CustomField31 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField32":
                                                            objContactMaster.CustomField32 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField33":
                                                            objContactMaster.CustomField33 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField34":
                                                            objContactMaster.CustomField34 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField35":
                                                            objContactMaster.CustomField35 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField36":
                                                            objContactMaster.CustomField36 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField37":
                                                            objContactMaster.CustomField37 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField38":
                                                            objContactMaster.CustomField38 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField39":
                                                            objContactMaster.CustomField39 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField40":
                                                            objContactMaster.CustomField40 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField41":
                                                            objContactMaster.CustomField41 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField42":
                                                            objContactMaster.CustomField42 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField43":
                                                            objContactMaster.CustomField43 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField44":
                                                            objContactMaster.CustomField44 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField45":
                                                            objContactMaster.CustomField45 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField46":
                                                            objContactMaster.CustomField46 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField47":
                                                            objContactMaster.CustomField47 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField48":
                                                            objContactMaster.CustomField48 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField49":
                                                            objContactMaster.CustomField49 = contact[column.ColumnName].ToString();
                                                            break;
                                                        case "CustomField50":
                                                            objContactMaster.CustomField50 = contact[column.ColumnName].ToString();
                                                            break;
                                                    }
                                                }


                                            }

                                            #endregion
                                            objContactMaster.IsActive = true;
                                            objContactMaster.InsertWithDefaultValues(true);
                                            Int64 ContactId = Convert.ToInt64(objContactMaster.ContactId);
                                            // ContactIds = ContactIds + ContactId + ",";

                                            if (!contatcInfo.ContainsKey(ContactId))
                                            {
                                                contatcInfo.Add(ContactId, "");
                                                validEmailIds = validEmailIds + contact["EmailAddress"].ToString() + ";";
                                            }
                                            else
                                                duplicateEmailids = duplicateEmailids + contact["EmailAddress"].ToString() + ";";

                                        }
                                        catch (Exception ex)
                                        {
                                            str.Append("<Error>Add New Contact: Problem at adding contact</Error>");
                                            Logger.logdata(logforRpService, "Add New Contact: " + ex.Message);

                                        }

                                    }

                                }
                                unDeleverdInfo.Append("</UndeliveredList>");

                            }

                            try
                            {

                                if (str.ToString().IndexOf("<Error>") == -1 && contatcInfo.Count > 0)
                                {

                                    listMaster = new ListMasterBase(ConnectionString);
                                    listMaster.ListName = "TL_" + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                                    listMaster.CreatedDate = System.DateTime.Now;
                                    listMaster.InsertWithDefaultValues(true);
                                    listid = Convert.ToInt64(listMaster.ListMasterID);
                                    Logger.logdata(logforRpService, "List Created,ListID = " + listid + "; ListName=" + listMaster.ListName);
                                    //ContactIds = ContactIds.Substring(0, ContactIds.Length - 1);
                                    //string[] selectContact = ContactIds.Split(',');
                                    if (listid > 0)
                                    {

                                        DataTable dtListContactMaster = new DataTable();
                                        dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string)));
                                        dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string)));
                                        dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string)));
                                        dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string)));
                                        dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool)));
                                        StringBuilder strbAddedContacts = new StringBuilder();

                                        foreach (DictionaryEntry item in contatcInfo)
                                        {
                                            DataRow rowListContactMaster = dtListContactMaster.NewRow();
                                            rowListContactMaster["ListMasterID"] = listid;
                                            rowListContactMaster["ContactId"] = item.Key;
                                            rowListContactMaster["CreatedDate"] = DateTime.Now.ToString();
                                            rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString();
                                            rowListContactMaster["IsActive"] = true;
                                            dtListContactMaster.Rows.Add(rowListContactMaster);
                                        }
                                        string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                                        string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                                        ListContactMaster.BulkCopy(dtListContactMaster, "ListContactMaster", SourceColumn, DestinationColumn, ConnectionString);
                                        Logger.logdata(logforRpService, "Added Given Contacts to Created List(ListId :" + listid + ")");

                                    }
                                }


                            }
                            catch (Exception ex)
                            {
                                str.Append("<Error>List: Problem at ListCreation contact</Error>");
                                Logger.logdata(logforRpService, "List: " + ex.Message);
                            }


                            #endregion

                            try
                            {
                                if (str.ToString().IndexOf("<Error>") == -1)
                                {
                                    MembershipUser objMembershipUser = Membership.GetUser(UserID);
                                    ProfileBase objProfileBase = ProfileBase.Create(UserID, true);

                                    CampaignMaster objCampaignMaster = new CampaignMaster(ConnectionString);
                                    objCampaignMaster.CampaignName = MailingName;
                                    objCampaignMaster.CampaignDescription = "";
                                    objCampaignMaster.FromAddress = FromAddress;
                                    objCampaignMaster.FromName = FromName;
                                    objCampaignMaster.ReplytoAddress = "";
                                    objCampaignMaster.ReplaytoName = "";
                                    objCampaignMaster.Subject = Subject;
                                    objCampaignMaster.TrackReads = true;//"1";
                                    objCampaignMaster.SelectCondition = listid.ToString();
                                    objCampaignMaster.TemplateId = 0;
                                    objCampaignMaster.ModifiedDate = DateTime.Now;
                                    objCampaignMaster.CreatedDate = DateTime.Now;
                                    objCampaignMaster.HTMLContent = "";
                                    objCampaignMaster.TextContent = "";
                                    objCampaignMaster.SuppressDomain = "";
                                    objCampaignMaster.UnsubscribeText = "If you no longer wish to receive these emails, simply click on the following link:";
                                    objCampaignMaster.UnsubscribeLinkText = "Unsubscribe";
                                    objCampaignMaster.SuppressSelection = "";
                                    objCampaignMaster.htmlHasUnsubLink = false;
                                    objCampaignMaster.txtHasUnsubLink = false;
                                    objCampaignMaster.AssignedCampaignID = 0;
                                    Int64 campaignMasterID = objCampaignMaster.insertCampainMaster(objCampaignMaster);
                                    Logger.logdata(logforRpService, "Mailing Inserted Successfully(Mailing Id:" + campaignMasterID + ")");
                                    if (campaignMasterID > 0)
                                    {
                                        CampaignJob objCampaignJob = new CampaignJob(ConnectionString);
                                        objCampaignJob.CampaignMasterID = campaignMasterID;
                                        objCampaignJob.CreatedDatetime = DateTime.Now;
                                        objCampaignJob.ScheduledDatetime = DateTime.Now;
                                        objCampaignJob.SendType = "IMMEDIATE";
                                        objCampaignJob.Status = 5;
                                        objCampaignJob.Insert();
                                    }
                                    str.Append("<Message>Mailing Inserted Succefully</Message>");
                                    str.Append("<MailingId>" + campaignMasterID.ToString() + "</MailingId>");
                                    str.Append("<MailingName>" + MailingName + "</MailingName>");
                                    str.Append("<ListID>" + listid + "</ListID>");

                                }
                                else
                                {
                                    str.Append("<Message>Mailing Sending Failed</Message>");
                                    Logger.logdata(logforRpService, "Mailing Sending Failed");

                                }
                            }
                            catch (Exception ex)
                            {
                                str.Append("<Message>Mailing Sending Failed,Problem At Scheduling The Mailing</Message>");
                                Logger.logdata(logforRpService, "Mailing Sending Failed:" + ex.Message);
                            }

                        }
                    }
                    else
                    {
                        str.Append("<Message>Please Enter Mailing Name and Ensure Mailing List File Is Not Empty</Message>");
                        Logger.logdata(logforRpService, "Empty Mailing Not Accepted and Ensure Mailing List File Is Not Empty");
                    }

                }
                else
                {
                    str.Append("<Message>No Email Address Field Found in Targeted List</Message>");
                    Logger.logdata(logforRpService, "No Email Address Field Found in Targeted List");
                }

            }
            else
            {
                str.Append("<Message>Please Enter Valid UserName and Password</Message>");
                Logger.logdata(logforRpService, "Invalid UserName or Password");
            }
            str.Append(unDeleverdInfo);
            str.Append("</MailingInfo>");
            doc.LoadXml(str.ToString());
            return doc;
        }