private bool Save() { #region get user input string sFirstName = this.txtFirstName.Text.Trim(); string sLastName = this.txtLastName.Text.Trim(); string sEmail = this.txtEmail.Text.Trim(); string sPhone = this.txtPhone.Text.Trim(); string sType = this.ddlType.SelectedValue; string sDOB = this.txtBirthday.Text.Trim(); if (!string.IsNullOrEmpty(sDOB)) { DateTime DOB; if (DateTime.TryParse(sDOB, out DOB) == false) { //PageCommon.AlertMsg(this, "Date of Birth is not a invalid date format."); PageCommon.WriteJsEnd(this, "Date of Birth is not a invalid date format.", PageCommon.Js_RefreshSelf); return(false); } } string sSSN = this.txtSSN.Text.Trim(); string sWorkflow = this.ddlWorkflow.SelectedValue; int iWflTempID = 0; int.TryParse(sWorkflow, out iWflTempID); string sMarketing = this.ddlMarketing.SelectedValue; // MailChimpList ID // Task Name string sTaskName = string.Empty; if (this.radTaskList.Checked == true) { if (this.ddlTaskList.SelectedValue == "-- select --") { sTaskName = string.Empty; } else { sTaskName = this.ddlTaskList.SelectedValue; } } else { sTaskName = this.txtTaskName.Text.Trim(); } // Due Date string sDueDate = this.txtDueDate.Text.Trim(); DateTime DueDate; if (sDueDate != string.Empty) { if (DateTime.TryParse(sDueDate, out DueDate) == false) { //PageCommon.AlertMsg(this, "Due Date is not a invalid date format."); PageCommon.WriteJsEnd(this, "Due Date is not a invalid date format.", PageCommon.Js_RefreshSelf); return(false); } DueDate = DateTime.Parse(sDueDate); } // Due Time string sDueTime = ddlDueTime_hour.Text + ":" + ddlDueTime_min.Text; //this.txtDueTime.Text.Trim(); DateTime DTN = DateTime.Now; string sDueTime_Span = null; TimeSpan DueTime = new TimeSpan(); if (sDueTime != string.Empty) { if (DateTime.TryParse(sDueTime, out DTN) == true) { sDueTime_Span = DTN.ToString("HH:mm"); if (TimeSpan.TryParse(sDueTime_Span, out DueTime) == false) { //PageCommon.AlertMsg(this, "Invalid Due Time format."); PageCommon.WriteJsEnd(this, "Invalid Due Time format.", PageCommon.Js_RefreshSelf); return(false); } } else { //PageCommon.AlertMsg(this, "Invalid Due Time format."); PageCommon.WriteJsEnd(this, "Invalid Due Time format.", PageCommon.Js_RefreshSelf); return(false); } } string sReminderUser = string.Empty; string sReminderUserID = string.Empty; int iReminderUserID = 0; string sReminderInterval = string.Empty; if (this.chkReminder.Checked == true) { sReminderUser = this.txtReminderUser.Text.Trim(); sReminderUserID = this.hdnReminderUserID.Value; iReminderUserID = Convert.ToInt32(sReminderUserID); sReminderInterval = this.ddlReminderInterval.SelectedValue; } //CR53 decimal loanAmount = string.IsNullOrEmpty(txtLoanAmount.Text) ? 0M : Convert.ToDecimal(txtLoanAmount.Text.Trim()); string purpose = ddlPurpose.Text.Trim() == "- select -" ? "" : ddlPurpose.Text; #endregion #region create contact/prospect and loan int iContactId = 0; try { iContactId = this.CreateContactAndProspect(sFirstName, sLastName, sEmail, sType, sPhone, sDOB, sSSN, this.CurrUser.iUserID, purpose); } catch (Exception ex) { //PageCommon.AlertMsg(this, "Failed to save contact and prospect."); PageCommon.WriteJsEnd(this, "Failed to save contact and prospect." + ex.Message, PageCommon.Js_RefreshSelf); return(false); } #endregion #region create loan //int iFileID = 0; try { iFileID = this.CreateLoan(iContactId, loanAmount, purpose); } catch (Exception ex) { //PageCommon.AlertMsg(this, "Failed to save loan info."); PageCommon.WriteJsEnd(this, "Failed to save loan info.", PageCommon.Js_RefreshSelf); return(false); } #endregion #region Apply LoanWflTempl if (iWflTempID > 0) { try { this.ApplyLoanWflTempl(iFileID, iWflTempID, this.CurrUser.iUserID); } catch (Exception ex) { //PageCommon.AlertMsg(this, "Failed to apply workflow template to loan."); PageCommon.WriteJsEnd(this, "Failed to apply workflow template to loan.", PageCommon.Js_RefreshSelf); return(false); } } #endregion #region GenerateWorkflow and get iCurrentLoanStageId int iCurrentLoanStageId = 0; if (iWflTempID > 0) { string sError; bool bResult = this.GenerateWorkflow(iFileID, iWflTempID, this.CurrUser.iUserID, out sError); if (bResult == false) { //PageCommon.AlertMsg(this, "Failed to generate workflow template: " + sError); PageCommon.WriteJsEnd(this, "Failed to generate workflow template: " + sError, PageCommon.Js_RefreshSelf); return(false); } System.Threading.Thread.Sleep(2000); // get current loan stage id iCurrentLoanStageId = LPWeb.BLL.WorkflowManager.GetCurrentLoanStageId(iFileID); } else if (!string.IsNullOrEmpty(sTaskName)) { iWflTempID = LPWeb.BLL.WorkflowManager.GetDefaultWorkflowTemplate("Prospect"); if (iWflTempID < 1) { iCurrentLoanStageId = LPWeb.BLL.WorkflowManager.GenerateDefaultLoanStages(iFileID, "Prospect"); } } #endregion #region Create Task and Reminder if (!string.IsNullOrEmpty(sTaskName)) { #region create task if (iCurrentLoanStageId < 0) { //PageCommon.AlertMsg(this, "There is no loan stage available."); PageCommon.WriteJsEnd(this, "There is no loan stage available.", PageCommon.Js_RefreshSelf); return(false); } int iLoanTaskId = 0; try { iLoanTaskId = this.CreateLoanTask(iFileID, sTaskName, this.CurrUser.iUserID, sDueDate, sDueTime, iCurrentLoanStageId); } catch (Exception ex) { } #endregion #region reminder if (this.chkReminder.Checked == true) { string sReminderDueTime = string.Empty; if (sDueTime != string.Empty) { TimeSpan Interval = new TimeSpan(); if (sReminderInterval.Contains("minutes") == true) { string sMinutes = sReminderInterval.Replace(" minutes", ""); int iMinutes = Convert.ToInt32(sMinutes); Interval = new TimeSpan(0, iMinutes, 0); } else if (sReminderInterval.Contains("hours") == true) { string sHours = sReminderInterval.Replace(" hours", ""); int iHours = Convert.ToInt32(sHours); Interval = new TimeSpan(iHours, 0, 0); } TimeSpan ReminderDueTime = DueTime.Add(Interval); sReminderDueTime = ReminderDueTime.ToString(); } string sReminderTaskName = sTaskName + " - Quick Lead Form - Reminder"; if (iReminderUserID == this.CurrUser.iUserID && sDueDate == DateTime.Now.ToString("MM/dd/yyyy")) { this.CurrUser.InitTaskListDueToday(); } } #endregion } #endregion #region API MailChimp_Subscribe if (sMarketing != string.Empty) { string sError2 = string.Empty; bool bResult2 = this.MailChimp_Subscribe(iContactId, sMarketing, out sError2); if (bResult2 == false) { //PageCommon.AlertMsg(this, "Failed to invoke API MailChimp_Subscribe: " + sError2); PageCommon.WriteJsEnd(this, "Failed to invoke API MailChimp_Subscribe: " + sError2, PageCommon.Js_RefreshSelf); return(false); } } #endregion if (ddlLoanOfficer.SelectedValue == "0") //Lead Routing Engine { #region invoke the WCF API LeadRouting_AssignLoanOfficer try { ServiceManager sm = new ServiceManager(); using (LP2ServiceClient client = sm.StartServiceClient()) { LR_AssignLoanOfficerReq req = new LR_AssignLoanOfficerReq(); req.LoanId = iFileID; req.LoanOfficerId = iLoanOfficerID; req.BorrowerContactId = iContactId; req.CoBorrowerContactId = 0; req.ReqHdr = new ReqHdr(); req.ReqHdr.UserId = CurrUser.iUserID; req.ReqHdr.SecurityToken = "SecurityToken"; RespHdr resp = client.LeadRouting_AssignLoanOfficer(req); } } catch (Exception ex) { PageCommon.WriteJsEnd(this, "Pulse Lead Manager is not running. Please select a Loan Officer from the list and save the lead.", PageCommon.Js_RefreshSelf); return(false); } #endregion } return(true); }