예제 #1
0
        private void InsertBizphoneLeadToZoho()
        {
            string bizphone_LeadStatus   = string.Empty;
            string bizphone_ContactNo    = string.Empty;
            string bizphone_CallStatus   = string.Empty;
            string bizphone_RecordingUrl = string.Empty;
            string bizphone_CallDuration = string.Empty;
            string bizphone_Department   = string.Empty;
            string bizphone_Extn         = string.Empty;
            string bizphone_Description  = string.Empty;

            bizphone_LeadStatus   = sbizphone_LeadStatus;
            bizphone_ContactNo    = sbizphone_ContactNo;
            bizphone_CallStatus   = sbizphone_CallStatus;
            bizphone_RecordingUrl = sbizphone_RecordingUrl;
            bizphone_CallDuration = sbizphone_CallDuration;
            bizphone_Extn         = sbizphone_Extn;
            bizphone_Description  = sbizphone_Description;

            string modulename = "Leads";
            string methodname = "insertRecords";
            string recordId   = "";//= "508020000000332001";


            string uri = zohocrmurl + modulename + "/" + methodname + "?";
            /* Append your parameters here */
            string postContent = "scope=crmapi";

            bizphone_ContactNo = "0" + FormatContactNo(bizphone_ContactNo);
            postContent        = postContent + "&authtoken=********************";//Give your authtoken
            if (methodname.Equals("insertRecords") || methodname.Equals("updateRecords"))
            {
                postContent = postContent + "&xmlData=" + HttpUtility.UrlEncode("<Leads><row no=\"1\">" +
                                                                                "<FL val=\"Task Owner\">[email protected]</FL>" +
                                                                                "<FL val=\"Lead Source\">" + mleadsource + "</FL>" +
                                                                                "<FL val=\"Lead Status\">" + bizphone_LeadStatus + "</FL>" +
                                                                                "<FL val=\"Last Name\">.</FL>" +
                                                                                "<FL val=\"Phone1\">" + bizphone_ContactNo + "</FL>" +
                                                                                "<FL val=\"Contact No\">" + bizphone_ContactNo + "</FL>" +
                                                                                "<FL val=\"Biz Call Status\">" + bizphone_CallStatus + "</FL>" +
                                                                                "<FL val=\"Biz Recording URL\">" + bizphone_RecordingUrl + "</FL>" +
                                                                                "<FL val=\"Biz Call Duration\">" + bizphone_CallDuration + "</FL>" +
                                                                                "<FL val=\"Biz Attended By\">" + bizphone_Extn + "</FL>" +
                                                                                "<FL val=\"Description\">" + bizphone_Description + "</FL>" +
                                                                                "</row></Leads>");
            }
            if (methodname.Equals("updateRecords") || methodname.Equals("deleteRecords") || methodname.Equals("getRecordById"))
            {
                postContent = postContent + "&id=" + recordId;
            }

            try
            {
                string result = AccessCRM(uri, postContent);
                //return result;
                //return result;
                XmlDocument document = new XmlDocument();
                document.Load(new System.IO.StringReader(result));
                XmlNode node       = document.DocumentElement.SelectSingleNode("//FL");
                string  ZohoLeadID = node.InnerXml;     //ZOHO Return Lead ID.
                Guid    userID     = new Guid();
                userID = Guid.Empty;
                InsertLead(userID.ToString(), "", bizphone_ContactNo, ZohoLeadID, "Inbound Calls");
            }
            catch (Exception ex)
            {
                MCG_Email_SMS_Util.Email objEmail = new MCG_Email_SMS_Util.Email();
                objEmail.ShootMail_NonThread(MCG_Email_SMS_Util.Email.EmailServer.Amazon_CRM_Utility, MCG_Email_SMS_Util.Email.EmailShootFor.crm_in, "sto", "*****@*****.**", "Error while entering Bizphone lead to Zoho", ex.Message.ToString(), "");
                objEmail = null;
            }
        }
