Ejemplo n.º 1
0
        // GET: Restaurants
        public async Task <ActionResult> Index(RestaurantSearchViewModel modelIn)
        {
            // TODO: In case of "Detect current location" searchTxtLoc value passed here, but not processed. Because it is not PlaceId. It shold be somehow matched to PlaceId, but it is messy
            var currentCityId = modelIn.CityId ?? (Session["currentCity"] as City)?.Id;
            var model         = (await _SearchBusiness(modelIn.CuisineId, currentCityId, modelIn.GroupId, modelIn.PlaceId).ToArrayAsync()).Select(
                r =>
                new RestaurantViewModel
            {
                Id   = r.Id,
                Name = r.Name,
                ImageFullFileName = r.ImageFullFileName,
                Place             = new PlaceViewModel {
                    Id = r.Place.Id, Name = r.Place.Name, City = new CityViewModel {
                        Id = r.Place.City.Id, Name = r.Place.City.Name
                    }
                },
                Cuisines = r.Cuisines.Select(c => new CuisineViewModel {
                    Name = c.Name
                }).ToArray(),
                Groups = r.Groups.Select(g => new RestaurantGroupViewModel {
                    Id = g.Id, Name = g.Name
                }).ToArray(),
                Votes = r.Votes.Select(v => new VoteViewModel {
                    ReviewText = v.ReviewText, ApplicationUser = new UserViewModel {
                        Id = v.ApplicationUser.Id, UserName = v.ApplicationUser.UserName, ImageFullFileName = v.ApplicationUser.ImageFullFileName, ReviewsCount = v.ApplicationUser.Votes.Count
                    }
                }).OrderByDescending(o => o.ApplicationUser.ReviewsCount).ToArray(),
                PercentRate = r.PercentRate
            }).OrderByDescending(o => o.PercentRate);

            // Creating ViewBag.Title
            var sb = new StringBuilder();

            sb.Append(!string.IsNullOrEmpty(modelIn.GroupId) ? $"{_db.RestaurantGroups.Find(modelIn.GroupId)?.Name} restaurants" : "Restaurants");
            if (!string.IsNullOrEmpty(modelIn.CuisineId))
            {
                sb.Append($" with {_db.Cuisines.Find(modelIn.CuisineId)?.Name}");
            }
            if (modelIn.PlaceId != null)
            {
                sb.Append($" in {_db.Places.Find(modelIn.PlaceId)?.Name}");
            }
            else if (!string.IsNullOrEmpty(currentCityId))
            {
                var cityName = string.IsNullOrEmpty(modelIn.CityId) ||
                               (!string.IsNullOrEmpty(modelIn.CityId) &&
                                string.Equals(modelIn.CityId, (Session["currentCity"] as City)?.Id))
                    ? (Session["currentCity"] as City)?.Name
                    : _db.Cities.Find(modelIn.CityId)?.Name;
                sb.Append($" in {cityName} city");
            }
            else
            {
                sb.Append(" in all cities");
            }
            ViewBag.Title = sb.ToString();

            return(View(model));
        }
