Ejemplo n.º 1
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;

        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        public XmlDocument AddList(string UserID, string Password, string ListName)
        {
            XmlDocument doc = new System.Xml.XmlDocument();
            StringBuilder str = new StringBuilder();
            str.Append("<ListsInsertInfo>");
            string ConnectionString = GetConnectionString(UserID, Password);
            ListMasters list = ListMaster.SelectByField("ListName", ListName, ConnectionString);
            if (list.Count > 0)
            {
                str.Append("<ListId>" + list[0].ListMasterID.ToString() + "</ListId>");
                str.Append("<Message> Already exists. Please enter other ListName</Message>");
            }
            else
            {
                ListMasterBase listMaster = new ListMasterBase(ConnectionString);
                listMaster.ListName = ListName;
                listMaster.CreatedDate = System.DateTime.Now;
                listMaster.InsertWithDefaultValues(true);

                Int64 listid = Convert.ToInt64(listMaster.ListMasterID);
                str.Append("<ListId>" + listid.ToString() + "</ListId>");
                str.Append("<Message> List Created Successfully.</Message>");
            }
            str.Append("</ListsInsertInfo>");
            doc.LoadXml(str.ToString());
            return doc;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Populates the fields of a single objects from the columns found in an open reader.
        /// </summary>
        /// <param name="obj" type="ListMaster">Object of ListMaster to populate</param>
        /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			11/6/2009 11:39:08 AM		Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        internal static void PopulateObjectFromReader(ListMasterBase obj,IDataReader rdr)
        {
            obj.ListMasterID = rdr.GetInt64(rdr.GetOrdinal(ListMasterFields.ListMasterID));
            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.ClientID)))
            {
                obj.ClientID = rdr.GetInt32(rdr.GetOrdinal(ListMasterFields.ClientID));
            }

            obj.ListName = rdr.GetString(rdr.GetOrdinal(ListMasterFields.ListName));
            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.ListDesc)))
            {
                obj.ListDesc = rdr.GetString(rdr.GetOrdinal(ListMasterFields.ListDesc));
            }
            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.ListCowner)))
            {
                obj.ListCowner = rdr.GetString(rdr.GetOrdinal(ListMasterFields.ListCowner));
            }
            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.TotalCount)))
            {
                obj.TotalCount = rdr.GetInt32(rdr.GetOrdinal(ListMasterFields.TotalCount));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.CreatedBy)))
            {
                obj.CreatedBy = rdr.GetInt32(rdr.GetOrdinal(ListMasterFields.CreatedBy));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.CreatedDate)))
            {
                obj.CreatedDate = rdr.GetDateTime(rdr.GetOrdinal(ListMasterFields.CreatedDate));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.ModifiedBy)))
            {
                obj.ModifiedBy = rdr.GetInt32(rdr.GetOrdinal(ListMasterFields.ModifiedBy));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.ModifiedDate)))
            {
                obj.ModifiedDate = rdr.GetDateTime(rdr.GetOrdinal(ListMasterFields.ModifiedDate));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.Active)))
            {
                obj.Active = rdr.GetBoolean(rdr.GetOrdinal(ListMasterFields.Active));
            }
            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.IsSegment)))
            {
                obj.IsSegment = rdr.GetBoolean(rdr.GetOrdinal(ListMasterFields.IsSegment));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.IsSeedList)))
            {
                obj.IsSeedList = rdr.GetBoolean(rdr.GetOrdinal(ListMasterFields.IsSeedList));
            }
            if (!rdr.IsDBNull(rdr.GetOrdinal(ListMasterFields.IsDeleted)))
            {
                obj.IsDeleted = rdr.GetBoolean(rdr.GetOrdinal(ListMasterFields.IsDeleted));
            }
        }
Ejemplo n.º 5
0
        private void updateSegmentDetails()
        {
            ListMasterBase listMaster = new ListMasterBase(ConnectionString);
                SegmentMasterBase segmentMaster = new SegmentMasterBase(ConnectionString);
                ListMasterPrimaryKey pk = new ListMasterPrimaryKey(Convert.ToInt64(hdfListId.Value));//hiddenEditID.Value));
                ListMaster listMasterNew = ListMaster.SelectOne(pk, ConnectionString);

                listMaster.ListMasterID = Convert.ToInt64(hdfListId.Value);
                listMaster.ListName = txtSegmentName.Text;
                listMaster.ListDesc = txtDescription.Text;
                listMaster.ModifiedDate = System.DateTime.Now;
                listMaster.CreatedDate = listMasterNew.CreatedDate;
                listMaster.IsSegment = true;
                listMaster.Update();

                segmentInfo = (DataTable)ViewState["SegementDetails"];
                segmentMaster.ListMasterID = Convert.ToInt64(hdfListId.Value);
                segmentMaster.SegmentName = txtSegmentName.Text;
                segmentMaster.SelectCondition = segmentInfo.Rows[0]["SelectCondition"].ToString();
                segmentMaster.SegmentFilter = segmentInfo.Rows[0]["SegmentFilter"].ToString();
                segmentMaster.Type = segmentInfo.Rows[0]["Type"].ToString();
                segmentMaster.Update();
                Response.Redirect("~/pages/segmentation.aspx?name=" + txtSegmentName.Text + "&mode=update");
        }