예제 #2
0
        private void InsertLeadToZoho()
        {
            string User_ID             = string.Empty;
            string LeadSource          = string.Empty;
            string FName               = string.Empty;
            string LName               = string.Empty;
            string Email               = string.Empty;
            string ContactNo           = string.Empty;
            string ParentContactNo     = string.Empty;
            string Address             = string.Empty;
            string AssessmentCompleted = string.Empty;
            string ProductCode         = string.Empty;
            string QuestionURL         = string.Empty;
            string ContactUSQuery      = string.Empty;
            string Description         = string.Empty;

            string PTGAttempts = string.Empty;

            User_ID             = sUser_ID;
            LeadSource          = sLeadSource;
            FName               = sFName;
            LName               = sLName;
            Email               = sEmail;
            ContactNo           = sContactNo;
            ParentContactNo     = sParentContactNo;
            Address             = sAddress;
            AssessmentCompleted = sAssessmentCompleted;
            ProductCode         = sProductCode;
            QuestionURL         = sQuestionURL;
            ContactUSQuery      = sContactUSQuery;
            Description         = sDescription;

            FName               = FName.Replace("&", " ");
            LName               = LName.Replace("&", " ");
            Address             = Address.Replace("&", "and");
            AssessmentCompleted = AssessmentCompleted.Replace("&", " ");
            ProductCode         = ProductCode.Replace("&", " ");
            QuestionURL         = QuestionURL.Replace("&", " ");
            ContactUSQuery      = ContactUSQuery.Replace("&", "and");
            Description         = Description.Replace("&", "and");

            if (LName == string.Empty)
            {
                LName = ".";
            }

            string sZohoID = CheckForZohoID(Email);

            //ContactNo = "0" + FormatContactNo(ContactNo);

            if (LeadSource == "Proceed To Guidance")
            {
                PTGAttempts = "1";
            }

            if (LeadSource == "Just Dial" || LeadSource == "Contact Us" || LeadSource == "Business Enquiries" || LeadSource == "FB Adds" || LeadSource == "Google Add-word" || LeadSource == "Youmint" || string.IsNullOrEmpty(sZohoID))
            {
                string modulename = "Leads";
                string methodname = "insertRecords";
                string recordId   = "";//= "508020000000332001";
                string uri        = zohocrmurl + modulename + "/" + methodname + "?";
                /* Append your parameters here */
                string postContent  = "scope=crmapi";
                string landing_page = "";
                string utm          = "";
                string edu_level    = "";

                if (LandingPage != string.Empty)
                {
                    landing_page = "<FL val=\"Landing Page\">" + LandingPage + "</FL>";
                }
                if (UTMParameters != string.Empty)
                {
                    utm = "<FL val=\"UTM Parameters\">" + UTMParameters + "</FL>";
                }
                if (EducationLevel != string.Empty)
                {
                    edu_level = "<FL val=\"Education Level\">" + EducationLevel + "</FL>";
                }

                postContent = postContent + "&authtoken=*********************";//Give your authtoken
                if (methodname.Equals("insertRecords") || methodname.Equals("updateRecords"))
                {
                    postContent = postContent + "&xmlData=" + HttpUtility.UrlEncode("<Leads><row no=\"1\">" +
                                                                                    "<FL val=\"Task Owner\">[email protected]</FL>" +
                                                                                    "<FL val=\"Lead Source\">" + LeadSource + "</FL>" +
                                                                                    "<FL val=\"Lead Status\">Open (O)</FL>" +
                                                                                    "<FL val=\"First Name\">" + FName + "</FL>" +
                                                                                    "<FL val=\"Last Name\">" + LName + "</FL>" +
                                                                                    "<FL val=\"Email\">" + Email + "</FL>" +
                                                                                    "<FL val=\"Phone1\">" + ContactNo + "</FL>" +
                                                                                    "<FL val=\"Contact No\">" + ContactNo + "</FL>" +
                                                                                    "<FL val=\"Parents Contact No\">" + ParentContactNo + "</FL>" +
                                                                                    "<FL val=\"Address\">" + Address + "</FL>" +
                                                                                    "<FL val=\"Assessment Completed\">" + AssessmentCompleted + "</FL>" +
                                                                                    "<FL val=\"Product Code\">" + ProductCode + "</FL>" +
                                                                                    "<FL val=\"Question Desc\">" + QuestionURL + "</FL>" +
                                                                                    "<FL val=\"Contact us Query\">" + ContactUSQuery + "</FL>" +
                                                                                    "<FL val=\"PTG Attempts\">" + PTGAttempts + "</FL>" +
                                                                                    "<FL val=\"Description\">" + Description + "</FL>" + landing_page + utm + edu_level +
                                                                                    "</row></Leads>");

                    postContent = postContent + "&wfTrigger=true";
                }
                if (methodname.Equals("updateRecords") || methodname.Equals("deleteRecords") || methodname.Equals("getRecordById"))
                {
                    postContent = postContent + "&id=" + recordId;
                }

                try
                {
                    string result = AccessCRM(uri, postContent);
                    //return result;
                    XmlDocument document = new XmlDocument();
                    document.Load(new System.IO.StringReader(result));
                    XmlNode node       = document.DocumentElement.SelectSingleNode("//FL");
                    string  ZohoLeadID = node.InnerXml;     //ZOHO Return Lead ID.

                    InsertLead(User_ID, Email, ContactNo, ZohoLeadID, LeadSource);

                    //insert Lead into Assessment Subdomain
                    this.InsertIntoSubDomain(Email, ZohoLeadID, LeadSource);
                    //insert Lead into Assessment Subdomain
                }
                catch (Exception ex)
                {
                    MCG_Email_SMS_Util.Email objEmail = new MCG_Email_SMS_Util.Email();
                    string sErrorMsg = string.Empty;
                    sErrorMsg = ex.Message.ToString() +
                                "LeadSource= " + LeadSource + "<br>" +
                                "FName= " + FName + "<br>" +
                                "LName= " + LName + "<br>" +
                                "Email= " + Email + "<br>" +
                                "ContactNo= " + ContactNo + "<br>" +
                                "Parent ContactNo= " + ParentContactNo + "<br>" +
                                "Address= " + Address + "<br>" +
                                "Assessment Completed= " + AssessmentCompleted + "<br>" +
                                "ProductCode= " + ProductCode + "<br>" +
                                "Question Desc= " + QuestionURL + "<br>" +
                                "Contact Us Query= " + ContactUSQuery + "<br>" +
                                "PTG Attempts= " + PTGAttempts + "<br>" +
                                "Description= " + Description + "<br>";
                    objEmail.ShootMail_NonThread(MCG_Email_SMS_Util.Email.EmailServer.Amazon_CRM_Utility, MCG_Email_SMS_Util.Email.EmailShootFor.crm_in, "sto", "*****@*****.**", "Error while entering lead to Zoho for " + LeadSource + " LeadSource", sErrorMsg, "");
                    objEmail = null;
                }
            }
            else
            {
                string sCurrentLeadStatus   = string.Empty;
                string sCurrentModifiedTime = string.Empty;
                string sCurrentDiscription  = string.Empty;
                string sCurrentProductCode  = string.Empty;
                string sCurrentAssCompleted = string.Empty;
                string sCurrentQuestionDesc = string.Empty;
                string sCurrentLeadSource   = string.Empty;
                string sCurrentPTGAttempts  = string.Empty;

                //string sZohoID = CheckForZohoID(Email);

                string modulename  = "Leads";
                string methodname  = "getRecordById";
                string recordId    = sZohoID;
                string uri         = zohocrmurl + modulename + "/" + methodname + "?";
                string postContent = string.Empty;

                if (methodname.Equals("getRecordById"))
                {
                    postContent = "scope=crmapi";
                    postContent = postContent + "&authtoken=*************************";
                    postContent = postContent + "&id=" + recordId;
                    postContent = postContent + "&newFormat=2&selectColumns=Leads(Lead Source,Current Lead Source,Lead Status,Modified Time,Assessment Completed,Question Desc,Product Code,Description,PTG Attempts)";

                    string      result = AccessCRM(uri, postContent);
                    int         i      = 0;
                    XmlDocument doc    = new XmlDocument();
                    doc.Load(new System.IO.StringReader(result));
                    foreach (XmlNode node in doc.DocumentElement.SelectNodes("//FL"))
                    {
                        XmlNode node1 = doc.DocumentElement.SelectNodes("//FL")[i];
                        if (i == 2)
                        {
                            sCurrentLeadStatus = node1.InnerText;
                        }
                        else if (i == 3)
                        {
                            sCurrentModifiedTime = node1.InnerText;
                        }
                        else if (i == 4)
                        {
                            sCurrentDiscription = node1.InnerText;
                        }
                        else if (i == 5)
                        {
                            sCurrentProductCode = node1.InnerText;
                        }
                        else if (i == 6)
                        {
                            sCurrentAssCompleted = node1.InnerText;
                        }
                        else if (i == 7)
                        {
                            sCurrentQuestionDesc = node1.InnerText;
                        }
                        else if (i == 8)
                        {
                            sCurrentLeadSource = node1.InnerText;
                        }
                        else if (i == 9)
                        {
                            sCurrentPTGAttempts = node1.InnerText;
                            if (LeadSource == "Proceed To Guidance")
                            {
                                if (!string.IsNullOrEmpty(sCurrentPTGAttempts) & sCurrentPTGAttempts.ToLower() != "null")
                                {
                                    sCurrentPTGAttempts = Convert.ToString(Convert.ToInt32(sCurrentPTGAttempts) + 1);
                                }
                                else
                                {
                                    sCurrentPTGAttempts = "1";
                                }
                            }
                        }
                        i++;
                    }
                }
                if (sCurrentModifiedTime.ToLower() != "null")
                {
                    try { DateTime dModifiedDate = Convert.ToDateTime(sCurrentModifiedTime); sCurrentModifiedTime = dModifiedDate.ToString("dd/MM/yyyy hh:mm tt"); }
                    catch (Exception x) { }
                }
                if (sCurrentLeadSource.ToLower() == "null")
                {
                    sCurrentLeadSource = LeadSource;
                }
                string sNewDescription = sCurrentModifiedTime + "\t Last Lead Source: " + sCurrentLeadSource + "\t Last Lead Status: " + sCurrentLeadStatus + "\t Last Product Code: " + sCurrentProductCode + "\t Assessment Done: " + sCurrentAssCompleted + "\t Question URL: " + sCurrentQuestionDesc;// +"\t Desc: " + Description;
                sNewDescription = sNewDescription + "\n\n" + sCurrentDiscription;

                postContent = string.Empty;
                methodname  = "updateRecords";
                uri         = zohocrmurl + modulename + "/" + methodname + "?";
                if (methodname.Equals("updateRecords"))
                {
                    postContent = "scope=crmapi";
                    postContent = postContent + "&authtoken=**********************";

                    string sParentUpdate = "";
                    if (ParentContactNo != "")
                    {
                        sParentUpdate = "<FL val=\"Parents Contact No\">" + ParentContactNo + "</FL>";
                    }
                    string sQuestionUpdate = "";
                    if (QuestionURL != "")
                    {
                        sQuestionUpdate = "<FL val=\"Question Desc\">" + QuestionURL + "</FL>";
                    }
                    string sContactUsUpdate = "";
                    if (ContactUSQuery != "")
                    {
                        sContactUsUpdate = "<FL val=\"Contact us Query\">" + ContactUSQuery + "</FL>";
                    }
                    string scontact_no = "";
                    if (ContactNo != "")
                    {
                        scontact_no = "<FL val=\"Contact No\">" + ContactNo + "</FL>";
                    }

                    postContent = postContent + "&xmlData=" + HttpUtility.UrlEncode("<Leads><row no=\"1\">" +

                                                                                    "<FL val=\"Current Lead Source\">" + LeadSource + "</FL>" +
                                                                                    "<FL val=\"Lead Status\">Open (O)</FL>" +
                                                                                    sParentUpdate + scontact_no +
                                                                                    "<FL val=\"Product Code\">" + ProductCode + "</FL>" +
                                                                                    sQuestionUpdate +
                                                                                    "<FL val=\"Assessment Completed\">" + AssessmentCompleted + "</FL>" +
                                                                                    sContactUsUpdate +
                                                                                    //"<FL val=\"Description\">" + Description + "</FL>" +
                                                                                    "<FL val=\"PTG Attempts\">" + sCurrentPTGAttempts + "</FL>" +
                                                                                    "<FL val=\"Description\">" + sNewDescription + "</FL>" +

                                                                                    "</row></Leads>");

                    postContent = postContent + "&wfTrigger=true";
                    postContent = postContent + "&id=" + recordId;

                    try
                    {
                        string result = AccessCRM(uri, postContent);
                    }
                    catch (Exception ex)
                    {
                        MCG_Email_SMS_Util.Email objEmail = new MCG_Email_SMS_Util.Email();
                        string sErrorMsg = string.Empty;
                        sErrorMsg = ex.Message.ToString() +
                                    "LeadSource= " + LeadSource + "<br>" +
                                    "FName= " + FName + "<br>" +
                                    "LName= " + LName + "<br>" +
                                    "Email= " + Email + "<br>" +
                                    "ContactNo= " + ContactNo + "<br>" +
                                    "Parent ContactNo= " + ParentContactNo + "<br>" +
                                    "Address= " + Address + "<br>" +
                                    "Assessment Completed= " + AssessmentCompleted + "<br>" +
                                    "ProductCode= " + ProductCode + "<br>" +
                                    "Question Desc= " + QuestionURL + "<br>" +
                                    "Contact Us Query= " + ContactUSQuery + "<br>" +
                                    "PTG Attempts= " + sCurrentPTGAttempts + "<br>" +
                                    "Description= " + Description + "<br>";
                        objEmail.ShootMail_NonThread(MCG_Email_SMS_Util.Email.EmailServer.Amazon_CRM_Utility, MCG_Email_SMS_Util.Email.EmailShootFor.crm_in, "sto", "*****@*****.**", "Error while Updating lead to Zoho for " + LeadSource + " LeadSource", sErrorMsg, "");
                        objEmail = null;
                    }
                }
            }
        }