private BComSiteResponse CreateNewSiteID(DataTable aviatorData)
        {
            // Create an HTTPS_ Interface.
            HTTPS_Interface httpsInterface = new HTTPS_Interface();

            // Create Site Request
            BComSiteRequest request =
                new BComSiteRequest();

            request.Site         = new Site();
            request.Site.Address = new Address();

            // Load the request.
            try
            {
                request.Site.CustomerProvidedId = this.cpid.ToString();
                request.Site.Name                = aviatorData.Rows[0]["BCOM_AcctName"].SafeToString();
                request.Site.CustomerName        = aviatorData.Rows[0]["AcctName"].SafeToString();
                request.Site.Description         = aviatorData.Rows[0]["AcctDescription"].SafeToString();
                request.Site.Address.AddressType = "Service";
                request.Site.Address.HouseNumber = aviatorData.Rows[0]["HouseNumber"].SafeToString();
                request.Site.Address.StreetName  = aviatorData.Rows[0]["StreetName"].SafeToString();
                request.Site.Address.City        = aviatorData.Rows[0]["City"].SafeToString();
                request.Site.Address.StateCode   = aviatorData.Rows[0]["StateCode"].SafeToString();
                request.Site.Address.ZipCode     = aviatorData.Rows[0]["Zip"].SafeToString();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failed loading Aviator data into order: " + ex.Message);
            }

            // Send the request and get the response.
            BComSiteResponse siteResponse =
                httpsInterface.CreateSite(request);

            // Did the request succeed?
            if (siteResponse.Status == "Success")
            {
                // Update Site information.
                try
                {
                    this.db.UpdateSitesTable(request, siteResponse);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Failed update the Sites table with the new account: " + ex.Message);
                }
            }

            // Return the response.
            return(siteResponse);
        }
        private void LoadBComAccount(DataTable aviatorData)
        {
            // Does the oppid need a siteid created by BCOM?
            this.siteid = -1;
            if (aviatorData.Rows[0]["siteid"].SafeToString() == "-1")
            {
                // Get the response.
                BComSiteResponse siteResponse = null;
                try
                {
                    siteResponse = CreateNewSiteID(aviatorData);
                }
                catch (Exception ex)
                {
                    this.response.SetJeop(
                        "Unable to request a SiteID for opp: " + ex.Message);
                    return;
                }

                // Did the request fail?
                if (siteResponse.Status != "Success")
                {
                    // Immediately Jeop with the error message.
                    this.response.SetJeop(siteResponse.ErrorMessage);
                    return;
                }

                // Extract the siteid.
                bool success = false;
                success = long.TryParse(
                    siteResponse.SiteID, out this.siteid);

                // Failed? Then Jeop.
                if (success == false)
                {
                    this.response.SetJeop(
                        "Unable to parse SiteID for opp: Returned value of " + siteResponse.SiteID);
                    return;
                }
            }
            else // It's there? Now parse it out to be used later.
            {
                bool success = false;
                success = long.TryParse(
                    aviatorData.Rows[0]["siteid"].SafeToString(), out this.siteid);

                // Failed? Then Jeop.
                if (success == false)
                {
                    this.response.SetJeop(
                        "Unable to parse SiteID for opp: Returned value of " + aviatorData.Rows[0]["siteid"].SafeToString());
                    return;
                }
            }

            // Debug, test write siteid.
            //Response.Write("SiteID: " + this.siteid.ToString());
            //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            // Does the oppid need a peerid created by BCOM?
            this.peerid = -1;
            if (aviatorData.Rows[0]["peerid"].SafeToString() == "-1")
            {
                // Get the response.
                BComSipPeerResponse peerResponse = null;
                try
                {
                    peerResponse = CreateNewPeerID(aviatorData);
                }
                catch (Exception ex)
                {
                    this.response.SetJeop(
                        "Unable to request a SipPeerID for opp: " + ex.Message);
                    return;
                }

                // Did the request fail?
                if (peerResponse.Status != "Success")
                {
                    // Immediately Jeop with the error message.
                    this.response.SetJeop(peerResponse.ErrorMessage);
                    return;
                }

                // Extract the peerid.
                bool success = false;
                success = long.TryParse(
                    peerResponse.SipPeerID, out this.peerid);

                // Failed? Then Jeop.
                if (success == false)
                {
                    this.response.SetJeop(
                        "Unable to parse SipPeerID for opp: Returned value of " + peerResponse.SipPeerID);
                    return;
                }
            }
            else // It's there? Now parse it out to be used later.
            {
                bool success = false;
                success = long.TryParse(
                    aviatorData.Rows[0]["peerid"].SafeToString(), out this.peerid);

                // Failed? Then Jeop.
                if (success == false)
                {
                    this.response.SetJeop(
                        "Unable to parse SipPeerID for opp: Returned value of " + aviatorData.Rows[0]["peerid"].SafeToString());
                    return;
                }
            }

            // Debug, test write peerid.
            //Response.Write("SipPeerID: " + this.siteid.ToString());
            //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);
        }