Ejemplo n.º 2
0
        // GET - THIS WAS CHANGED FROM GET
        public ActionResult GetFoodSuggestions(string[] friends)
        {
            RestaurantSearchViewModel restaurantSearchModel = new RestaurantSearchViewModel();
            var currentUser = db.Users.Find(System.Web.HttpContext.Current.User.Identity.GetUserId());

            restaurantSearchModel.User = currentUser;
            var geoCodeClient = new WebClient();

            geoCodeClient.Headers.Add("X-API-Key", "aOpKxmKJDaHhhhg7IgRUISKvK4gMVJxx");
            var    geoCodeResponse = geoCodeClient.DownloadString("https://api.internationalshowtimes.com/v4/cities?query=" + restaurantSearchModel.User.City);
            var    geoCodeResults  = new JavaScriptSerializer().Deserialize <IShowTimeCityResultResponse>(geoCodeResponse);
            string lat             = geoCodeResults.Cities[0].Lat;
            string lon             = geoCodeResults.Cities[0].Lon;

            foreach (string userId in friends)
            {
                foreach (UserToCuisine cuisine in db.UserToCuisines)
                {
                    if (cuisine.UserId == userId)
                    {
                        restaurantSearchModel.CuisineIdsToSearch.Add(cuisine.CuisineId);
                    }
                }
            }

            foreach (UserToCuisine cuisine in db.UserToCuisines)
            {
                if (cuisine.UserId == restaurantSearchModel.User.Id)
                {
                    restaurantSearchModel.CuisineIdsToSearch.Add(cuisine.CuisineId);
                }
            }
            restaurantSearchModel.ResolvedCuisineIdsToSearch = restaurantSearchModel.CuisineIdsToSearch.First();
            if (restaurantSearchModel.CuisineIdsToSearch.Count > 1)
            {
                restaurantSearchModel.ResolvedCuisineIdsToSearch = string.Join(",", restaurantSearchModel.CuisineIdsToSearch);
            }
            var restaurantSearchClient = new WebClient();

            restaurantSearchClient.Headers.Add("user-key", "d846616ebd6c5c018f6cd8fd36a6fb68");
            var restaurantSearchResponse = restaurantSearchClient.DownloadString("https://developers.zomato.com/api/v2.1/search?lat=" + lat + "&lon=" + lon + "&cuisines=" + restaurantSearchModel.ResolvedCuisineIdsToSearch + "");
            var restaurantSearchResults  = new JavaScriptSerializer().Deserialize <RestaurantResultResponse>(restaurantSearchResponse);

            for (int i = 0; i < 20; i++)
            {
                restaurantSearchResults.Restaurants[i].Restaurant.Address    = restaurantSearchResults.Restaurants[i].Restaurant.Location.Address;
                restaurantSearchResults.Restaurants[i].Restaurant.Locality   = restaurantSearchResults.Restaurants[i].Restaurant.Location.Locality;
                restaurantSearchResults.Restaurants[i].Restaurant.City       = restaurantSearchResults.Restaurants[i].Restaurant.Location.City;
                restaurantSearchResults.Restaurants[i].Restaurant.State      = restaurantSearchResults.Restaurants[i].Restaurant.Location.State;
                restaurantSearchResults.Restaurants[i].Restaurant.Latitude   = restaurantSearchResults.Restaurants[i].Restaurant.Location.Latitude;
                restaurantSearchResults.Restaurants[i].Restaurant.Longitude  = restaurantSearchResults.Restaurants[i].Restaurant.Location.Longitude;
                restaurantSearchResults.Restaurants[i].Restaurant.Zipcode    = restaurantSearchResults.Restaurants[i].Restaurant.Location.Zipcode;
                restaurantSearchResults.Restaurants[i].Restaurant.Country_Id = restaurantSearchResults.Restaurants[i].Restaurant.Location.Country_Id;
                restaurantSearchModel.RestaurantResults.Add(restaurantSearchResults.Restaurants[i].Restaurant);
            }
            return(View(restaurantSearchModel));
        }
Ejemplo n.º 3
0
        // GET: Customer
        public ActionResult Index(RestaurantSearchViewModel searchParameters)
        {
            List <Restaurant> restaurants = new List <Restaurant>();

            if (searchParameters == null)
            {
                restaurants = _customerService.GetAllRestaurants().ToList();
            }
            else
            {
                restaurants = _customerService.GetRestaurantsInCity(searchParameters.City).ToList();
            }

            return(View(restaurants));
        }
 public RestaurantSearchViewModel Restaurants()
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         try
         {
             RestaurantSearchViewModel result          = new RestaurantSearchViewModel();
             List <Restaurant>         RestaurantsList = GetAllRestaurants();
             result.Restaurants           = RestaurantsList;
             result.MealGroups            = GetMealGroupsForView(context, RestaurantsList, new List <int>());
             result.Neighborhoods         = GetNeighborhoodsForView(context, RestaurantsList, new List <int>());
             result.RestaurantFeatures    = GetRestaurantFeaturesForView(context, RestaurantsList, new List <int>());
             result.Cuisines              = GetCuisinesForView(context, RestaurantsList, new List <int>());
             result.IsSelectedAnyCategory = false;
             return(result);
         }
         catch
         {
             throw new Exception("Restaurants not found");
         }
     }
 }
