public IQueryable <RestaurantSearchDetails> SearchForRestaurants(SearchForRestautrant searchDetails) { List <RestaurantSearchDetails> restaurantInfo = new List <RestaurantSearchDetails>(); restaurantInfo = GetRestaurantDetailsBasedOnMultipleOptions(searchDetails); return(restaurantInfo.AsQueryable()); }
public IQueryable <RestaurantSearchDetails> SearchForRestaurant(SearchForRestautrant searchDetails) { List <RestaurantSearchDetails> searchedRestaurantBasedOnRating = new List <RestaurantSearchDetails>(); List <RestaurantSearchDetails> Resturants = new List <RestaurantSearchDetails>(); searchedRestaurantBasedOnRating = GetResturantDetailsBasedOnMutipleParams(searchDetails); List <RestaurantSearchDetails> restaurantsBasedOnLocation = new List <RestaurantSearchDetails>(); restaurantsBasedOnLocation = GetRetaurantBasedOnLocationAndName(searchDetails.location); var restaurantInfo = restaurantsBasedOnLocation.Union(searchedRestaurantBasedOnRating).ToList <RestaurantSearchDetails>(); var result = restaurantInfo.Select(O => O.restauran_ID).Distinct().ToList(); foreach (int id in result) { foreach (var resturant in restaurantInfo) { if (id == resturant.restauran_ID) { Resturants.Add(resturant); break; } } } var restaurantInfoSorted = Resturants.OrderByDescending(s => s.Rating).ToList(); return(restaurantInfoSorted.AsQueryable()); }
public IQueryable <RestaurantInformation> SearchForRestaurant(SearchForRestaurant searchDetails) { try { List <RestaurantInformation> restaurantInformationList = new List <RestaurantInformation>(); DataLayer.DataEntity.LocationDetails locationDetails = new DataLayer.DataEntity.LocationDetails() { restaurant_Name = searchDetails.location.restaurant_Name, distance = searchDetails.location.distance, xaxis = searchDetails.location.xaxis, yaxis = searchDetails.location.yaxis }; DataLayer.DataEntity.AddtitionalFeatureForSearch addtitionalFeatureForSearch = new AddtitionalFeatureForSearch() { cuisine = searchDetails.search.cuisine, Menu = searchDetails.search.Menu, rating = searchDetails.search.rating }; DataLayer.DataEntity.SearchForRestautrant searchForRestautrant = new SearchForRestautrant() { location = locationDetails, search = addtitionalFeatureForSearch }; IQueryable <RestaurantSearchDetails> searchedRestaurants = search_Repository.SearchForRestaurant(searchForRestautrant); if (searchedRestaurants != null) { foreach (var restaurant in searchedRestaurants) { RestaurantInformation restaurantDetails = new RestaurantInformation { restaurant_ID = restaurant.restauran_ID, restaurant_Name = restaurant.restaurant_Name, restaurant_Address = restaurant.restaurant_Address, restaurant_ContactNo = restaurant.restaurant_PhoneNumber, website = restaurant.restraurant_Website, opening_Time = restaurant.opening_Time, closing_Time = restaurant.closing_Time, xaxis = restaurant.xaxis, yaxis = restaurant.yaxis }; restaurantInformationList.Add(restaurantDetails); } } return(restaurantInformationList.AsQueryable()); } catch (Exception ex) { throw ex; } }
public IQueryable <RestaurantSearchDetails> SearchForRestaurant(SearchForRestautrant searchDetails) { List <RestaurantSearchDetails> searchedRestaurantBasedOnRating = new List <RestaurantSearchDetails>(); searchedRestaurantBasedOnRating = GetRestaurantDetailsBasedOnRating(searchDetails.search); List <RestaurantSearchDetails> restaurantsBasedOnLocation = new List <RestaurantSearchDetails>(); restaurantsBasedOnLocation = GetRetaurantBasedOnLocationAndName(searchDetails.location); List <RestaurantSearchDetails> restaurantInfo = new List <RestaurantSearchDetails>(); restaurantInfo = restaurantsBasedOnLocation.Intersect(searchedRestaurantBasedOnRating).ToList <RestaurantSearchDetails>(); return(restaurantInfo.AsQueryable()); }
public IQueryable <RestaurantInformation> SearchForRestaurant(SearchForRestaurant searchDetails) { List <RestaurantInformation> restaurant_Info = new List <RestaurantInformation>(); try { DataLayer.DataEntity.SearchForRestautrant searchParms = new SearchForRestautrant() { location = new DataLayer.DataEntity.LocationDetails() { distance = searchDetails.location.distance, xaxis = searchDetails.location.xaxis, yaxis = searchDetails.location.yaxis, restaurant_Name = searchDetails.location.restaurant_Name }, search = new DataLayer.DataEntity.AddtitionalFeatureForSearch() { rating = searchDetails.search.rating, cuisine = searchDetails.search.cuisine, Menu = searchDetails.search.Menu } }; var searchResult = search_Repository.SearchForRestaurant(searchParms); if (searchResult != null) { foreach (var restaurants in searchResult) { RestaurantInformation restaurant_Details = new RestaurantInformation { restaurant_ID = restaurants.restauran_ID, restaurant_Name = restaurants.restaurant_Name, restaurant_Address = restaurants.restaurant_Address, restaurant_ContactNo = restaurants.restaurant_PhoneNumber, closing_Time = restaurants.closing_Time, opening_Time = restaurants.opening_Time, website = restaurants.restraurant_Website, xaxis = restaurants.xaxis, yaxis = restaurants.yaxis, Rating = restaurants.Rating }; restaurant_Info.Add(restaurant_Details); } } return(restaurant_Info.AsQueryable()); } catch (Exception ex) { return(restaurant_Info.AsQueryable()); } }
public IQueryable <RestaurantSearchDetails> SearchForRestaurant(SearchForRestautrant searchDetails) { try { List <RestaurantSearchDetails> searchedRestaurantBasedOnRating = new List <RestaurantSearchDetails>(); if (!string.IsNullOrEmpty(searchDetails.search.cuisine) || !string.IsNullOrEmpty(searchDetails.search.Menu) || searchDetails.search.rating > 0) { searchedRestaurantBasedOnRating = GetRestaurantDetailsBasedOnRating(searchDetails.search); } List <RestaurantSearchDetails> restaurantsBasedOnLocation = new List <RestaurantSearchDetails>(); if (!string.IsNullOrEmpty(searchDetails.location.restaurant_Name) || searchDetails.location.xaxis != 0 || searchDetails.location.yaxis != 0) { restaurantsBasedOnLocation = GetRetaurantBasedOnLocationAndName(searchDetails.location); } List <RestaurantSearchDetails> restaurantInfo = new List <RestaurantSearchDetails>(); if ((!string.IsNullOrEmpty(searchDetails.search.cuisine) || !string.IsNullOrEmpty(searchDetails.search.Menu) || searchDetails.search.rating > 0) && restaurantsBasedOnLocation.Count == 0) { restaurantInfo = restaurantsBasedOnLocation; } else if ((!string.IsNullOrEmpty(searchDetails.location.restaurant_Name) || searchDetails.location.xaxis != 0 || searchDetails.location.yaxis != 0) && searchedRestaurantBasedOnRating.Count == 0) { restaurantInfo = searchedRestaurantBasedOnRating; } else if (searchedRestaurantBasedOnRating.Any() && restaurantsBasedOnLocation.Any()) { restaurantInfo = searchedRestaurantBasedOnRating.Intersect (restaurantsBasedOnLocation, new RestaurantSearchDetailsComparer()).ToList(); } return(restaurantInfo.AsQueryable()); } catch (Exception ex) { throw ex; } }
public IQueryable <RestaurantSearchDetails> SearchForRestaurant(SearchForRestautrant searchDetails) { List <RestaurantSearchDetails> searchedRestaurantBasedOnRating = new List <RestaurantSearchDetails>(); List <RestaurantSearchDetails> restaurantsBasedOnLocation = new List <RestaurantSearchDetails>(); TotalSearchForRestaurant(searchDetails); if (searchDetails.search != null) { searchedRestaurantBasedOnRating = GetRestaurantDetailsBasedOnRating(searchDetails.search); } if (searchDetails.location != null) { restaurantsBasedOnLocation = GetRetaurantBasedOnLocationAndName(searchDetails.location); } List <RestaurantSearchDetails> restaurantInfo = new List <RestaurantSearchDetails>(); restaurantInfo = restaurantsBasedOnLocation.Union(searchedRestaurantBasedOnRating).ToList <RestaurantSearchDetails>(); return(restaurantInfo.AsQueryable()); }
private List <RestaurantSearchDetails> GetRestaurantDetailsBasedOnMultipleOptions(SearchForRestautrant searchDetails) { List <RestaurantSearchDetails> restaurants = new List <RestaurantSearchDetails>(); try { var restaurantFilter = (from restaurant in db.TblRestaurant join location in db.TblLocation on restaurant.TblLocationId equals location.Id join rating in db.TblRating on restaurant.Id equals rating.TblRestaurantId join offer in db.TblOffer on restaurant.Id equals offer.TblRestaurantId join menu in db.TblMenu on offer.TblMenuId equals menu.Id join cousine in db.TblCuisine on menu.TblCuisineId equals cousine.Id select new { TblRestaurant = restaurant, TblLocation = location, TblRating = rating, TblOffer = offer, TblMenu = menu, TblCuisine = cousine }); if (!string.IsNullOrEmpty(searchDetails.location.restaurant_Name)) { restaurantFilter = (from filteredRestaurant in restaurantFilter where filteredRestaurant.TblRestaurant.Name.Contains(searchDetails.location.restaurant_Name) select filteredRestaurant); } if ((searchDetails.location.xaxis > 0) && (searchDetails.location.yaxis > 0)) { restaurantFilter = (from filteredRestaurant in restaurantFilter where Convert.ToDouble(filteredRestaurant.TblLocation.X) <= searchDetails.location.xaxis && Convert.ToDouble(filteredRestaurant.TblLocation.Y) <= searchDetails.location.yaxis select filteredRestaurant); if (searchDetails.location.distance > 0 && searchDetails.location.distance <= calculateDistanceUsingCordinates(searchDetails.location.xaxis, searchDetails.location.yaxis)) { //TBD } } if (searchDetails.search.rating > 0) { restaurantFilter = (from filteredRestaurant in restaurantFilter where Convert.ToInt32(filteredRestaurant.TblRating.Rating) <= searchDetails.search.rating select filteredRestaurant); } if (!string.IsNullOrEmpty(searchDetails.search.Menu)) { restaurantFilter = (from filteredRestaurant in restaurantFilter where filteredRestaurant.TblMenu.Item.Contains(searchDetails.search.Menu) select filteredRestaurant); } if (!string.IsNullOrEmpty(searchDetails.search.cuisine)) { restaurantFilter = (from filteredRestaurant in restaurantFilter where filteredRestaurant.TblCuisine.Cuisine.Contains(searchDetails.search.cuisine) select filteredRestaurant); } foreach (var item in restaurantFilter) { RestaurantSearchDetails restaurant = new RestaurantSearchDetails { restauran_ID = item.TblRestaurant.Id, restaurant_Name = item.TblRestaurant.Name, restaurant_Address = item.TblRestaurant.Address, restaurant_PhoneNumber = item.TblRestaurant.ContactNo, restraurant_Website = item.TblRestaurant.Website, closing_Time = item.TblRestaurant.CloseTime, opening_Time = item.TblRestaurant.OpeningTime, xaxis = (double)item.TblLocation.X, yaxis = (double)item.TblLocation.Y }; restaurants.Add(restaurant); } return(restaurants); } catch (Exception ex) { throw ex; } }
private List <RestaurantSearchDetails> GetResturantDetailsBasedOnMutipleParams(SearchForRestautrant searchDetails) { List <RestaurantSearchDetails> restaurants = new List <RestaurantSearchDetails>(); try { var restaurantFilter = (from restaurant in db.TblRestaurant join location in db.TblLocation on restaurant.TblLocationId equals location.Id join rating in db.TblRating on restaurant.Id equals rating.TblRestaurantId select new { TblRestaurant = restaurant, TblLocation = location, TblRating = rating }); restaurantFilter = (from filteredRestaurant in restaurantFilter join offer in db.TblOffer on filteredRestaurant.TblRestaurant.Id equals offer.TblRestaurantId join menu in db.TblMenu on offer.TblMenuId equals menu.Id join cuisine in db.TblCuisine on menu.TblCuisineId equals cuisine.Id where (cuisine.Cuisine.Contains(searchDetails.search.cuisine) || menu.Item.Contains(searchDetails.search.Menu) || filteredRestaurant.TblRating.Rating.Contains(searchDetails.search.rating.ToString())) select filteredRestaurant).Distinct(); foreach (var item in restaurantFilter) { RestaurantSearchDetails restaurant = new RestaurantSearchDetails { restauran_ID = item.TblRestaurant.Id, restaurant_Name = item.TblRestaurant.Name, restaurant_Address = item.TblRestaurant.Address, restaurant_PhoneNumber = item.TblRestaurant.ContactNo, restraurant_Website = item.TblRestaurant.Website, closing_Time = item.TblRestaurant.CloseTime, opening_Time = item.TblRestaurant.OpeningTime, xaxis = (double)item.TblLocation.X, yaxis = (double)item.TblLocation.Y, Rating = int.Parse(item.TblRating.Rating) }; restaurants.Add(restaurant); } return(restaurants); } catch (Exception ex) { return(restaurants); } }
public IQueryable <RestaurantSearchDetails> TotalSearchForRestaurant(SearchForRestautrant searchDetails) { List <RestaurantSearchDetails> restaurants = new List <RestaurantSearchDetails>(); try { var res = db.TblRestaurant.Include(x => x.TblRating); var restaurantFilter = (from restaurant in res join location in db.TblLocation on restaurant.TblLocationId equals location.Id select new { TblRestaurant = restaurant, TblLocation = location }); if (searchDetails.search != null) { if (!string.IsNullOrEmpty(searchDetails.search.cuisine)) { restaurantFilter = (from filteredRestaurant in restaurantFilter join offer in db.TblOffer on filteredRestaurant.TblRestaurant.Id equals offer.TblRestaurantId join menu in db.TblMenu on offer.TblMenuId equals menu.Id join cuisine in db.TblCuisine on menu.TblCuisineId equals cuisine.Id where cuisine.Cuisine.Contains(searchDetails.search.cuisine) select filteredRestaurant).Distinct(); } if (!string.IsNullOrEmpty(searchDetails.search.Menu)) { restaurantFilter = (from filteredRestaurant in restaurantFilter join offer in db.TblOffer on filteredRestaurant.TblRestaurant.Id equals offer.TblRestaurantId join menu in db.TblMenu on offer.TblMenuId equals menu.Id where menu.Item.Contains(searchDetails.search.Menu) select filteredRestaurant).Distinct(); } if (searchDetails.search.budget > 0) { restaurantFilter = (from filteredRestaurant in restaurantFilter join offer in db.TblOffer on filteredRestaurant.TblRestaurant.Id equals offer.TblRestaurantId join menu in db.TblMenu on offer.TblMenuId equals menu.Id where offer.Price > searchDetails.search.budget select filteredRestaurant).Distinct(); } if (searchDetails.search.rating > 0) { restaurantFilter = (from filteredRestaurant in restaurantFilter join rating in db.TblRating on filteredRestaurant.TblRestaurant.Id equals rating.TblRestaurantId where rating.Rating.Contains(searchDetails.search.rating.ToString()) select filteredRestaurant).Distinct(); } } if (searchDetails.location != null) { if (!string.IsNullOrEmpty(searchDetails.location.restaurant_Name)) { restaurantFilter = restaurantFilter.Where(a => a.TblRestaurant.Name.Contains(searchDetails.location.restaurant_Name)); } if (!(searchDetails.location.xaxis <= 0) || (searchDetails.location.yaxis < 0)) { foreach (var place in restaurantFilter) { double distance = Distance(searchDetails.location.xaxis, searchDetails.location.yaxis, (double)place.TblLocation.X, (double)place.TblLocation.Y); if (distance < int.Parse(searchDetails.location.distance.ToString())) { RestaurantSearchDetails tblRestaurant = new RestaurantSearchDetails { restauran_ID = place.TblRestaurant.Id, restaurant_Name = place.TblRestaurant.Name, restaurant_Address = place.TblRestaurant.Address, restaurant_ContactNo = place.TblRestaurant.ContactNo, website = place.TblRestaurant.Website, closing_Time = place.TblRestaurant.CloseTime, opening_Time = place.TblRestaurant.OpeningTime, xaxis = (double)place.TblLocation.X, yaxis = (double)place.TblLocation.Y }; try { tblRestaurant.rating = place.TblRestaurant.TblRating.Average(x => Convert.ToDecimal(x.Rating)); } catch { tblRestaurant.rating = 0; } restaurants.Add(tblRestaurant); } } } else { foreach (var item in restaurantFilter) { RestaurantSearchDetails tblRestaurant = new RestaurantSearchDetails { restauran_ID = item.TblRestaurant.Id, restaurant_Name = item.TblRestaurant.Name, restaurant_Address = item.TblRestaurant.Address, restaurant_ContactNo = item.TblRestaurant.ContactNo, website = item.TblRestaurant.Website, closing_Time = item.TblRestaurant.CloseTime, opening_Time = item.TblRestaurant.OpeningTime, xaxis = (double)item.TblLocation.X, yaxis = (double)item.TblLocation.Y }; try { tblRestaurant.rating = item.TblRestaurant.TblRating.Average(x => Convert.ToDecimal(x.Rating)); } catch { tblRestaurant.rating = 0; } restaurants.Add(tblRestaurant); } } } return(restaurants.DistinctBy(x => x.restaurant_Name).AsQueryable().OrderByDescending(x => x.rating)); } catch (Exception ex) { return(null); } }