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_Delete_DeletesRestaurantFromDatabase() { //Arrange Restaurant testRestaurant1 = new Restaurant("Taste of India", 1, "123 example st", "555-555-5555"); testRestaurant1.Save(); Restaurant testRestaurant2 = new Restaurant("Olive Garden", 2, "123 example st", "555-555-5555"); testRestaurant2.Save(); //Act testRestaurant1.Delete(); List <Restaurant> resultRestaurants = Restaurant.GetAll(); List <Restaurant> testRestaurantList = new List <Restaurant> { testRestaurant2 }; //Assert Assert.Equal(testRestaurantList, resultRestaurants); }
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"]); }; }