public ActionResult SearchRestaurant(SearchRestaurant searchRestaurant) { CustomJsonResult result = new CustomJsonResult(); List <Restaurant> restaurants = new List <Restaurant>(); if (!string.IsNullOrEmpty(searchRestaurant.RestaurantName)) { var res = db.Restaurants.Where(r => r.RestaurantName == searchRestaurant.RestaurantName).ToList(); //restaurants.Add(res); UpdateRestaurantList(restaurants, res); } if (searchRestaurant.Search != null && searchRestaurant.Search.Count > 0) { for (int i = 0; i < searchRestaurant.Search.Count; i++) { string id = searchRestaurant.Search[i].Id; if (searchRestaurant.Search[i].OptGroup == "Locations") { var res = db.Restaurants.Where(r => r.City == id).ToList(); //restaurants.Add(res); UpdateRestaurantList(restaurants, res); } else if (searchRestaurant.Search[i].OptGroup == "Cuisines") { var res = db.RestaurantCuisines.Where(c => c.CuisineId.ToString() == id).Select(r => r.Restaurant).ToList(); //restaurants.Add(res); UpdateRestaurantList(restaurants, res); } else if (searchRestaurant.Search[i].OptGroup == "Amenities") { var res = db.RestaurantAmenities.Where(c => c.AmenitieId.ToString() == id).Select(r => r.Restaurant).ToList(); //restaurants.Add(res); UpdateRestaurantList(restaurants, res); } else if (searchRestaurant.Search[i].OptGroup == "Styles") { var res = db.RestaurantStyles.Where(c => c.StyleId.ToString() == id).Select(r => r.Restaurant).ToList(); //restaurants.Add(res); //ListA.Where(a => ListX.Any(x => x.b == a.b)) UpdateRestaurantList(restaurants, res); } else if (searchRestaurant.Search[i].OptGroup == "Ambience") { var res = db.RestaurantTablesAmbiences.Where(c => c.AmbienceId.ToString() == id).Select(r => r.RestaurantTables.Restaurant).ToList(); //restaurants.Add(res); UpdateRestaurantList(restaurants, res); } } } else { restaurants = db.Restaurants.ToList(); } result.Data = new { Result = true, Restaurants = restaurants }; return(result); }
public List <RestaurantInfo> SearchByName(string name) { var restaurants = restaurantRepository.getAll(); var search = new SearchRestaurant(); var results = search.PartialSearch(name, restaurants); return(results); }
public ActionResult GetModel() { try { CustomJsonResult result = new CustomJsonResult(); // Call action here... User user = new User(); user.UserBookings = new List <UserBooking>(); user.UserFavoriteRestaurnats = new List <UserFavoriteRestaurnat>(); user.UserRestaurnatReviews = new List <UserRestaurnatReview>(); var cuisines = db.Cuisines.ToList(); var styles = db.Styles.ToList(); var amenities = db.Amenities.ToList(); var paymentMethods = db.PaymentMethods.ToList(); var ambience = db.Ambiences.ToList(); var restaurantNames = db.Restaurants.Select(r => new { r.Id, r.RestaurantName }).ToList(); var searchRestaurant = new SearchRestaurant(); searchRestaurant.Search = new List <OptGroupList>(); var userBooking = new UserBooking(); result.Data = new { User = user, CuisinesList = cuisines, AmenitiesList = amenities, PaymentMethodsList = paymentMethods, AmbiencesList = ambience, StylesList = styles, RestaurantNamesList = restaurantNames, SearchRestaurant = searchRestaurant, UserBooking = userBooking }; //result.Data = restaurant; return(result); } catch (Exception ex) { throw ex; } }