Пример #1
0
    protected int CreateContactAndProspect(string sFirstName, string sLastName, string sEmail, string sType, string sPhone, string sDOB, string sSSN, int iUserID, string Purpose)
    {
        #region create new contact

        LPWeb.Model.Contacts ContactsModel = new LPWeb.Model.Contacts();
        ContactsModel.ContactId = 0;
        ContactsModel.FirstName = sFirstName;
        ContactsModel.LastName  = sLastName;
        ContactsModel.Email     = sEmail;

        if (sType == "Cell Phone")
        {
            ContactsModel.CellPhone     = sPhone;
            ContactsModel.HomePhone     = string.Empty;
            ContactsModel.BusinessPhone = string.Empty;
        }
        else if (sType == "Home Phone")
        {
            ContactsModel.CellPhone     = string.Empty;
            ContactsModel.HomePhone     = sPhone;
            ContactsModel.BusinessPhone = string.Empty;
        }
        else if (sType == "Work Phone")
        {
            ContactsModel.CellPhone     = string.Empty;
            ContactsModel.HomePhone     = string.Empty;
            ContactsModel.BusinessPhone = sPhone;
        }

        if (sDOB == string.Empty)
        {
            ContactsModel.DOB = null;
        }
        else
        {
            ContactsModel.DOB = Convert.ToDateTime(sDOB);
        }

        ContactsModel.SSN = sSSN;

        ContactsModel.MiddleName     = string.Empty;
        ContactsModel.NickName       = txtFirstName.Text.Trim();
        ContactsModel.Title          = string.Empty;
        ContactsModel.GenerationCode = string.Empty;
        ContactsModel.Fax            = string.Empty;
        ContactsModel.MailingAddr    = string.Empty;
        ContactsModel.MailingCity    = string.Empty;
        ContactsModel.MailingState   = string.Empty;
        ContactsModel.MailingZip     = string.Empty;

        #endregion

        #region create new prospect

        LPWeb.Model.Prospect ProspectModel = new LPWeb.Model.Prospect();

        ProspectModel.PreferredContact = sType;

        ProspectModel.Contactid  = 0;
        ProspectModel.Created    = DateTime.Now;
        ProspectModel.CreatedBy  = iUserID;
        ProspectModel.LeadSource = ddlLeadSource.SelectedValue.ToString() == "0" ? "" : this.ddlLeadSource.SelectedItem.Text;

        string sLoanOfficerID = ddlLoanOfficer.SelectedValue;
        iLoanOfficerID = 0;
        if (sLoanOfficerID == "-1" || sLoanOfficerID == "-2")
        {
            //Nobody
        }
        else if (sLoanOfficerID == "0")
        {
            //Lead Routing Engine
            try
            {
                ServiceManager sm = new ServiceManager();
                using (LP2ServiceClient client = sm.StartServiceClient())
                {
                    //invoke the WCF API GetNextLoanOfficer
                    LR_GetNextLoanOfficerReq req = new LR_GetNextLoanOfficerReq();
                    req.LeadSource           = ddlLeadSource.SelectedItem.Text;
                    req.Purpose              = Purpose;
                    req.ReqHdr               = new ReqHdr();
                    req.ReqHdr.UserId        = CurrUser.iUserID;
                    req.ReqHdr.SecurityToken = "SecurityToken";
                    LR_GetNextLoanOfficerResp response = client.LeadRouting_GetNextLoanofficer(req);
                    if (response.RespHdr.Successful)
                    {
                        iLoanOfficerID = response.NextLoanOfficerID;
                    }
                    else
                    {
                        Company_Lead_Sources LeadSourceMgr     = new Company_Lead_Sources();
                        DataTable            SelLeadSourceList = LeadSourceMgr.GetList("LeadSourceID='" + ddlLeadSource.SelectedValue + "'").Tables[0];
                        if (SelLeadSourceList != null && SelLeadSourceList.Rows.Count > 0)
                        {
                            iLoanOfficerID = SelLeadSourceList.Rows[0]["DefaultUserId"] == DBNull.Value ? 0 : Convert.ToInt32(SelLeadSourceList.Rows[0]["DefaultUserId"]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Company_Lead_Sources LeadSourceMgr     = new Company_Lead_Sources();
                DataTable            SelLeadSourceList = LeadSourceMgr.GetList("LeadSourceID='" + ddlLeadSource.SelectedValue + "'").Tables[0];
                if (SelLeadSourceList != null && SelLeadSourceList.Rows.Count > 0)
                {
                    iLoanOfficerID = SelLeadSourceList.Rows[0]["DefaultUserId"] == DBNull.Value ? 0 : Convert.ToInt32(SelLeadSourceList.Rows[0]["DefaultUserId"]);
                }
            }
        }
        else
        {
            iLoanOfficerID = Convert.ToInt32(sLoanOfficerID);
        }


        ProspectModel.Loanofficer   = iLoanOfficerID;
        ProspectModel.ReferenceCode = string.Empty;
        ProspectModel.Status        = "Active";
        ProspectModel.CreditRanking = string.Empty;
        ProspectModel.Referral      = null;

        Prospect ProspectManager = new Prospect();

        int iContactId = ProspectManager.CreateContactAndProspect(ContactsModel, ProspectModel);


        #endregion

        return(iContactId);
    }