private bool PostLead(string xml_data, out string response_text) { bool ret_status = false; try { DataSet ds = new DataSet(); ZillowAttributeCollection zcol = new ZillowAttributeCollection(); // Parse the xml and populate the ZillowAttributeCollection using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml_data))) { using (StreamReader reader = new StreamReader(stream)) { // copy data into collection ds.ReadXml(reader, XmlReadMode.Auto); zcol = ImportManager.ImportLeadFromZillowv5(ds); // re-read the xml stream.Seek(0, SeekOrigin.Begin); zcol.ZillowXml = reader.ReadToEnd(); } } // Read security token zcol.PulseSecurityToken = Helpers.ReadSecurityToken(); // Get Pulse Lead Request object from ZillowAttributeCollection PostLeadRequest pulse_lead_req = PulseLeadClient.GetPulseLeadRequest(zcol); // post request ResponseHdr response_hdr = PulseLeadClient.PostPulseLeadRequest(pulse_lead_req, zcol.ImportTransId.ToString()); if (response_hdr.Successful) { zcol.ReturnStatus = "Success"; ret_status = true; zcol.BorrowerId = response_hdr._postArgs.ContactId; zcol.CoborrowerId = response_hdr._postArgs.CoBorrowerContactId; zcol.LoanId = response_hdr._postArgs.LoanId; } else { zcol.ReturnStatus = "Failed."; } zcol.Save(); response_text = zcol.ReturnStatus; } catch (Exception ex) { response_text = "Application Error<br/>" + ex.Message; NLogger.Error(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, ex.Message, ex); } return(ret_status); }
protected void ButtonSubmit_Click(object sender, EventArgs e) { try { DataSet ds = new DataSet(); ZillowAttributeCollection zcol = new ZillowAttributeCollection(); // Parse the xml and populate the ZillowAttributeCollection using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(TextBoxZillowXml.Text))) { using (StreamReader reader = new StreamReader(stream)) { // copy data into collection ds.ReadXml(reader, XmlReadMode.Auto); zcol = ImportManager.ImportLeadFromZillowv5(ds); // re-read the xml stream.Seek(0, SeekOrigin.Begin); zcol.ZillowXml = reader.ReadToEnd(); } } // Read security token zcol.PulseSecurityToken = Helpers.ReadSecurityToken(); // Get Pulse Lead Request object from ZillowAttributeCollection PostLeadRequest pulse_lead_req = PulseLeadClient.GetPulseLeadRequest(zcol); // post request ResponseHdr response_hdr = PulseLeadClient.PostPulseLeadRequest(pulse_lead_req, zcol.ImportTransId.ToString()); if (response_hdr.Successful) { zcol.ReturnStatus = "Success"; zcol.BorrowerId = response_hdr._postArgs.ContactId; zcol.CoborrowerId = response_hdr._postArgs.CoBorrowerContactId; zcol.LoanId = response_hdr._postArgs.LoanId; } else { zcol.ReturnStatus = "Failed."; } zcol.Save(); // display html formatted LiteralResults.Text = "<p>Response Status: " + zcol.ReturnStatus + "</p><p>" + Helpers.FriendlyHtml(zcol) + "</p>"; } catch (Exception ex) { LiteralResults.Text = "Application Error<br/>" + ex.Message; } }
/// <summary> /// Returns the PostLeadRequest object populated with Zillow XML data /// </summary> /// <param name="zcol"></param> /// <returns></returns> internal static PostLeadRequest GetPulseLeadRequest(ZillowAttributeCollection zcol) { try { PostLeadRequest req = MapZillowToPulseLeadRequest(zcol); NLogger.Info(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, "ZillowImport (" + zcol.ImportTransId.ToString() + ") completed."); return(req); } catch (Exception ex) { NLogger.Error(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, ex.Message, ex); throw; } }
protected void ButtonParse_Click(object sender, EventArgs e) { try { // Parse the xml and populate the ZillowAttributeCollection StringReader tr = new StringReader(TextBoxZillowXml.Text); // move data into collection DataSet ds = new DataSet(); ds.ReadXml(tr, XmlReadMode.Auto); ZillowAttributeCollection zcoll = ImportManager.ImportLeadFromZillowv5(ds); // display html formatted LiteralResults.Text = Helpers.FriendlyHtml(zcoll); } catch (Exception ex) { LiteralResults.Text = "Error: " + ex.Message; } }
/// <summary> /// Returns the credit score read from the Zillow Xml /// </summary> /// <param name="zcol"></param> /// <returns></returns> private static int?GetCreditScore(ZillowAttributeCollection zcol) { IEnumerable <ZillowAttribute> query = from p in zcol.ZillowAttributes where p.GroupName.Equals("CreditScore", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("CreditScore_Text", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { int int_value; if (int.TryParse(query.First().AttributeValue, out int_value)) { return(int_value > 0 ? (int?)int_value : null); } } } return(null); }
internal static string FriendlyHtml(ZillowAttributeCollection zcol) { // Get Pulse Lead Request object from ZillowAttributeCollection PostLeadRequest pulse_lead_req = PulseLeadClient.GetPulseLeadRequest(zcol); // display results StringBuilder sb = new StringBuilder(); sb.AppendLine(@"<div class='col1'>Zillow Xml Attributes<br>"); sb.AppendLine("<table class='imagetable'>"); sb.AppendLine("<tr><th>GroupName</th><th>AttributeName</th><th>AttributeValue</th></tr>"); foreach (ZillowAttribute attrib in zcol.ZillowAttributes) { sb.AppendLine("<tr><td>" + attrib.GroupName + "</td>" + "<td>" + attrib.AttributeName + "</td>" + "<td>" + attrib.AttributeValue + "</td></tr>"); } sb.AppendLine("</table></div>"); sb.AppendLine(@"<div class='col2'>Pulse Lead Request<br>"); sb.AppendLine("<table class='imagetable'>"); sb.AppendLine("<tr><th>Name</th><th>Value</th></tr>"); foreach (FieldInfo f in pulse_lead_req.GetType().GetFields()) { if (f.Name.Equals("Employment", StringComparison.OrdinalIgnoreCase) && pulse_lead_req.Employment != null) { continue; } if (f.Name.Equals("OtherIncome", StringComparison.OrdinalIgnoreCase) && pulse_lead_req.OtherIncome != null) { continue; } if (f.Name.Equals("LiquidAssets", StringComparison.OrdinalIgnoreCase) && pulse_lead_req.LiquidAssets != null) { continue; } if (f.Name.Equals("RequestHeader", StringComparison.OrdinalIgnoreCase) && pulse_lead_req.RequestHeader != null) { continue; } sb.AppendLine("<tr><td>" + f.Name + "</td>" + "<td>" + f.GetValue(pulse_lead_req) + "</td></tr>"); } foreach (FieldInfo f in pulse_lead_req.GetType().GetFields()) { if (f.Name.Equals("RequestHeader", StringComparison.OrdinalIgnoreCase) && pulse_lead_req.RequestHeader != null) { sb.AppendLine("<tr><th colspan=2><strong>Request Header</strong></th></tr>"); foreach (FieldInfo f1 in pulse_lead_req.RequestHeader.GetType().GetFields()) { sb.AppendLine("<tr><td>" + f1.Name + "</td>" + "<td>" + f1.GetValue(pulse_lead_req.RequestHeader) + "</td></tr>"); } } else if (f.Name.Equals("Employment", StringComparison.OrdinalIgnoreCase) && pulse_lead_req.Employment != null) { sb.AppendLine("<tr><th colspan=2><strong>Employment</strong></th></tr>"); foreach (Employment employment in pulse_lead_req.Employment) { foreach (FieldInfo f1 in employment.GetType().GetFields()) { sb.AppendLine("<tr><td>" + f1.Name + "</td>" + "<td>" + f1.GetValue(employment) + "</td></tr>"); } } } else if (f.Name.Equals("OtherIncome", StringComparison.OrdinalIgnoreCase) && pulse_lead_req.OtherIncome != null) { sb.AppendLine("<tr><th colspan=2><strong>OtherIncome</strong></th></tr>"); foreach (OtherIncome other_income in pulse_lead_req.OtherIncome) { foreach (FieldInfo f1 in other_income.GetType().GetFields()) { sb.AppendLine("<tr><td>" + f1.Name + "</td>" + "<td>" + f1.GetValue(other_income) + "</td></tr>"); } } } else if (f.Name.Equals("LiquidAssets", StringComparison.OrdinalIgnoreCase) && pulse_lead_req.LiquidAssets != null) { sb.AppendLine("<tr><th colspan=2><strong>LiquidAssets</strong></th></tr>"); foreach (LiquidAssets liquid_assets in pulse_lead_req.LiquidAssets) { foreach (FieldInfo f1 in liquid_assets.GetType().GetFields()) { sb.AppendLine("<tr><td>" + f1.Name + "</td>" + "<td>" + f1.GetValue(liquid_assets) + "</td></tr>"); } } } } sb.AppendLine("</table></div>"); return(sb.ToString()); }
/// <summary> /// Populates PostLeadRequest with Zillow XML data /// </summary> /// <param name="zcol"></param> /// <returns></returns> private static PostLeadRequest MapZillowToPulseLeadRequest(ZillowAttributeCollection zcol) { // initialize request object PostLeadRequest req = new PostLeadRequest(); req.RequestHeader = new RequestHeader(); req.RequestHeader.SecurityToken = zcol.PulseSecurityToken; IEnumerable <ZillowAttribute> query = from p in zcol.ZillowAttributes where p.GroupName.Equals("ZillowMortgageContactList", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("version", StringComparison.OrdinalIgnoreCase) select p; req.LeadSource = CONST_LEADSOURCE + " v" + query.First().AttributeValue; //------------------------------------------------------------------ // CreditScore // Excellent = 1, 750-850 // VeryGood = 2, 700-749 // Good = 3, 650-699 // Fair = 4, 600-649 // Poor = 5, 300-599 query = from p in zcol.ZillowAttributes where p.GroupName.Equals("CreditScore", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("CreditScore_Text", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { int int_value; if (int.TryParse(query.First().AttributeValue, out int_value)) { req.CreditScore = int_value; if (int_value <= 599) { req.CreditRanking = CreditRanking.Poor; } else if (int_value <= 649) { req.CreditRanking = CreditRanking.Fair; } else if (int_value <= 699) { req.CreditRanking = CreditRanking.Good; } else if (int_value <= 749) { req.CreditRanking = CreditRanking.VeryGood; } else { req.CreditRanking = CreditRanking.Excellent; } } } } //------------------------------------------------------------------ //BaseMonthlyIncome query = from p in zcol.ZillowAttributes where p.GroupName.Equals("PrimaryBorrower", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("BaseMonthlyIncome", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { decimal d_value; if (decimal.TryParse(query.First().AttributeValue, out d_value)) { req.Employment = new Employment[] { new Employment() { MonthlySalary = d_value } }; } } } //------------------------------------------------------------------ //AdditionalMonthlyIncome query = from p in zcol.ZillowAttributes where p.GroupName.Equals("PrimaryBorrower", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("AdditionalMonthlyIncome", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { decimal d_value; if (decimal.TryParse(query.First().AttributeValue, out d_value)) { req.OtherIncome = new OtherIncome[] { new OtherIncome() { Amount = d_value } }; } } } //------------------------------------------------------------------ //PropertyUsage query = from p in zcol.ZillowAttributes where p.GroupName.Equals("PropertyDetails", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("PropertyUsage", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { if (query.First().AttributeValue.Equals("primaryResidence", StringComparison.OrdinalIgnoreCase)) { req.OccupancyType = OccupancyType.PrimaryResidence; } else if (query.First().AttributeValue.Equals("secondaryOrVacation", StringComparison.OrdinalIgnoreCase)) { req.OccupancyType = OccupancyType.SecondHome; } else if (query.First().AttributeValue.Equals("investmentOrRental", StringComparison.OrdinalIgnoreCase)) { req.OccupancyType = OccupancyType.InvestmentProperty; } } } //------------------------------------------------------------------ //LoanAmount query = from p in zcol.ZillowAttributes where p.GroupName.Equals("LoanDetails", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("LoanAmount", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { int int_value; if (int.TryParse(query.First().AttributeValue, out int_value)) { req.LoanAmount = int_value; } } } //------------------------------------------------------------------ //EstimatedPropertyValue query = from p in zcol.ZillowAttributes where p.GroupName.Equals("EstimatedPropertyValue", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("EstimatedPropertyValue_Text", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { int int_value; if (int.TryParse(query.First().AttributeValue, out int_value)) { req.PropertyValue = int_value; } } } //------------------------------------------------------------------ //Assets query = from p in zcol.ZillowAttributes where p.GroupName.Equals("Asset", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { List <LiquidAssets> lassets = new List <LiquidAssets>(); string name_of_account = "Not provided"; foreach (ZillowAttribute item in query) { if (item.AttributeName.Equals("type", StringComparison.OrdinalIgnoreCase)) { name_of_account = item.AttributeValue; } else if (item.AttributeName.Equals("asset_text", StringComparison.OrdinalIgnoreCase)) { decimal d_value; if (decimal.TryParse(item.AttributeValue, out d_value)) { lassets.Add(new LiquidAssets { NameOfAccount = name_of_account, Amount = d_value, AccountNo = "" }); name_of_account = "Not provided"; } } } if (lassets.Any()) { req.LiquidAssets = lassets.ToArray(); } } //------------------------------------------------------------------ //LoanPurpose query = from p in zcol.ZillowAttributes where p.GroupName.Equals("LoanRequestCreated", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("LoanPurpose", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { if (query.First().AttributeValue.Equals("purchase", StringComparison.OrdinalIgnoreCase)) { req.PurposeOfLoan = PurposeOfLoan.Purchase; } else if (query.First().AttributeValue.Equals("refinance", StringComparison.OrdinalIgnoreCase)) { req.PurposeOfLoan = PurposeOfLoan.Refinance_No_Cashout; } else if (query.First().AttributeValue.Equals("homeEquity", StringComparison.OrdinalIgnoreCase)) { req.PurposeOfLoan = PurposeOfLoan.Refinance_Cashout; } } //<xsd:enumeration value="purchase"/> //<xsd:enumeration value="refinance"/> //<xsd:enumeration value="homeEquity"/> // req.PurposeOfLoan = PurposeOfLoan.Construction; // req.PurposeOfLoan = PurposeOfLoan.Other; // req.PurposeOfLoan = PurposeOfLoan.Purchase; // req.PurposeOfLoan = PurposeOfLoan.Refinance_Cashout; // req.PurposeOfLoan = PurposeOfLoan.Refinance_No_Cashout; } //------------------------------------------------------------------ //FirstName query = from p in zcol.ZillowAttributes where p.GroupName.Equals("WebContact", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("FirstName", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.BorrowerFirstName = Helpers.FormatSqlStringValue(query.First().AttributeValue, 50); } } //------------------------------------------------------------------ //LastName query = from p in zcol.ZillowAttributes where p.GroupName.Equals("WebContact", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("LastName", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.BorrowerLastName = Helpers.FormatSqlStringValue(query.First().AttributeValue, 50); } } //------------------------------------------------------------------ //EmailAddress query = from p in zcol.ZillowAttributes where p.GroupName.Equals("WebContact", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("EmailAddress", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.Email = Helpers.FormatSqlStringValue(query.First().AttributeValue, 255); } } //------------------------------------------------------------------ //PhoneNumber query = from p in zcol.ZillowAttributes where p.GroupName.Equals("WebContact", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("PhoneNumber", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.HomePhone = Helpers.FormatSqlStringValue(query.First().AttributeValue, 20); } } //------------------------------------------------------------------ //Message query = from p in zcol.ZillowAttributes where p.GroupName.Equals("WebContact", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("Message", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.Notes = Helpers.FormatSqlStringValue(query.First().AttributeValue, 4000); } } //------------------------------------------------------------------ //City query = from p in zcol.ZillowAttributes where p.GroupName.Equals("PropertyDetails", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("City", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.Property_City = Helpers.FormatSqlStringValue(query.First().AttributeValue, 50); } } //------------------------------------------------------------------ //State query = from p in zcol.ZillowAttributes where p.GroupName.Equals("PropertyDetails", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("State", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.Property_State = Helpers.ConvertStateNameToAbbrev(query.First().AttributeValue); } } //------------------------------------------------------------------ //StreetAddress query = from p in zcol.ZillowAttributes where p.GroupName.Equals("PropertyInfoType", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("StreetAddress", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.Property_Street = Helpers.FormatSqlStringValue(query.First().AttributeValue, 50); } } //------------------------------------------------------------------ //Zip query = from p in zcol.ZillowAttributes where p.GroupName.Equals("PropertyDetails", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("Zip", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.Property_Zip = Helpers.FormatSqlStringValue(query.First().AttributeValue, 10); } } //------------------------------------------------------------------ //PropertyType query = from p in zcol.ZillowAttributes where p.GroupName.Equals("PropertyDetails", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("PropertyType", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.PropertyType = Helpers.FormatSqlStringValue(query.First().AttributeValue, 255); } } //------------------------------------------------------------------ //CurrentLoanProgram query = from p in zcol.ZillowAttributes where p.GroupName.Equals("LoanDetails", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("CurrentLoanProgram", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { req.LoanProgram = Helpers.FormatSqlStringValue(query.First().AttributeValue, 255); } } return(req); }
/// <summary> /// Saves the ZillowAttributeCollection to the Pulse database /// </summary> /// <param name="collection"></param> internal static void Save(ZillowAttributeCollection collection) { }
/// <summary> /// Parses the Zillow XML into the ZillowAttributeCollection /// </summary> /// <param name="ds"></param> /// <returns></returns> internal static ZillowAttributeCollection ImportLeadFromZillowv5(DataSet ds) { try { // Initialize objects and import N/V pairs ZillowAttributeCollection collection = new ZillowAttributeCollection(); foreach (DataTable dt in ds.Tables) { foreach (DataRow dr in dt.Rows) { foreach (DataColumn dc in dt.Columns) { collection.ZillowAttributes.Add(new ZillowAttribute() { GroupName = dt.TableName, AttributeName = dc.ColumnName, AttributeValue = dr[dc].ToString() }); } } } // Validate only Version 5 is supported IEnumerable <ZillowAttribute> query = from p in collection.ZillowAttributes where p.GroupName.Equals("ZillowMortgageContactList", StringComparison.OrdinalIgnoreCase) && p.AttributeName.Equals("version", StringComparison.OrdinalIgnoreCase) select p; if (query.Any()) { if (!string.IsNullOrEmpty(query.First().AttributeValue)) { if (!query.First().AttributeValue.Equals("5")) { ApplicationException appex = new ApplicationException("Application Error: only ZillowMortgageContactList version 5 is supported."); NLogger.Error(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, appex.Message, appex); throw appex; } } else { ApplicationException appex = new ApplicationException("Application Error: unable to locate version in ZillowMortgageContactList."); NLogger.Error(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, appex.Message, appex); throw appex; } } else { ApplicationException appex = new ApplicationException("Application Error: unable to parse the Zillow XML."); NLogger.Error(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, appex.Message, appex); throw appex; } // update the collection's xml version collection.XmlVersion = query.First().AttributeValue; return(collection); } catch (Exception ex) { NLogger.Error(MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, ex.Message, ex); throw; } }