Exemplo n.º 1
0
        protected void btnSaveAndContinue_Click(object sender, EventArgs e)
        {
            bool  isDuplicate = false;
            Leads objLead     = null;

            lblError.Text      = string.Empty;
            lblError.Visible   = false;
            lblSave.Text       = string.Empty;
            lblSave.Visible    = false;
            lblMessage.Visible = false;
            lblMessage.Text    = string.Empty;
            bool isNew = false;

            Page.Validate("NewLead");

            if (!Page.IsValid)
            {
                return;
            }

            try {
                if (ViewState["LeadIds"] == null)
                {
                    // new lead/claim
                    objLead = new Leads();

                    objLead.UserId = Convert.ToInt32(Session["UserId"]);

                    // 2013-07-19

                    objLead.ClientID = Convert.ToInt32(Session["ClientId"]);

                    objLead.DateSubmitted = DateTime.Now;

                    objLead.Status = 1;

                    isNew = true;
                }
                else
                {
                    objLead = LeadsManager.GetByLeadId(Convert.ToInt32(ViewState["LeadIds"].ToString()));
                }

                //int claimsNumber = 0;

                objLead.Longitude = Convert.ToDouble(hf_Longitude.Value);
                objLead.Latitude  = Convert.ToDouble(hf_Latitude.Value);

                DateTime?originalLeadDate = null;
                if (!string.IsNullOrEmpty(txtOriginalLeadDate.Text.Trim()))
                {
                    originalLeadDate = Convert.ToDateTime(txtOriginalLeadDate.Text.Trim());
                }
                //DateTime.TryParse(txtOriginalLeadDate.Text.Trim(), out originalLeadDate);

                DateTime?lastContactDate = null;

                DateTime?siteSurveyDate = null;

                objLead.OriginalLeadDate = originalLeadDate;



                //DateTime? lossDate = null;
                //if (!string.IsNullOrEmpty(txtLossDate.Text.Trim()))
                //	lossDate = Convert.ToDateTime(txtLossDate.Text.Trim());
                //objLead.LossDate = lossDate;

                // 2013-10-29 tortega
                objLead.LossLocation = txtLossLocation.Text.Trim();

                //objLead.ClaimsNumber = claimsNumber;
                objLead.InsuredName = txtInsuredName.Text.Trim();

                objLead.ClaimantFirstName  = txtClaimantName.Text.Trim();;
                objLead.ClaimantLastName   = txtClaimantLastName.Text.Trim();
                objLead.ClaimantMiddleName = txtClaimantMiddleName.Text.Trim();
                objLead.Salutation         = txtSalutation.Text.Trim();

                objLead.BusinessName = txtBusinessName.Text;

                objLead.SecondaryLeadSource = txtSecondaryLeadSource.Text;


                if (Convert.ToInt32(ddlUmpire.SelectedValue) != 0)
                {
                    objLead.UmpireID = Convert.ToInt32(ddlUmpire.SelectedValue);
                }
                if (Convert.ToInt32(ddlContractor.SelectedValue) != 0)
                {
                    objLead.ContractorID = Convert.ToInt32(ddlContractor.SelectedValue);
                }
                if (Convert.ToInt32(ddlAppraiser.SelectedValue) != 0)
                {
                    objLead.AppraiserID = Convert.ToInt32(ddlAppraiser.SelectedValue);
                }

                // mailing address
                objLead.MailingAddress  = txtMailingAddress.Text.Trim();
                objLead.MailingAddress2 = txtMailingAddress2.Text.Trim();
                objLead.MailingCity     = txtMailingCity.Text.Trim();

                if (ddlMailingState.SelectedIndex > 0)
                {
                    objLead.MailingState = ddlMailingState.SelectedValue;
                }

                objLead.MailingZip = txtMailingZip.Text.Trim();

                // Loss Address
                objLead.LossAddress  = txtLossAddress.Text;
                objLead.LossAddress2 = txtLossAddress2.Text;

                if (ddlState.SelectedIndex > 0)
                {
                    objLead.StateName = ddlState.SelectedValue;
                }

                objLead.CityName = txtCityName.Text;
                objLead.Zip      = txtZipCode.Text;

                // check for duplicate name/address
                isDuplicate = LeadsManager.CheckForDuplicate(objLead);
                if (isDuplicate)
                {
                    lblError.Text    = "Duplicate clients not allowed.";
                    lblError.Visible = true;
                    return;
                }

                objLead.EmailAddress = txtEmail.Text;
                if (Convert.ToInt32(ddlLeadSource.SelectedValue) != 0)
                {
                    objLead.LeadSource = Convert.ToInt32(ddlLeadSource.SelectedValue);
                }
                if (Convert.ToInt32(ddlPrimaryProducer.SelectedValue) != 0)
                {
                    objLead.PrimaryProducerId = Convert.ToInt32(ddlPrimaryProducer.SelectedValue);
                }
                if (Convert.ToInt32(ddlSecondaryProducer.SelectedValue) != 0)
                {
                    objLead.SecondaryProducerId = Convert.ToInt32(ddlSecondaryProducer.SelectedValue);
                }

                objLead.PhoneNumber = txtPhoneNumber.Text;
                objLead.MobilePhone = txtMobilePhone.Text;

                //string Damagetxt = string.Empty;
                //string DamageId = string.Empty;
                //for (int j = 0; j < chkTypeOfDamage.Items.Count; j++) {
                //	if (chkTypeOfDamage.Items[j].Selected == true) {
                //		Damagetxt += chkTypeOfDamage.Items[j].Text + ',';
                //		DamageId += chkTypeOfDamage.Items[j].Value + ',';
                //	}
                //}
                //if (Damagetxt != string.Empty && DamageId != string.Empty) {
                //	objLead.TypeOfDamage = DamageId;
                //	objLead.TypeofDamageText = Damagetxt;
                //}

                //if (Convert.ToInt32(ddlTypeOfProperty.SelectedValue) != 0) {
                //	objLead.TypeOfProperty = Convert.ToInt32(ddlTypeOfProperty.SelectedValue);
                //}



                objLead.IsSubmitted = true;



                objLead.SiteSurveyDate  = siteSurveyDate;
                objLead.LastContactDate = lastContactDate;
                if (Convert.ToInt32(ddlOwnerSame.SelectedValue) != 0)
                {
                    objLead.OwnerSame = Convert.ToInt32(ddlOwnerSame.SelectedValue);
                }
                objLead.OwnerFirstName = txtOwnerFirstName.Text.Trim();
                objLead.OwnerLastName  = txtOwnerLastName.Text.Trim();
                objLead.OwnerPhone     = txtOwnerPhone.Text.Trim();

                // 2013-03-11 tortega added owner email
                objLead.OwnerEmail = txtOwnerEmail.Text.Trim();

                objLead.SecondaryEmail = txtSecondaryEmail.Text.Trim();
                objLead.SecondaryPhone = txtSecondaryPhone.Text.Trim();
                //save new fields
                if (!string.IsNullOrEmpty(txtBirthdate.Text))
                {
                    objLead.Birthdate = Convert.ToDateTime(txtBirthdate.Text);
                }
                objLead.Reference     = txtReference.Text;
                objLead.Languages     = txtLanguage.Text;
                objLead.Title         = txtTitle.Text;
                objLead.LossCounty    = txtlossCountry.Text;
                objLead.MailingCounty = txtMailingCountry.Text;

                Leads ins = LeadsManager.Save(objLead);


                if (ins.LeadId > 0)
                {
                    int      categoryId = ContactManager.GetContactId("Claimant");;
                    Contact  objcontact = ContactManager.GetLeadContact(objLead.LeadId, categoryId);
                    string[] name       = txtThirdPartyName.Text.Split(' ');
                    int      nameLength = name.Length;
                    string   firstName  = string.Empty;
                    string   lastName   = string.Empty;
                    firstName = firstName.Trim();
                    if (nameLength > 1)
                    {
                        for (int count = 0; count <= nameLength - 2; count++)
                        {
                            firstName = firstName + " " + name[count];
                        }
                        lastName = name[nameLength - 1];
                    }
                    else
                    {
                        firstName = name[0];
                    }

                    Contact contact = null;
                    contact = new Contact();
                    if (objcontact != null)
                    {
                        contact.ContactID = objcontact.ContactID;
                    }
                    contact.LeadId      = ins.LeadId;
                    contact.ClientID    = SessionHelper.getClientId();
                    contact.UserID      = SessionHelper.getUserId();
                    contact.IsActive    = true;
                    contact.FirstName   = firstName.Trim();
                    contact.LastName    = lastName.Trim();
                    contact.ContactName = firstName.Trim() + " " + lastName.Trim();;
                    contact.Address1    = txtThirdPartyStreet.Text;
                    contact.CityName    = txtThirdPartyCity.Text;
                    contact.State       = txtThirdPartyState.Text;
                    contact.ZipCode     = txtThirdPartyPostalCodes.Text;
                    contact.Phone       = txtThirdPartyPhoneNumber.Text;

                    contact.CategoryID = categoryId;
                    if (objcontact == null)
                    {
                        contact = ContactManager.SaveContact(contact);
                        //Contact contactupdate = new Contact();
                        //contactupdate.ContactID = contact.ContactID;
                        //contactupdate.ContactName = contact.ContactName;
                        //contact = ContactManager.UpdateContact(contactupdate);
                    }
                    else
                    {
                        contact = ContactManager.Update(contact);
                    }



                    Session["LeadIds"] = ins.LeadId;

                    ViewState["LeadIds"] = ins.LeadId;

                    //savePolicy();

                    //SaveLeadLog(objLead);

                    showControls(true);

                    lblSave.Text = "Claim/Lead information saved successfully.";

                    lblSave.Visible = true;

                    //// repopulate policy info after saving a new lead
                    //if (isNew) {
                    //	fillPolicy(ins.LeadId);
                    //}
                }
            }
            catch (Exception ex) {
                lblError.Text    = "Your update could not be saved for the following reason(s):<br />" + ex.ToString();
                lblError.Visible = true;
            }
        }