Ejemplo n.º 5
0
        public ActionResult Index(RestaurantSearchViewModel vm)
        {
            vm.Results = Query(new SearchRestaurantQuery(vm.Criteria));

            return(View(vm));
        }
        public RestaurantSearchViewModel SearchRestaurants(string searchText, string CuisinesCheck, string FeaturesCheck, string MealGroups, string Neighborhoods)
        {
            using (GoodTasteContext context = new GoodTasteContext())
            {
                try
                {
                    RestaurantSearchViewModel result          = new RestaurantSearchViewModel();
                    List <Restaurant>         RestaurantsList = new List <Restaurant>();
                    List <int> idRest = new List <int>();
                    List <int> idNB   = new List <int>();
                    List <int> idRF   = new List <int>();
                    List <int> idRC   = new List <int>();
                    List <int> idRMG  = new List <int>();
                    bool       IsSelectedAnyCategory = false;
                    if (Neighborhoods != null)
                    {
                        idNB   = ParseStringForId(Neighborhoods);
                        idRest = GetRestaurantsIDByNeighborhoods(idNB);
                        IsSelectedAnyCategory = true;
                    }
                    if (FeaturesCheck != null)
                    {
                        idRF = ParseStringForId(FeaturesCheck);
                        List <int> IDs = GetRestaurantsIDByFeatures(idRF);
                        idRest = idRest.Count > 0 ? idRest.Intersect(IDs).ToList() : IDs;
                        IsSelectedAnyCategory = true;
                    }

                    if (CuisinesCheck != null)
                    {
                        idRC = ParseStringForId(CuisinesCheck);
                        List <int> IDs = GetRestaurantsIDByCuisines(idRC);
                        idRest = idRest.Count > 0 ? idRest.Intersect(IDs).ToList() : IDs;
                        IsSelectedAnyCategory = true;
                    }

                    if (MealGroups != null)
                    {
                        idRMG = ParseStringForId(MealGroups);
                        List <int> IDs = GetRestaurantsIDByMealGroups(idRMG);
                        idRest = idRest.Count > 0 ? idRest.Intersect(IDs).ToList() : IDs;
                        IsSelectedAnyCategory = true;
                    }
                    if (searchText.Length > 0)
                    {
                        List <int> IDs = GetRestaurantsIDByName(searchText);
                        idRest = idRest.Count > 0 ? idRest.Intersect(IDs).ToList() : IDs;
                        IsSelectedAnyCategory = true;
                    }
                    if (idRest.Count == 0)
                    {
                        RestaurantsList = GetAllRestaurants();
                    }
                    else
                    {
                        RestaurantsList = GetRestaurantsByID(idRest);
                    }
                    result.Restaurants           = RestaurantsList;
                    result.MealGroups            = GetMealGroupsForView(context, RestaurantsList, idRMG);
                    result.Neighborhoods         = GetNeighborhoodsForView(context, RestaurantsList, idNB);
                    result.RestaurantFeatures    = GetRestaurantFeaturesForView(context, RestaurantsList, idRF);
                    result.Cuisines              = GetCuisinesForView(context, RestaurantsList, idRC);
                    result.IsSelectedAnyCategory = IsSelectedAnyCategory;
                    return(result);
                }
                catch
                {
                    throw new Exception("Restaurants not found");
                }
            }
        }