public Int64 UpdateHostWithContacts(EProspect prospect, string userID, string shell, string role)
    {
        FranchisorDAL franchisorDAL   = new FranchisorDAL();
        Int64         returnresult    = franchisorDAL.SaveHost(prospect, Convert.ToInt32(EOperationMode.Update), userID, shell, role);
        Int64         ContctID        = 0;
        Int64         returnContactID = 0;
        int           prospectid      = 0;

        if (returnresult == 0)
        {
            prospectid = Convert.ToInt32(prospect.ProspectID);

            // Save prospect details
            if (prospect.ProspectDetails != null)
            {
                franchisorDAL.SaveProspectDetails(prospect.ProspectDetails, prospectid);
            }

            if (prospect.Contact != null && prospect.Contact.Count > 0)
            {
                for (int i = 0; i < prospect.Contact.Count; i++)
                {
                    if (prospect.Contact[i].IsDeleted == false)
                    {
                        //returnContactID = franchisorDAL.SaveNewProspectContact(prospect.Contact[i], 2, prospectid, Convert.ToInt32(userID));
                        if (prospect.Contact[i].ContactID > 0)
                        {
                            returnContactID = franchisorDAL.SaveContact(prospect.Contact[i], Convert.ToInt32(EOperationMode.Update), Convert.ToInt32(userID));
                            if (returnContactID >= 0)
                            {
                                returnContactID = prospect.Contact[i].ContactID;
                            }
                            else
                            {
                                returnContactID = -1;
                            }
                        }
                        else
                        {
                            returnContactID = franchisorDAL.SaveContact(prospect.Contact[i], Convert.ToInt32(EOperationMode.Insert), Convert.ToInt32(userID));
                        }

                        if (returnContactID > 0)
                        {
                            franchisorDAL.SaveProspectContact(returnContactID, prospectid, true);
                            franchisorDAL.SaveProspectContactRoleMapping(prospect.Contact[i].ListProspectContactRole, returnContactID, prospectid);
                        }
                    }
                    else
                    {
                        //Delete the same record
                        franchisorDAL.SaveProspectContact(prospect.Contact[i].ContactID, prospectid, false);
                    }
                }
            }
            if (ContctID > 0 || prospectid > 0 && (prospect.ContactMeeting != null))
            {
                prospect.ContactMeeting.ProspectID        = prospectid;
                prospect.ContactMeeting.Contact.ContactID = Convert.ToInt32(returnContactID);
                franchisorDAL.SaveMeeting(prospect.ContactMeeting, Convert.ToInt32(EOperationMode.Insert));
            }
        }
        return(returnresult);
    }
    /// <summary>
    /// To update prospect detail
    /// </summary>
    /// <param name="prospectList"></param>
    /// <param name="userID"></param>
    /// <param name="shell"></param>
    /// <param name="role"></param>
    /// <returns></returns>
    public Int64 UpdateProspectWithContact(EProspect prospect, string userID, string shell, string role)
    {
        FranchisorDAL franchisorDAL   = new FranchisorDAL();
        Int64         returnresult    = franchisorDAL.SaveProspect(prospect, Convert.ToInt32(EOperationMode.Update), userID, shell, role);
        Int64         returnContactID = 0;
        int           prospectid      = 0;

        if (returnresult == 0)
        {
            prospectid = Convert.ToInt32(prospect.ProspectID);

            if (prospect.AddressMailing != null)
            {
                // Save prospect mailing address
                franchisorDAL.SaveProspectAddress(prospect.AddressMailing, prospectid);
            }
            // Save prospect details
            if (prospect.ProspectDetails != null)
            {
                franchisorDAL.SaveProspectDetails(prospect.ProspectDetails, prospectid);
            }

            if (prospect.Contact != null && prospect.Contact.Count > 0)
            {
                for (int i = 0; i < prospect.Contact.Count; i++)
                {
                    if (prospect.Contact[i].IsDeleted == false)
                    {
                        // Save Prospect Communication
                        //returnContactID = franchisorDAL.SaveNewProspectContact(prospect.Contact[i], 2, prospectid, Convert.ToInt32(userID));
                        if (prospect.Contact[i].ContactID > 0)
                        {
                            returnContactID = franchisorDAL.SaveContact(prospect.Contact[i], Convert.ToInt32(EOperationMode.Update), Convert.ToInt32(userID));
                            if (returnContactID >= 0)
                            {
                                returnContactID = prospect.Contact[i].ContactID;
                            }
                            else
                            {
                                returnContactID = -1;
                            }
                        }
                        else
                        {
                            returnContactID = franchisorDAL.SaveContact(prospect.Contact[i], Convert.ToInt32(EOperationMode.Insert), Convert.ToInt32(userID));
                        }

                        if (returnContactID > 0)
                        {
                            franchisorDAL.SaveProspectContact(returnContactID, prospectid, true);
                            franchisorDAL.SaveProspectContactRoleMapping(prospect.Contact[i].ListProspectContactRole, returnContactID, prospectid);
                        }
                    }
                    else
                    {
                        //Deactivates the same record
                        franchisorDAL.SaveProspectContact(prospect.Contact[i].ContactID, prospectid, false);
                    }
                }
            }
        }
        if (prospect.ContactCall != null)
        {
            prospect.ContactCall.Contact           = new EContact();
            prospect.ContactCall.Contact.ContactID = Convert.ToInt32(returnContactID);
            prospect.ContactCall.ProspectID        = prospectid;
            franchisorDAL.SaveCall(prospect.ContactCall, Convert.ToInt32(EOperationMode.Insert));
        }
        if (prospect.ContactMeeting != null)
        {
            prospect.ContactMeeting.Contact           = new EContact();
            prospect.ContactMeeting.Contact.ContactID = Convert.ToInt32(returnContactID);
            prospect.ContactMeeting.ProspectID        = prospectid;
            franchisorDAL.SaveMeeting(prospect.ContactMeeting, Convert.ToInt32(EOperationMode.Insert));
        }
        if (prospect.Task != null)
        {
            prospect.Task.ContactID  = Convert.ToInt32(returnContactID);
            prospect.Task.ProspectID = prospectid;
            franchisorDAL.SaveTask(prospect.Task, Convert.ToInt32(EOperationMode.Insert), userID, shell, role);
        }

        return(returnresult);
    }
    /// <summary>
    /// Save Prospect
    /// </summary>
    private void SaveProspect()
    {
        //FranchisorService service = new FranchisorService();
        EProspect        prospect            = new EProspect();
        EAddress         addressbilling      = new EAddress();
        EAddress         addressmailing      = new EAddress();
        EProspectDetails objEProspectDetails = new EProspectDetails();

        prospect.ProspectDetails = new EProspectDetails();
        bool blnIsHost = false;

        OtherDAL otherDal      = new OtherDAL();
        EZip     zipobjbilling = otherDal.CheckCityZip(txtcityBilling.Text, txtzipBilling.Text, ddlstateBilling.SelectedValue);

        EZip zipobjmailing = new EZip();

        // format phone no.
        CommonCode objCommonCode = new CommonCode();

        if (txtzipBilling.Text != "")
        {
            if (zipobjbilling.CityID == 0)
            {
                divErrorMsg.Visible   = true;
                divErrorMsg.InnerHtml = "City name for address is not valid. <br> Please Try again.";

                //ClientScript.RegisterStartupScript(typeof(string), "jscodebilling", "alert('City name for billing address is not valid. <br> Please Try again.');", true);
                return;
            }
            else if (zipobjbilling.CityID > 0 && zipobjbilling.ZipID == 0)
            {
                divErrorMsg.Visible   = true;
                divErrorMsg.InnerHtml = "Address Zip code for the corresponding city is not valid. <br> Please Try again.";

                //ClientScript.RegisterStartupScript(typeof(string), "jscodebilling", "alert('Billing address Zip code for the corresponding city is not valid. <br> Please Try again.');", true);
                return;
            }
        }
        if (chkMailingAddress.Checked == true)
        {
            zipobjmailing = otherDal.CheckCityZip(txtcityMailing.Text, txtzipMailing.Text, ddlstateMailing.SelectedValue);
            if (txtzipMailing.Text != "")
            {
                if (zipobjmailing.CityID == 0)
                {
                    divErrorMsg.Visible   = true;
                    divErrorMsg.InnerHtml = "City name for mailing address is not valid. <br> Please Try again.";

                    //ClientScript.RegisterStartupScript(typeof(string), "jscodemailing", "alert('City name for mailing address is not valid. <br> Please Try again.');", true);
                    return;
                }
                else if (zipobjmailing.CityID > 0 && zipobjmailing.ZipID == 0)
                {
                    divErrorMsg.Visible   = true;
                    divErrorMsg.InnerHtml = "Mailing address Zip code for the corresponding city is not valid. <br> Please Try again.";

                    //ClientScript.RegisterStartupScript(typeof(string), "jscodemailing", "alert('Mailing address Zip code for the corresponding city is not valid. <br> Please Try again.');", true);
                    return;
                }
            }
        }

        if (ViewState["ProspectID"] != null)
        {
            prospect.ProspectID = Convert.ToInt32(ViewState["ProspectID"].ToString());
        }

        if (ViewState["AddressIDBilling"] != null)
        {
            addressbilling.AddressID = Convert.ToInt32(ViewState["AddressIDBilling"].ToString());
        }

        prospect.OrganizationName = txtOrgName.Text;
        prospect.WebSite          = txtwebaddress.Text;

        EProspectType prospecttype = new EProspectType();

        prospecttype.ProspectTypeID = Convert.ToInt32(ddlHostType.SelectedValue.ToString());
        prospect.ProspectType       = prospecttype;

        prospect.ActualMembership = txtActualMembers.Text.Length > 0 ? Convert.ToDecimal(txtActualMembers.Text) : 0;
        prospect.Attendance       = txtAttendence.Text.Length > 0 ? Convert.ToDecimal(txtAttendence.Text) : 0;

        prospect.EMailID   = txtEmail.Text;
        prospect.PhoneCell = "";
        if (txtcphoneoffice.Text.Trim().Equals("(___)-___-____"))
        {
            txtcphoneoffice.Text = "";
        }
        prospect.PhoneOffice = objCommonCode.FormatPhoneNumber(txtcphoneoffice.Text);
        prospect.PhoneOther  = "";

        prospect.Notes = txtNotes.Text;

        if (ViewState["IsHost"].ToString().Equals("1"))
        {
            prospect.IsHost = true;
            blnIsHost       = true;
        }
        else
        {
            prospect.IsHost = false;
        }

        addressbilling.Address1 = txtaddress1Billing.Text;
        addressbilling.Address2 = txtaddress2Billing.Text;


        if (Convert.ToInt32(ddlstateBilling.SelectedValue) > 0)
        {
            addressbilling.State   = ddlstateBilling.SelectedItem.Text;
            addressbilling.StateID = Convert.ToInt32(ddlstateBilling.SelectedItem.Value);
        }
        else
        {
            addressbilling.State = string.Empty;
        }

        addressbilling.ZipID = txtzipBilling.Text.Length > 0 ? Convert.ToInt32(txtzipBilling.Text) : 0;
        addressbilling.City  = txtcityBilling.Text;
        if (txtFax.Text.Trim().Equals("(___)-___-____"))
        {
            txtFax.Text = "";
        }
        addressbilling.Fax = objCommonCode.FormatPhoneNumber(txtFax.Text);

        prospect.Address = addressbilling;

        if (blnIsHost)
        {
            addressbilling.ZipID = txtzipBilling.Text.Length > 0 ? zipobjbilling.ZipID : 0;
        }
        else
        {
            addressbilling.ZipID = txtzipBilling.Text.Length > 0 ? Convert.ToInt32(txtzipBilling.Text) : 0;
        }

        addressbilling.CityID = txtcityBilling.Text.Length > 0 ? zipobjbilling.CityID : 0;

        addressbilling.Country   = COUNTRY_NAME;
        addressbilling.CountryID = COUNTRY_ID;

        // If mailing address is provided
        if (chkMailingAddress.Checked == true)
        {
            addressmailing.IsMailing = true;
            addressmailing.Address1  = txtaddress1Mailing.Text;
            addressmailing.Address2  = txtaddress2Mailing.Text;

            if (Convert.ToInt32(ddlstateMailing.SelectedValue) > 0)
            {
                addressmailing.State   = ddlstateMailing.SelectedItem.Text;
                addressmailing.StateID = Convert.ToInt32(ddlstateBilling.SelectedItem.Value);
            }
            else
            {
                addressmailing.State = string.Empty;
            }

            if (blnIsHost)
            {
                addressmailing.ZipID = txtzipMailing.Text.Length > 0 ? zipobjmailing.ZipID : 0;
            }
            else
            {
                addressmailing.ZipID = txtzipMailing.Text.Length > 0 ? Convert.ToInt32(txtzipMailing.Text) : 0;
            }

            addressmailing.City   = txtcityMailing.Text;
            addressmailing.CityID = txtcityMailing.Text.Length > 0 ? zipobjmailing.CityID : 0;
            addressmailing.Zip    = txtzipMailing.Text;
            addressmailing.Fax    = "";

            addressmailing.Country   = COUNTRY_NAME;
            addressmailing.CountryID = COUNTRY_ID;
        }
        // Mailing address is same as billing address
        else
        {
            addressmailing.Address1 = addressbilling.Address1;
            addressmailing.Address2 = addressbilling.Address2;
            addressmailing.City     = addressbilling.City;
            addressmailing.State    = addressbilling.State;
            addressmailing.Zip      = addressbilling.Zip;
            addressmailing.Country  = addressbilling.Country;

            addressmailing.CityID    = addressbilling.CityID;
            addressmailing.StateID   = addressbilling.StateID;
            addressmailing.ZipID     = addressbilling.ZipID;
            addressmailing.CountryID = addressbilling.CountryID;

            addressmailing.IsMailing = true;
        }

        if (ViewState["AddressIDMailing"] != null)
        {
            addressmailing.AddressID = Convert.ToInt32(ViewState["AddressIDMailing"].ToString());
        }

        prospect.AddressMailing  = addressmailing;
        prospect.FollowDate      = DateTime.Now.ToShortDateString();
        prospect.WillCommunicate = Convert.ToInt32(ddlFeederPromotionStatus.SelectedValue);
        if (ddlFeederPromotionStatus.SelectedValue.Equals("0"))
        {
            prospect.ReasonWillCommunicate = txtWillPromote.Text;
        }
        if (ViewState["FranchiseeID"] != null)
        {
            ArrayList arrtemp = (ArrayList)ViewState["FranchiseeID"];
            prospect.FranchiseeID = arrtemp;
            //prospect.FranchiseeID = arrtemp.ToArray();
        }


        objEProspectDetails.FacilitiesFee = txtFacilitiesFee.Text;

        string strPaymentMethod = string.Empty;

        foreach (ListItem li in chkPaymentMethod.Items)
        {
            if (li.Selected == true)
            {
                if (strPaymentMethod == "")
                {
                    strPaymentMethod = li.Value;
                }
                else
                {
                    strPaymentMethod = strPaymentMethod + "," + li.Value;
                }
            }
        }
        objEProspectDetails.PaymentMethod   = strPaymentMethod;
        objEProspectDetails.DepositsRequire = Convert.ToInt16(rbtnDepositsRequired.SelectedValue);

        if (rbtnDepositsRequired.SelectedValue.Equals("1"))
        {
            objEProspectDetails.DepositsAmount = txtAmount.Text.Length > 0 ? Convert.ToDecimal(txtAmount.Text) : 0.0m;
        }
        objEProspectDetails.WillHost       = Convert.ToInt16(ddlhostStatus.SelectedValue);
        objEProspectDetails.ViableHostSite = Convert.ToInt16(ddlViableHost.SelectedValue);
        objEProspectDetails.HostedInPast   = Convert.ToInt16(ddlHostedInPast.SelectedValue);
        if (ddlhostStatus.SelectedValue.Equals("0"))
        {
            objEProspectDetails.ReasonWillHost = txtWillHost.Text;
        }
        if (ddlViableHost.SelectedValue.Equals("0"))
        {
            objEProspectDetails.ReasonViableHostSite = txtViableHostSite.Text;
        }
        if (ddlHostedInPast.SelectedValue.Equals("0"))
        {
            objEProspectDetails.ReasonHostedInPast = txtHostInPast.Text;
        }
        if (ddlHostedInPast.SelectedValue.Equals("1"))
        {
            objEProspectDetails.HostedInPastWith = txtHostedInPast.Text;
        }

        if (ViewState["ProspectDetailsID"] != null)
        {
            objEProspectDetails.ProspectDetailID = Convert.ToInt32(ViewState["ProspectDetailsID"].ToString());
        }
        prospect.ProspectDetails = objEProspectDetails;

        prospect.ContactMeeting = null;
        prospect.ContactCall    = null;
        prospect.Task           = null;

        var currentSession = IoC.Resolve <ISessionContext>().UserSession;

        Session["Popup"] = "True";
        if (blnIsHost)
        {
            UpdateHostWithContacts(prospect, currentSession.UserId.ToString(), currentSession.CurrentOrganizationRole.OrganizationId.ToString(),
                                   currentSession.CurrentOrganizationRole.RoleId.ToString());
        }
        else
        {
            UpdateProspectWithContact(prospect, currentSession.UserId.ToString(), currentSession.CurrentOrganizationRole.OrganizationId.ToString(),
                                      currentSession.CurrentOrganizationRole.RoleId.ToString());
        }

        ClientScript.RegisterStartupScript(typeof(Page), "Edit Prospect Host", "<script language='javascript'  type='text/javascript' > CloseWindow(); </script>");
    }