public string AddRentValuationRecord(HOBAppUser user, Address address, RentValuationData rentValuationData) { // check if the user is already there AppUsers existingUser = FindUser(user.Email); // if this user not found, then add. string existingUserId = string.Empty; if (existingUser == null) { existingUserId = AddNewUser(user); } else { // also update the user UpdateUser(existingUser, user); existingUserId = existingUser.UserId; var IPAddress = FindIPAddress(existingUserId, user.ClientIPAddress); if (IPAddress == null) { AddNewIPAddress(existingUserId, user.ClientIPAddress); } } // check if this address is already there. Or else add. var existingAddress = FindAddress(existingUserId, address); string existingAddressId = string.Empty; if (existingAddress == null) { existingAddressId = AddNewAddress(existingUserId, address); } else { existingAddressId = existingAddress.AddressId; } // we always add the rent valuation record everytime as it will keep changing as per market fluctuation var newRentValuationRecordGuid = Guid.NewGuid().ToString(); homeOwnerBestieDBContext.RentValuationReports.Add(new RentValuationReports() { AverageMonthlyRent = rentValuationData.AverageMonthlyRent, IsRentEstimateAvailable = rentValuationData.IsRentEstimateAvailable, RentValuationRecordId = newRentValuationRecordGuid, ValuationRentHigh = rentValuationData.ValuationRentHigh, ValuationRentLow = rentValuationData.ValuationRentLow, ValueChangedIn30Days = rentValuationData.ValueChangedIn30Days, DateCreated = DateTime.Now, UserId = existingUserId, AddressId = existingAddressId }); homeOwnerBestieDBContext.SaveChanges(); return(newRentValuationRecordGuid); }
public string AddRentValuationRecord(HOBAppUser user, Address address, RentValuationData rentValuationData) { try { return(leadDataProvider.AddRentValuationRecord(user, address, rentValuationData)); } catch (Exception ex) { //TBD return(null); } }
public bool EmailRentValuationReport(HOBAppUser user, decimal homeOwnerSpecifiedRent) { string userId = this.leadDataManager.GetUserIdFromEmail(user.Email); string updatedRentValuationRecord = this.leadDataManager.UpdateHomeOwnerSpecifiedRent(userId, homeOwnerSpecifiedRent); RentValuationData rentValuationData = this.leadDataManager.FindRentValuationRecord(updatedRentValuationRecord); Address address = this.leadDataManager.GetAddressFromRentValuationRecordId(updatedRentValuationRecord); //var jsonUser = JsonConvert.SerializeObject(user); //var jsonRentValuationData = JsonConvert.SerializeObject(rentValuationData); //var jsonAddress = JsonConvert.SerializeObject(address); EmailEnvelop emailEnvelope = new EmailEnvelop() { Body = "<h1>Congratulations on your signup!</h1>" + "<hr/>" + "<h2>Here is the data we have collected from you.</h2>" + "<h3>User Info</h3>" + "<p> Name: " + user.FirstName + " " + user.LastName + "</p>" + "<p> IP Address: " + user.ClientIPAddress + "</p>" + "<p> Phone: " + user.Phone + "</p>" + "<h3>Rent Valuation Data</h3>" + "<p> Home Owner Specified Rent: " + (rentValuationData.HomeOwnerSpecifiedRent == 0 ? "None" : rentValuationData.HomeOwnerSpecifiedRent.ToString()) + "</p>" + "<p> Average Monthly Rent: " + rentValuationData.AverageMonthlyRent + "</p>" + "<p> Valuation Range High : " + rentValuationData.ValuationRentHigh + "</p>" + "<p> Valuation Range Low : " + rentValuationData.ValuationRentLow + "</p>" + "<p> Value Changed In 30 Days: " + rentValuationData.ValueChangedIn30Days + "</p>" + "<p> Is Rent Estimate Available: " + (rentValuationData.IsRentEstimateAvailable?"Yes":"No") + "</p>" + "<h3>Home Address</h3>" + "<p> Street: " + address.Street + "</p>" + "<p> City: " + address.City + "</p>" + "<p> County: " + (!string.IsNullOrEmpty(address.County)?address.County:"--") + "</p>" + "<p> State: " + address.State + "</p>" + "<p> Zip: " + address.Zip + "</p>" + "<h4>Thank you. Visit us again!</h4>" + "<h5>Best wishes from Home Owner Bestie Team :-)</h5>", From = "*****@*****.**", To = user.Email, Subject = $"Hello {user.FirstName}! Your Home Rent Valuation Info is now ready.", }; EmailConfig emailConfig = new EmailConfig() { Password = "******", Port = 587, Smtp = "smtp.gmail.com", UserName = "******" }; return(Utils.SendEmail(emailEnvelope, emailConfig)); }
public RentValuationData RunRentEvaluation(HOBAppUser user, Address address) { RentValuationData rentValuationData = realEstateDataProvider.RunRentEvaluation(address); if (rentValuationData == null) { return(rentValuationData); } string rentValuationRecordId = leadDataManager.AddRentValuationRecord(user, address, rentValuationData); if (string.IsNullOrWhiteSpace(rentValuationRecordId)) { return(null); } return(rentValuationData); }
public RentValuationData RunRentEvaluation(Address address) { if (address == null) { return(null); } string url = $"{mApiUrl}?zws-id={mApiKey}&address={address.Street}&citystatezip={address.City}+{address.State}+{address.Zip}&rentzestimate=true"; // GET data from api & map to Poco var response = url.GetJsonFromUrl(); bool isNoMatchFound = response.IndexOf("no exact match") > 0; bool isError = (response.IndexOf("Error") > 0 || response.IndexOf("error") > 0); if (isNoMatchFound) { return new RentValuationData() { Message = "No Match Found" } } ; else if (isError) { return new RentValuationData() { Message = "Zillow API Encountered Some Unknown Error" } } ; else { System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(searchresults)); searchresults searchresults; using (StringReader sr = new StringReader(response)) { searchresults = (searchresults)ser.Deserialize(sr); } var rentZestimateResults = searchresults?.response?.results; var zestimateResults = searchresults?.response?.results; // get the last result set. Because, the last result is always the latest. var rentZestimate = rentZestimateResults[rentZestimateResults.Length - 1].rentzestimate; var zestimate = zestimateResults[zestimateResults.Length - 1].zestimate; RentValuationData rentValuationData = new RentValuationData(); if (rentZestimate != null) { rentValuationData.AverageMonthlyRent = Convert.ToDecimal(rentZestimate.amount.Value); rentValuationData.ValueChangedIn30Days = Convert.ToDecimal(rentZestimate.valueChange.Value); rentValuationData.ValuationRentLow = Convert.ToDecimal(rentZestimate.valuationRange.low.Value); rentValuationData.ValuationRentHigh = Convert.ToDecimal(rentZestimate.valuationRange.high.Value); rentValuationData.IsRentEstimateAvailable = true; } else if (zestimate != null) { if (Convert.ToDecimal(zestimate.amount.Value) == 0) { return new RentValuationData() { Message = "No Data Found" } } ; rentValuationData.AverageMonthlyRent = Decimal.Multiply(Convert.ToDecimal(zestimate.amount.Value), 0.05M); rentValuationData.ValueChangedIn30Days = 0; rentValuationData.ValuationRentHigh = Decimal.Multiply(Convert.ToDecimal(zestimate.amount.Value), 0.1M); rentValuationData.ValuationRentLow = Decimal.Multiply(Convert.ToDecimal(zestimate.amount.Value), 0.1M); rentValuationData.IsRentEstimateAvailable = false; } return(rentValuationData); } } }