public static DirectSalesAgentList FindReferrals(Double latitude, Double longitude, Int32 minimum) { DirectSalesAgentList referrals = new DirectSalesAgentList(); // TODO: change to use radicals Double radius = Double.Parse(ConfigurationProvider.Instance.Settings["ReferralRadius"]); Double distance = 0; Int32 daysSinceReferral = Int32.Parse(ConfigurationProvider.Instance.Settings["DaysSinceReferral"]); Int32 minimumReferrals = minimum == 0 ? Int32.Parse(ConfigurationProvider.Instance.Settings["MinimumReferrals"]) : minimum; Int32 maxSearches = Int32.Parse(ConfigurationProvider.Instance.Settings["ReferralMaxSearches"]); IdType minimumTitleId = IdType.Parse(ConfigurationProvider.Instance.Settings["MinimumReferralTitleId"]); Int32 referralsFound = 0; Int32 searchCount = 0; try { while ((referralsFound < minimumReferrals) && (searchCount < maxSearches)) { searchCount++; if (searchCount >= maxSearches) { distance = int.MaxValue; } else { distance += radius; } DecimalType minLat = Convert.ToDecimal(CalculateSouthernRadicalPoint(latitude, longitude, distance).Latitude); DecimalType maxLat = Convert.ToDecimal(CalculateNorthernRadicalPoint(latitude, longitude, distance).Latitude); DecimalType minLong = Convert.ToDecimal(CalculateEasternRadicalPoint(latitude, longitude, distance).Longitude); DecimalType maxLong = Convert.ToDecimal(CalculateWesternRadicalPoint(latitude, longitude, distance).Longitude); referrals = DemonstratorDAO.DAO.FindWithinGeographicArea(Convert.ToDecimal(latitude), Convert.ToDecimal(longitude), minLat, maxLat, minLong, maxLong, minimumTitleId); referralsFound = referrals.Count; } } catch (Exception ex) { log.Error(ex.ToString()); return(new DirectSalesAgentList()); } return(referrals); }
private bool FindReferral(ref IdType id, bool forceNew) { if (!forceNew) { IReferral recycled = FindByEmail(); if (recycled != null) { id = recycled.DirectSalesAgentId; return(true); } recycled = FindByGeocode(); if (recycled != null) { id = recycled.DirectSalesAgentId; return(true); } } DirectSalesAgentList list = FindReferrals(this.Latitude, this.Longitude); if (list.Count > 0) { IdType x = IdType.UNSET; for (int i = 0; i < list.Count; i++) { x = list[i].DirectSalesAgentId; if (!x.Equals(this.DirectSalesAgentId)) { break; } } id = x; } return(false); }