Beispiel #1
0
        public static List<WPerson> GetSearchResults(NameSource nameSource, ZipCodes zip)
        {
            List<WPerson> found = new List<WPerson>();

            if (IsValid(nameSource, zip))
            {
                foreach (Name name in nameSource.Names)
                {
                    var zipRequest = new ZipRequest(name.Value, zip.ZipCode);

                    zipRequest.CreateWebRequest();

                    string response = zipRequest.GetWebResponseString();

                    BuildPersonSearchResults(response, zip, found);

                    Pause();

                }
            }

            var unique = GetUniqueResults(found);

            var finalList = VerifiedBLL.RemoveVerified(unique, zip);

            return finalList.OrderByDescending(x => x.Street).ThenBy(x => x.House).ToList();
        }
Beispiel #2
0
        /// <summary>
        /// Fill the found list with the true matches from white pages.
        /// </summary>
        public static void CleanAndAdd(List<WPerson> persons, ZipCodes zip, List<WPerson> found)
        {
            if (persons != null && persons.Count > 0)
            {
                 //white page will return nearby zipcodes on non matches, we want exact
                var hits = persons.Where(x => !string.IsNullOrEmpty(x.Address)  && x.Zip == zip.ZipCode);

                if (hits.Count() > 0)
                {
                    found.AddRange(hits);
                }
            }
        }
Beispiel #3
0
        public ActionResult Search(ZipCodes model)
        {
            if (ModelState.IsValid)
            {
                List<WPerson> persons;

                if(Convert.ToBoolean(Utils.GetConfigSetting("MockAPI")))  //use fake data for testing.
                {
                    persons = ZipperBLL.GetMockResults();
                }
                else //really hit the whitepages api
                {
                    NameSource namesToSearch = NamesBLL.GetAllNames();
                    persons = ZipperBLL.GetSearchResults(namesToSearch, model);
                }

                ViewBag.ZipCode = model.ZipCode;
                return View("Results", persons);
            }

            return View();
        }
Beispiel #4
0
        /// <summary>
        /// Return all listings that have not already been verified.
        /// </summary>
        /// <returns></returns>
        public static List<WPerson> RemoveVerified(List<WPerson> persons, ZipCodes zip)
        {
            var db = DbLayer.GetDatabase();

            var newPersons = new List<WPerson>();

            var collection = db.GetCollection<VerifiedPersons>("verified");

            var verifiedForZip = collection.AsQueryable<VerifiedPersons>();
            foreach (WPerson p in persons)
            {
                bool newName = true;

                foreach (var vp in verifiedForZip)
                {

                    string verified = vp.StreetAddress.ToLower();

                    bool streetMatch = verified.Contains(p.Address.ToLower());

                    bool zipMatch = vp.ZipCode.ToString() == p.Zip;

                    if (zipMatch && streetMatch) //not already verified!
                    {
                        newName = false;
                    }

                }

                if (newName)
                {
                    newPersons.Add(p);
                }
            }

            return newPersons;
        }
Beispiel #5
0
 /// <summary>
 /// Ensure data is sound before searching
 /// </summary>
 private static bool IsValid(NameSource nameSource, ZipCodes zip)
 {
     return (nameSource != null && zip != null && nameSource.Names != null);
 }
Beispiel #6
0
        /// <summary>
        /// Attempt to get a response from the uri and translate it into our business object
        /// </summary>
        private static void BuildPersonSearchResults(string response, ZipCodes zip, List<WPerson> found)
        {
            if (!string.IsNullOrEmpty(response))
            {
                try
                {
                    dynamic rootObject = JObject.Parse(response);

                    List<WPerson> persons = BuildPersonList(rootObject);
                    CleanAndAdd(persons, zip, found);
                }
                catch { }
            }
        }