Ejemplo n.º 1
0
        public async Task <IEnumerable <Business> > GetBusinesses(string location, string searchstring)
        {
            if (string.IsNullOrEmpty(location) || string.IsNullOrEmpty(searchstring))
            {
                return(new List <Business>());
            }
            List <Business> lstBusiness = new List <Business>();
            var             client      = new Yelp.Api.Client("<apikey>");

            Yelp.Api.Models.SearchRequest searchRequest = new Yelp.Api.Models.SearchRequest();
            searchRequest.Location = location;
            searchRequest.Term     = searchstring;
            var results = await client.SearchBusinessesAllAsync(searchRequest);

            Yelp.Api.Models.SearchResponse searchResponse = results;
            var businesses = searchResponse.Businesses;

            foreach (var b in businesses)
            {
                var business = new Business();
                business.Name    = b.Name.Trim();
                business.Address = b.Location.Address1.Trim();
                business.City    = b.Location.City.Trim();
                business.ZipCode = b.Location.ZipCode.Trim();
                business.State   = b.Location.State.Trim();
                business.Phone   = b.Phone.Trim();
                var reviewresult = await client.GetReviewsAsync(b.Id);

                var revs = reviewresult.Reviews;
                business.Reviews = revs.Select(x => Regex.Replace(x.Text.Trim(), @"\r\n?|\n", "")).ToArray();
                lstBusiness.Add(business);
            }
            return(lstBusiness);
        }
Ejemplo n.º 2
0
        private async void GetBusinessesWithReviews()
        {
            Businesses.Clear();
            var client = new Yelp.Api.Client("<INPUT YOUR YELP API KEY>");

            Yelp.Api.Models.SearchRequest searchRequest = new Yelp.Api.Models.SearchRequest();
            searchRequest.Location = Location;
            searchRequest.Term     = SearchString;
            var results = await client.SearchBusinessesAllAsync(searchRequest);

            Yelp.Api.Models.SearchResponse searchResponse = results;
            var businesses = searchResponse.Businesses;

            foreach (var b in businesses)
            {
                var business = new Business();
                business.Name    = b.Name.Trim();
                business.Address = b.Location.Address1.Trim();
                business.City    = b.Location.City.Trim();
                business.ZipCode = b.Location.ZipCode.Trim();
                business.State   = b.Location.State.Trim();
                business.Phone   = b.Phone.Trim();
                var reviewresult = await client.GetReviewsAsync(b.Id);

                var revs = reviewresult.Reviews;
                business.Reviews = revs.Select(x => Regex.Replace(x.Text.Trim(), @"\r\n?|\n", "")).ToArray();
                Businesses.Add(business);
            }
        }
Ejemplo n.º 3
0
        //search through restaurants
        private async void  btnSearch_Click(object sender, RoutedEventArgs e)
        {
            //if the text is empty, don't let them search
            if (tbLocation.Text == "" || tbSearch.Text == "")
            {
                ContentDialog badInputDialog = new ContentDialog()
                {
                    Title           = "Bad search input",
                    Content         = "Please check search values",
                    CloseButtonText = "Ok"
                };

                await badInputDialog.ShowAsync();


                return;
            }

            //get search data
            searchData.searchKeyWord  = tbSearch.Text;
            searchData.searchLocation = tbLocation.Text;

            //set up yelp api client
            var client = new Yelp.Api.Client("uhYZFxMUHsPL7QO5AWYmIVGnrO1n_neqgTDJLZwQyFT2oHCzABvq5_BuXljPrjfS_DO3gkVoRwW2msSEj01JnP7gZAh1BEsDj2wz8zUO8m-Ka9eKrXRypgGzHYS6WnYx");

            //set up the request
            var request = new Yelp.Api.Models.SearchRequest();

            request.Term     = searchData.searchKeyWord;
            request.Location = searchData.searchLocation;

            //send request async and get results
            var results = await client.SearchBusinessesAllAsync(request);

            int resultCount = results.Businesses.Count;

            //for each result, make a restaurant model and add it to search data
            for (int i = 0; i < resultCount; i++)
            {
                RestaurantModel rm = new RestaurantModel(results.Businesses[i].Name,
                                                         results.Businesses[i].Phone, results.Businesses[i].Rating, results.Businesses[i].Categories,
                                                         results.Businesses[i].Url, results.Businesses[i].Location.Address1, results.Businesses[i].Location.Country,
                                                         results.Businesses[i].Location.State, results.Businesses[i].Location.City, results.Businesses[i].Location.ZipCode,
                                                         results.Businesses[i].ImageUrl, results.Businesses[i].IsClosed);

                searchData.Restaurants.Add(rm);
            }

            //Navigate to search results page

            this.Frame.Navigate(typeof(SearchResults));
        }