Ejemplo n.º 6
0
        private void createSegemnt(string SegmentType)
        {
            try
            {
                lblMainMsg.Text = string.Empty;
                ListMasterBase listMaster = new ListMasterBase(ConnectionString);
                SegmentMasterBase segmentMaster = new SegmentMasterBase(ConnectionString);
                ListContactMaster objListContactMaster = new ListContactMaster(ConnectionString);
                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("IsSegment", typeof(bool)));
                dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool)));
                List<string> contactids = new List<string>();
                contactids = (List<string>)Session["ContactId"];
                if (hdfListId.Value != "")
                {
                    bool isDeleted = objListContactMaster.DeleteAllContactsFromList(Convert.ToInt64(hdfListId.Value));
                    if (isDeleted)
                    {
                        foreach (string contactID in contactids)
                        {
                            DataRow rowListContactMaster = dtListContactMaster.NewRow();
                            rowListContactMaster["ListMasterID"] = hdfListId.Value;
                            rowListContactMaster["ContactId"] = contactID;
                            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);
                        ListMasterPrimaryKey pk = new ListMasterPrimaryKey(Convert.ToInt64(hdfListId.Value));
                        ListMaster listMasterNew = ListMaster.SelectOne(pk, ConnectionString);
                        listMaster.ListMasterID = Convert.ToInt64(hdfListId.Value);
                        listMaster.ListName = txtSegmentName.Text;
                        listMaster.ListDesc = txtDescription.Text;
                        listMaster.CreatedDate = listMasterNew.CreatedDate;
                        listMaster.ModifiedDate = System.DateTime.Now;
                        listMaster.IsSegment = true;
                        listMaster.Update();
                        segmentMaster.ListMasterID = Convert.ToInt64(hdfListId.Value);
                        segmentMaster.SegmentName = txtSegmentName.Text;
                        segmentMaster.SelectCondition = SelectedIds.Value.Substring(0, SelectedIds.Value.Length);
                        if (rbSegCamRecOnly.Checked)
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactFieldName\" onChange='QueryBuild(this);'");
                        else
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactFieldName\" onChange='ListQueryBuild(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorName\"", "\"ddlOperatorName\" onChange='getSearchKeys(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddllinkdate\"", "\"ddllinkdate\" onChange='linkDateRange(this);'");
                        segmentMaster.SegmentFilter = HtmlContent.Value;
                        segmentMaster.Type = SegmentType;
                        segmentMaster.Update();
                    }
                    Response.Redirect("~/pages/segmentation.aspx?name=" + txtSegmentName.Text + "&mode=update");
                }
                else
                {
                    if (rgdContacts.MasterTableView.Items.Count > 0)
                    {
                        listMaster.ListName = txtSegmentName.Text;
                        listMaster.ListDesc = txtDescription.Text;
                        listMaster.CreatedDate = System.DateTime.Now;
                        listMaster.IsSegment = true;
                        listMaster.InsertWithDefaultValues(true);
                        Int64 listid = Convert.ToInt64(listMaster.ListMasterID);

                        segmentMaster.ListMasterID = listid;
                        segmentMaster.SegmentName = txtSegmentName.Text;
                        segmentMaster.SelectCondition = SelectedIds.Value.Substring(0, SelectedIds.Value.Length);
                        if (rbSegCamRecOnly.Checked)
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactFieldName\" onChange='QueryBuild(this);'");
                        else
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactFieldName\" onChange='ListQueryBuild(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorName\"", "\"ddlOperatorName\" onChange='getSearchKeys(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddllinkdate\"", "\"ddllinkdate\" onChange='linkDateRange(this);'");
                        segmentMaster.SegmentFilter = HtmlContent.Value;
                        segmentMaster.Type = SegmentType;
                        segmentMaster.Insert();

                        foreach (string contactID in contactids)
                        {
                            DataRow rowListContactMaster = dtListContactMaster.NewRow();
                            rowListContactMaster["ListMasterID"] = listid;
                            rowListContactMaster["ContactId"] = contactID;
                            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);
                    }
                }
                Response.Redirect("~/pages/segmentation.aspx?name=" + txtSegmentName.Text + "&mode=create");
            }
            catch (Exception ex)
            {
                lblMainMsg.Text = "Error: " + ex.Message;
                rtsAddSegment.SelectedIndex = 0;
                rtsAddSegment.MultiPage.SelectedIndex = 0;
            }
        }
Ejemplo n.º 7
0
        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;
        }