public void TestRestaurant_SearchByName_ReturnsMatches() { Restaurant restaurant1 = new Restaurant("McDonalds", 1, 2); restaurant1.Save(); Restaurant restaurant2 = new Restaurant("Tender Green", 3, 1); restaurant2.Save(); Restaurant restaurant3 = new Restaurant("mcdonalds", 2, 5); restaurant3.Save(); Restaurant restaurant4 = new Restaurant("Best Restaurants", 5, 3); restaurant4.Save(); List <Restaurant> controlList = new List <Restaurant> { restaurant1, restaurant3 }; List <Restaurant> matches = Restaurant.SearchByName("MCDONALDS"); Assert.Equal(controlList, matches); }
public HomeModule() { Get["/"] = _ => { List <Cuisine> allCuisines = Cuisine.GetAll(); Dictionary <string, object> model = new Dictionary <string, object> { }; model.Add("user-name", Request.Form["user-name"]); model.Add("cuisines", allCuisines); return(View["index.cshtml", model]); }; Get["/cuisine/new"] = _ => { Dictionary <string, string> model = new Dictionary <string, string> { }; string formType = Request.Query["form-type"]; model.Add("form-type", formType); return(View["form.cshtml", model]); }; Post["/"] = _ => { Dictionary <string, object> model = new Dictionary <string, object> { }; Cuisine newCuisine = new Cuisine(Request.Form["cuisine-input"]); newCuisine.Save(); List <Cuisine> allCuisines = Cuisine.GetAll(); model.Add("user-name", Request.Form["user-name"]); model.Add("cuisines", allCuisines); return(View["index.cshtml", model]); }; Get["/cuisine/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object> { }; Cuisine selectedCuisine = Cuisine.Find(parameters.id); List <Restaurant> restaurantsByCuisine = selectedCuisine.GetRestaurants(); model.Add("restaurants", restaurantsByCuisine); model.Add("selected-cuisine", selectedCuisine); return(View["show_restaurants.cshtml", model]); }; Get["/cuisine/{id}/restaurant/new"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object> { }; string formType = Request.Query["form-type"]; Cuisine selectedCuisine = Cuisine.Find(parameters.id); model.Add("form-type", formType); model.Add("selected-cuisine", selectedCuisine); return(View["form.cshtml", model]); }; Post["/cuisine/{id}/restaurant"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object> { }; Restaurant newRestaurant = new Restaurant(Request.Form["restaurant-name-input"], Request.Form["restaurant-stars-input"], parameters.id); newRestaurant.Save(); Cuisine selectedCuisine = Cuisine.Find(parameters.id); List <Restaurant> allCuisineRestaurants = selectedCuisine.GetRestaurants(); model.Add("restaurants", allCuisineRestaurants); model.Add("selected-cuisine", selectedCuisine); return(View["show_restaurants.cshtml", model]); }; Delete["/"] = _ => { Cuisine.DeleteAll(); List <Cuisine> allCuisines = Cuisine.GetAll(); Dictionary <string, object> model = new Dictionary <string, object> { }; model.Add("user-name", Request.Form["user-name"]); model.Add("cuisines", allCuisines); return(View["index.cshtml", model]); }; Delete["/cuisine/{id}/delete"] = parameters => { Cuisine selectedCuisine = Cuisine.Find(parameters.id); selectedCuisine.DeleteSingleCuisine(); List <Cuisine> allCuisines = Cuisine.GetAll(); Dictionary <string, object> model = new Dictionary <string, object> { }; model.Add("user-name", Request.Form["user-name"]); model.Add("cuisines", allCuisines); return(View["index.cshtml", model]); }; Delete["/cuisine/{id}/restaurant"] = parameters => { Cuisine selectedCuisine = Cuisine.Find(parameters.id); selectedCuisine.DeleteRestaurants(); List <Cuisine> allCuisines = Cuisine.GetAll(); Dictionary <string, object> model = new Dictionary <string, object> { }; model.Add("user-name", Request.Form["user-name"]); model.Add("cuisines", allCuisines); return(View["index.cshtml", model]); }; Get["/cuisine/{id}/update"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object> { }; Cuisine selectedCuisine = Cuisine.Find(parameters.id); string formType = Request.Query["form-type"]; model.Add("selected-cuisine", selectedCuisine); model.Add("form-type", formType); return(View["form.cshtml", model]); }; Patch["/cuisine/{id}/update"] = parameters => { Cuisine selectedCuisine = Cuisine.Find(parameters.id); selectedCuisine.Update(Request.Form["cuisine-input"]); List <Cuisine> allCuisines = Cuisine.GetAll(); Dictionary <string, object> model = new Dictionary <string, object> { }; model.Add("user-name", Request.Form["user-name"]); model.Add("cuisines", allCuisines); return(View["index.cshtml", allCuisines]); }; Get["/cuisine/{cuisId}/restaurant/{restId}/update"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object> { }; Cuisine selectedCuisine = Cuisine.Find(parameters.cuisId); Restaurant selectedRestaurant = Restaurant.Find(parameters.restId); string formType = Request.Query["form-type"]; model.Add("selected-cuisine", selectedCuisine); model.Add("form-type", formType); model.Add("selected-restaurant", selectedRestaurant); return(View["form.cshtml", model]); }; Patch["/cuisine/{id}/restaurant/{restId}/update"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object> { }; Cuisine selectedCuisine = Cuisine.Find(parameters.id); Restaurant selectedRestaurant = Restaurant.Find(parameters.restId); selectedRestaurant.Update(Request.Form["restaurant-name-input"], Request.Form["restaurant-stars-input"]); List <Restaurant> cuisineRestaurants = selectedCuisine.GetRestaurants(); model.Add("selected-cuisine", selectedCuisine); model.Add("restaurants", cuisineRestaurants); return(View["show_restaurants", model]); }; Get["/cuisine/{cuisId}/restaurant/{restId}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object> { }; Cuisine selectedCuisine = Cuisine.Find(parameters.cuisId); Restaurant selectedRestaurant = Restaurant.Find(parameters.restId); List <Client> subscribers = selectedRestaurant.GetSubscribers(); List <Client> allClients = Client.GetAll(); model.Add("selected-cuisine", selectedCuisine); model.Add("restaurant", selectedRestaurant); model.Add("subscribers", subscribers); model.Add("all-clients", allClients); return(View["restaurant.cshtml", model]); }; Post["/cuisine/profile/new"] = _ => { Dictionary <string, object> model = new Dictionary <string, object> { }; Client newClient = new Client(Request.Form["user-name"]); newClient.Save(); List <Cuisine> allCuisines = Cuisine.GetAll(); model.Add("user-name", newClient); model.Add("cuisines", allCuisines); return(View["index.cshtml", model]); }; Post["/cuisine/{cuisId}/restaurant/{restId}/subscribed"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object> { }; Cuisine selectedCuisine = Cuisine.Find(parameters.cuisId); Restaurant selectedRestaurant = Restaurant.Find(parameters.restId); int userId = Request.Form["selected-user"]; Client selectedUser = Client.Find(userId); selectedUser.SubscribeToRestaurant(selectedRestaurant); List <Client> subscribers = selectedRestaurant.GetSubscribers(); List <Client> allClients = Client.GetAll(); model.Add("selected-cuisine", selectedCuisine); model.Add("restaurant", selectedRestaurant); model.Add("subscribers", subscribers); model.Add("all-clients", allClients); return(View["restaurant.cshtml", model]); }; Get["/search/results"] = _ => { Dictionary <string, object> model = new Dictionary <string, object> { }; string searchType = Request.Query["search-type"]; string searchQuery = Request.Query["search-query"]; List <Client> clientMatches = new List <Client> { }; List <Cuisine> cuisineMatches = new List <Cuisine> { }; List <Restaurant> restaurantMatches = new List <Restaurant> { }; if (searchType == "client") { clientMatches = Client.SearchByName(searchQuery); model.Add("matches", clientMatches); } else if (searchType == "cuisine") { cuisineMatches = Cuisine.SearchByName(searchQuery); model.Add("matches", cuisineMatches); } else if (searchType == "restaurant") { restaurantMatches = Restaurant.SearchByName(searchQuery); model.Add("matches", restaurantMatches); } model.Add("search-type", searchType); model.Add("search-query", searchQuery); return(View["results.cshtml", model]); }; }