public ActionResult PreviewResults(string terms, string location, int radius )
        {
            var searchResult = new YellowPagesApi().SearchListings(location, terms, radius, 1);

            var leads = new List<Lead>();
            foreach (var listing in searchResult.SearchResult.SearchListings.SearchListing)
            {
                var lead = new Lead()
                {
                    BusinessName = listing.BusinessName,
                    BaseClickUrl = listing.BaseClickUrl,
                    MoreInfoUrl = listing.MoreInfoUrl,
                    Phone = listing.Phone,
                    PrimaryCategory = listing.PrimaryCategory,
                    YpListingId = listing.ListingId,
                    Street = listing.Street,
                    State = listing.State,
                    City = listing.City,
                    Zip = listing.Zip

                };

                leads.Add(lead);
            }

            var viewModel = new SearchViewModel();

            viewModel.Terms = terms;
            viewModel.Location = location;
            viewModel.Radius = radius;

            if (leads.Any())
            {
                viewModel.Leads = leads;
                viewModel.ListingsFound = Convert.ToInt32(searchResult.SearchResult.MetaProperties.totalAvailable);
            }

            return View(viewModel);
        }
Exemple #2
0
        private void FindListings(LeadSearch leadSearch)
        {
            var ypApi = new YellowPagesApi();

            var yellowPagesSearchListingsJsonResult = ypApi.SearchListings(leadSearch.Location, leadSearch.Terms, leadSearch.Radius, leadSearch.YpPagesScraped);

            while (leadSearch.Leads.Count < Convert.ToInt32(yellowPagesSearchListingsJsonResult.SearchResult.MetaProperties.totalAvailable))
            {
                if (yellowPagesSearchListingsJsonResult.SearchResult.SearchListings != null)
                {
                    var leads = new List<Lead>();
                    foreach (var listing in yellowPagesSearchListingsJsonResult.SearchResult.SearchListings.SearchListing)
                    {
                        var lead = new Lead()
                                       {
                                           BusinessName = listing.BusinessName,
                                           BaseClickUrl = listing.BaseClickUrl,
                                           MoreInfoUrl = listing.MoreInfoUrl,
                                           Phone = listing.Phone,
                                           PrimaryCategory = listing.PrimaryCategory,
                                           YpListingId = listing.ListingId
                                       };

                        leads.Add(lead);
                    }

                    leadSearch.Leads.AddRange(leads);
                    leadSearch.YpPagesScraped++;

                    yellowPagesSearchListingsJsonResult = ypApi.SearchListings(leadSearch.Location, leadSearch.Terms,leadSearch.Radius, leadSearch.YpPagesScraped);
                }
            }

            //jobs done?
            if (leadSearch.Leads.Count == Convert.ToInt32(yellowPagesSearchListingsJsonResult.SearchResult.MetaProperties.totalAvailable))
            {
                RavenSession.SaveChanges();
            }
        }