public HomeModule() { Get["/"] = _ => { List <Cuisine> AllCuisines = Cuisine.GetAll(); return(View["index.cshtml", AllCuisines]); }; Post["/addCuisine"] = _ => { Cuisine newCuisine = new Cuisine(Request.Form["cuisine-name"]); newCuisine.Save(); List <Cuisine> AllCuisines = Cuisine.GetAll(); return(View["index.cshtml", AllCuisines]); }; Post["/addRestaurant"] = _ => { Restaurant newRestaurant = new Restaurant(Request.Form["restaurant-name"], Request.Form["restaurant-cuisine"], Request.Form["restaurant-address"], Request.Form["restaurant-phone"]); if ((Restaurant.FindName(Request.Form["restaurant-name"])).GetId() == 0) { newRestaurant.Save(); } List <Cuisine> AllCuisines = Cuisine.GetAll(); return(View["index.cshtml", AllCuisines]); }; Get["/restaurant/{id}"] = parameters => { Restaurant SelectedRestaurant = Restaurant.Find(parameters.id); return(View["restaurant.cshtml", SelectedRestaurant]); }; Get["/cuisine/{id}"] = parameters => { Cuisine SelectedCuisine = Cuisine.Find(parameters.id); return(View["cuisine.cshtml", SelectedCuisine]); }; Get["/restaurant/{id}/edit"] = parameters => { Restaurant SelectedRestaurant = Restaurant.Find(parameters.id); return(View["restaurant_edit.cshtml", SelectedRestaurant]); }; Patch["/restaurant/{id}/edit"] = parameters => { Restaurant SelectedRestaurant = Restaurant.Find(parameters.id); SelectedRestaurant.Update(Request.Form["restaurant-name"]); List <Cuisine> AllCuisines = Cuisine.GetAll(); return(View["index.cshtml", AllCuisines]); }; Delete["/restaurant/{id}/delete"] = parameters => { Restaurant SelectedRestaurant = Restaurant.Find(parameters.id); SelectedRestaurant.Delete(); List <Cuisine> AllCuisines = Cuisine.GetAll(); return(View["index.cshtml", AllCuisines]); }; Post["/search_results"] = _ => { Restaurant foundRestaurant = Restaurant.FindName(Request.Form["search"]); return(View["search_results.cshtml", foundRestaurant]); }; }
public void Test_Find() { Restaurant newRestaurant = new Restaurant("Italian", 2); newRestaurant.Save(); Restaurant testRestaurant = Restaurant.Find(newRestaurant.GetId()); Assert.Equal(testRestaurant, newRestaurant); }
public void Test_Find_FindsRestaurantInDatabase() { Restaurant testRestaurant = new Restaurant("Wolf & Bears", 1, "123 example st", "555-555-5555"); testRestaurant.Save(); Restaurant foundRestaurant = Restaurant.Find(testRestaurant.GetId()); Assert.Equal(testRestaurant, foundRestaurant); }
public void Test_Find_FindsRestaurantInDatabase() { //Arrange Restaurant testRestaurant = new Restaurant("Chipotle", 1, new DateTime(1984, 9, 3), "In da hood"); testRestaurant.Save(); //Act Restaurant foundRestaurant = Restaurant.Find(testRestaurant.GetId()); //Assert Assert.Equal(testRestaurant, foundRestaurant); }
public void Test_Find_FindsRestaurantInDatabase() { //Arrange Restaurant testRestaurant = new Restaurant("Manny's",1); testRestaurant.Save(); //Act Restaurant foundRestaurant = Restaurant.Find(testRestaurant.GetId()); //Assert Assert.Equal(testRestaurant, foundRestaurant); }
public void Test_Update_UpdateRestaurantInDatabase() { //Arrange Restaurant testRestaurant = new Restaurant("Chipotle", 1, new DateTime(1984, 9, 3), "In da hood"); testRestaurant.Save(); //Act testRestaurant.Update("Starbucks", 1, new DateTime(3030, 9, 3), "Portland"); Restaurant otherRestaurant = Restaurant.Find(testRestaurant.GetId()); //Assert Assert.Equal(testRestaurant, otherRestaurant); }
public void Test_Find_FindsRestaurantInDatabase() { //Arrange Restaurant testRestaurant = new Restaurant("Le Fromage", 1, "24 Main St.", "10AM", "11PM"); testRestaurant.Save(); //Act Restaurant foundRestaurant = Restaurant.Find(testRestaurant.GetId()); //Assert Assert.Equal(testRestaurant, foundRestaurant); }
public void Test5_FindId() { //Arrange Restaurant testRestaurant = new Restaurant("thai"); testRestaurant.Save(); //Act Restaurant foundRestaurant = Restaurant.Find(testRestaurant.GetId()); //Assert Assert.Equal(testRestaurant, foundRestaurant); }
public void Test_Find_FindsRestaurantInDatabase() { //arrange // int id = 1; Restaurant newRestaurant = new Restaurant("Lucia", 3, 1); newRestaurant.Save(); //Act Restaurant foundRestaurant = Restaurant.Find(newRestaurant.GetId()); //assert Assert.Equal(newRestaurant, foundRestaurant); }
public void Test_Update_RestaurantInDataBase() { string originalRestaurantName = "bob's mexican"; int originalRestaurantCuisine = 1; Restaurant originalRestaurant = new Restaurant(originalRestaurantName, originalRestaurantCuisine); originalRestaurant.Save(); string newRestaurantName = "Bob's sushi"; int newRestaurantCuisine = 2; Restaurant updatedRestaurant = new Restaurant(newRestaurantName, newRestaurantCuisine); originalRestaurant.Update(newRestaurantName, newRestaurantCuisine); Console.WriteLine(originalRestaurant.GetId()); Console.WriteLine(originalRestaurant.GetName()); Console.WriteLine(originalRestaurant.GetCuisineId()); Restaurant foundRestaurant = Restaurant.Find(originalRestaurant.GetId()); Console.WriteLine(foundRestaurant.GetId()); Console.WriteLine(foundRestaurant.GetName()); Console.WriteLine(foundRestaurant.GetCuisineId()); Assert.Equal(foundRestaurant, originalRestaurant); }
public HomeModule() { Get["/"] = _ => { List <Cuisine> allCuisines = Cuisine.GetAll(); return(View["index.cshtml", allCuisines]); }; Post["/cuisine/new"] = _ => { string newCuisineName = Request.Form["cuisine-name"]; Cuisine newCuisine = new Cuisine(newCuisineName); newCuisine.Save(); List <Cuisine> allCuisines = Cuisine.GetAll(); return(View["index.cshtml", allCuisines]); }; Get["/cuisines/{id}"] = parameters => { Cuisine currentCuisine = Cuisine.Find(parameters.id); return(View["cuisine.cshtml", currentCuisine]); }; Get["/cuisines/delete/{id}"] = parameters => { Cuisine currentCuisine = Cuisine.Find(parameters.id); return(View["cuisine_delete.cshtml", currentCuisine]); }; Delete["/cuisines/delete/{id}"] = parameters => { Cuisine currentCuisine = Cuisine.Find(parameters.id); currentCuisine.DeleteCuisine(); List <Cuisine> allCuisines = Cuisine.GetAll(); return(View["index.cshtml", allCuisines]); }; Get["/cuisines/update/{id}"] = parameters => { Cuisine currentCuisine = Cuisine.Find(parameters.id); return(View["cuisine_update.cshtml", currentCuisine]); }; Patch["/cuisines/update/{id}"] = parameters => { Cuisine currentCuisine = Cuisine.Find(parameters.id); currentCuisine.Update(Request.Form["cuisine-name"]); return(View ["cuisine.cshtml", currentCuisine]); }; Get["/cuisines/{id}/restaurants/new"] = parameters => { Cuisine currentCuisine = Cuisine.Find(parameters.id); return(View["restaurant_form.cshtml", currentCuisine]); }; Post["/cuisines/{id}/restaurants/new"] = parameters => { Restaurant newRestaurant = new Restaurant(Request.Form["restaurant-name"], parameters.id, Request.Form["restaurant-address"], Request.Form["restaurant-open-time"], Request.Form["restaurant-close-time"]); newRestaurant.Save(); return(View["cuisine.cshtml", Cuisine.Find(parameters.id)]); }; Get["/cuisines/{cuisineId}/restaurants/{id}"] = parameters => { Restaurant currentRestaurant = Restaurant.Find(parameters.id); Cuisine currentCuisine = Cuisine.Find(parameters.cuisineId); Dictionary <string, object> model = new Dictionary <string, object>() { { "restaurant", currentRestaurant }, { "cuisine", currentCuisine } }; return(View["restaurant_info.cshtml", model]); }; Get["/cuisines/{cuisineId}/restaurants/{id}/delete"] = parameters => { Restaurant currentRestaurant = Restaurant.Find(parameters.id); Cuisine currentCuisine = Cuisine.Find(parameters.cuisineId); Dictionary <string, object> model = new Dictionary <string, object>() { { "restaurant", currentRestaurant }, { "cuisine", currentCuisine } }; return(View["restaurant_delete.cshtml", model]); }; Delete["/cuisines/{cuisineId}/restaurants/{id}/delete"] = parameters => { Restaurant currentRestaurant = Restaurant.Find(parameters.id); Cuisine currentCuisine = Cuisine.Find(parameters.cuisineId); currentRestaurant.DeleteRestaurant(); // List<Restaurant> CuisineRestaurants = currentCuisine.GetRestaurants(); return(View["cuisine.cshtml", currentCuisine]); }; Get["/cuisines/{cuisineId}/restaurants/{id}/update"] = parameters => { Restaurant currentRestaurant = Restaurant.Find(parameters.id); List <Cuisine> allCuisines = Cuisine.GetAll(); Dictionary <string, object> model = new Dictionary <string, object>() { { "restaurant", currentRestaurant }, { "cuisines", allCuisines } }; return(View["restaurant_update.cshtml", model]); }; Patch["/cuisines/{cuisineId}/restaurants/{id}/update"] = parameters => { Restaurant currentRestaurant = Restaurant.Find(parameters.id); currentRestaurant.Update(Request.Form["restaurant-name"], Request.Form["cuisine-name"], Request.Form["restaurant-address"], Request.Form["restaurant-open-time"], Request.Form["restaurant-close-time"]); Cuisine currentCuisine = Cuisine.Find(currentRestaurant.GetCuisineId()); Dictionary <string, object> model = new Dictionary <string, object> { { "restaurant", currentRestaurant }, { "cuisine", currentCuisine } }; return(View["restaurant_info.cshtml", model]); }; }
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]); }; }
public HomeModule() { Get["/"] = _ => { return(View["index.cshtml"]); }; Get["/Cuisine"] = _ => { return(View["cuisine.cshtml", Cuisine.GetAll()]); }; Post["/Cuisine"] = _ => { Cuisine newCuisine = new Cuisine(Request.Form["name"]); newCuisine.Save(); return(View["cuisine.cshtml", Cuisine.GetAll()]); }; Get["/Cuisine/{id}"] = parameters => { Cuisine newCuisine = Cuisine.Find(parameters.id); List <Restaurant> restaurantList = Restaurant.FindByCuisineId(newCuisine.GetId()); Dictionary <string, object> myDictionary = new Dictionary <string, object> { }; myDictionary.Add("cuisine", newCuisine); myDictionary.Add("restaurants", restaurantList); return(View["cuisineView.cshtml", myDictionary]); }; Post["/Cuisine/Update/{id}"] = parameters => { Cuisine newCuisine = Cuisine.Find(parameters.id); newCuisine.Update(Request.Form["name"]); return(View["cuisine.cshtml", Cuisine.GetAll()]); }; Get["/Cuisine/Delete/{id}"] = parameters => { Cuisine newCuisine = Cuisine.Find(parameters.id); newCuisine.Delete(); return(View["cuisine.cshtml", Cuisine.GetAll()]); }; Get["/Cuisine/Create"] = _ => { return(View["cuisineCreate.cshtml"]); }; Get["/Cuisine/Delete"] = _ => { Cuisine.DeleteAll(); return(View["cuisine.cshtml", "delete"]); }; Get["/Restaurant"] = _ => { return(View["restaurant.cshtml", Restaurant.GetAll()]); }; Post["/Restaurant"] = _ => { DateTime newDateTime = Convert.ToDateTime((string)Request.Form["date"]); Restaurant newRestaurant = new Restaurant(Request.Form["name"], Request.Form["cuisine"], newDateTime, Request.Form["location"]); newRestaurant.Save(); return(View["restaurant.cshtml", Restaurant.GetAll()]); }; Get["/Restaurant/{id}"] = parameters => { List <Cuisine> cuisineList = Cuisine.GetAll(); Restaurant newRestaurant = Restaurant.Find(parameters.id); Dictionary <string, object> myDictionary = new Dictionary <string, object> { }; myDictionary.Add("cuisine", cuisineList); myDictionary.Add("restaurant", newRestaurant); return(View["restaurantView.cshtml", myDictionary]); }; Post["/Restaurant/Update/{id}"] = parameters => { Restaurant newRestaurant = Restaurant.Find(parameters.id); DateTime newDateTime = Convert.ToDateTime((string)Request.Form["date"]); newRestaurant.Update(Request.Form["name"], Request.Form["cuisine"], newDateTime, Request.Form["location"]); return(View["restaurant.cshtml", Restaurant.GetAll()]); }; Get["/Restaurant/Delete/{id}"] = parameters => { Restaurant newRestaurant = Restaurant.Find(parameters.id); newRestaurant.Delete(); return(View["restaurant.cshtml", Restaurant.GetAll()]); }; Get["/Restaurant/Create"] = _ => { List <Cuisine> newCuisine = Cuisine.GetAll(); return(View["restaurantCreate.cshtml", newCuisine]); }; Get["/Restaurant/Delete"] = _ => { Restaurant.DeleteAll(); return(View["restaurant.cshtml", "delete"]); }; }