Ejemplo n.º 4
0
        public async System.Threading.Tasks.Task <ActionResult> Attractions()
        {
            var request = new Yelp.Api.Models.SearchRequest();

            request.Latitude   = 43.034274;
            request.Longitude  = -87.911465;
            request.Term       = "Restaurants, Bars";
            request.MaxResults = 10;
            request.Radius     = 1610;
            var client  = new Yelp.Api.Client("d76-ipn8brnI7BsOm7yk_X0Xa7-RTXpO8v4G93RcqMA9FRT3AdFbGsV8MkvAW6Q9ww-0YikIX7lDNgHfZ-6yDrfgG28FrU3PAj4TTUD1YT9mJO-hkAxqrKl-IzxrW3Yx");
            var results = await client.SearchBusinessesAllAsync(request);

            var latitudes  = new List <string>();
            var longitudes = new List <string>();
            var links      = new List <string>();
            var name       = new List <string>();
            var ratings    = new List <string>();

            //Lat and long for attraction
            for (int i = 0; i < request.MaxResults; i++)
            {
                latitudes.Add(results.Businesses[i].Coordinates.Latitude.ToString() + "\n");
                longitudes.Add(results.Businesses[i].Coordinates.Longitude.ToString() + "\n");
                ViewBag.Latitudes  = latitudes;
                ViewBag.Longitudes = longitudes;
            }

            //Name of attraction
            for (int i = 0; i < request.MaxResults; i++)
            {
                name.Add(results.Businesses[i].Name.ToString() + "\n");
                ViewBag.CompanyName = name;
            }

            //Link to attraction
            for (int i = 0; i < request.MaxResults; i++)
            {
                links.Add(results.Businesses[i].Url.ToString() + "\n");
                ViewBag.Links = links;
            }

            //Rating for attraction
            for (int i = 0; i < request.MaxResults; i++)
            {
                ratings.Add(results.Businesses[i].Rating.ToString() + "\n");
                ViewBag.Ratings = ratings;
            }

            return(View());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetBusiness(double lat, double lng, string categories = null)
        {
            try {
                var request = new Yelp.Api.Models.SearchRequest();
                request.Latitude  = lat;
                request.Longitude = lng;
                if (categories != null)
                {
                    request.Categories = categories;
                }
                request.MaxResults = 40;
                //request.Radius = 20; //maximum 25miles
                request.OpenNow = true; //get only open stores

                var client  = new Client("aFKewegoRzd6G0g_S3-UQkII28xShW1JGZqS8otwLCsmeEYrnaOUGR6XS2ub-IXo0Wx8uWgckNrBbI568fkpN9K3rYgNpMNCr7RuqjlfqY825esrWcfn7_FCOOWYWnYx");
                var results = await client.SearchBusinessesAllAsync(request);

                return(Ok(results));
            }
            catch (Exception e) {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Index(string search, int userId)
        {
            using (var chefClient = new HttpClient())
            {
                try
                {
                    chefClient.BaseAddress = new Uri("https://praiseapi.azurewebsites.net");
                    var response = await chefClient.GetAsync($"/api/recommendations");

                    response.EnsureSuccessStatusCode();

                    var chefResults = await response.Content.ReadAsStringAsync();

                    // required to convert to a List<CelebrityChef> since the json coming from API is numerous arrays from their database.
                    var rawChefRecommendations = JsonConvert.DeserializeObject <List <ChefResults> >(chefResults);

                    var yelpRequest = new Yelp.Api.Models.SearchRequest();
                    yelpRequest.Term       = "restaurants";
                    yelpRequest.Location   = search.ToLower();
                    yelpRequest.MaxResults = 50;

                    var yelpClient  = new Yelp.Api.Client("e0ZfT6muy7b6ZDYXAJVWjIx_oM4eCQSxVxaFGhjJSrLfHRoEX6XgUExr7DCGufP-WTImBXy150jg5eC12i5l2nVcLl5RvmZbck26hv6a_BpIvEhfOZc0YEfFPTfjW3Yx");
                    var yelpResults = await yelpClient.SearchBusinessesAllAsync(yelpRequest);

                    var rawYelpRecommendations = yelpResults.Businesses;

                    IEnumerable <ChefResults> filteredChefRecommendations = rawChefRecommendations.Where(x => x.city.ToLower() == search.ToLower());
                    List <ChefResults>        combinedResults             = new List <ChefResults>();

                    foreach (var item in rawYelpRecommendations)
                    {
                        foreach (var chefRec in rawChefRecommendations)
                        {
                            if (item.Name.ToLower() == chefRec.restaurantName.ToLower())
                            {
                                combinedResults.Add(chefRec);
                            }
                        }
                    }

                    int count = 0;
                    int index = 0;
                    int final = 10 - combinedResults.Count();

                    while (count < final && rawYelpRecommendations.ElementAt(index) != null)
                    {
                        bool isValid = true;
                        foreach (ChefResults cr in combinedResults)
                        {
                            if (cr.restaurantName.ToLower() == rawYelpRecommendations.ElementAt(index).Name.ToLower())
                            {
                                isValid = false;
                            }
                        }

                        if (isValid)
                        {
                            ChefResults yelpRest = new ChefResults
                            {
                                restaurantName  = rawYelpRecommendations.ElementAt(index).Name,
                                description     = rawYelpRecommendations.ElementAt(index).Categories[0].Title,
                                address         = rawYelpRecommendations.ElementAt(index).Location.Address1,
                                restaurantImage = rawYelpRecommendations.ElementAt(index).ImageUrl
                            };
                            combinedResults.Add(yelpRest);
                            count++;
                        }
                        index++;
                    }
                    return(View(new FavoritesCombined {
                        UserID = userId, ResultsList = combinedResults
                    }));
                }
                catch (HttpRequestException e)
                {
                    return(BadRequest($"Sorry, getting chef recommendations from PraiseAPI: {e.Message}"));
                }
            }
        }