예제 #1
0
        public void Test_Find_FindsReviewsByRestaurantIdInDatabase()
        {
            // Arrange
            Restaurant testRestaurant = new Restaurant("Pizza Factory", "5th Street", "530-816-9999", 0);

            testRestaurant.Save();
            Review testReview = new Review("Their pizza was marvelous", 4, testRestaurant.GetId());

            testReview.Save();
            Review testReview1 = new Review("Their pizza was bland", 2, testRestaurant.GetId());

            testReview1.Save();
            Review testReview2 = new Review("Best pizza ever", 5, testRestaurant.GetId());

            testReview2.Save();
            Review testReview3 = new Review("Great Spaghetti", 3, 0);

            testReview3.Save();

            // Act
            List <Review> checkReviews = new List <Review> {
                testReview, testReview1, testReview2
            };
            List <Review> foundReviews = Review.FindAll(testRestaurant.GetId());

            // Assert
            Assert.Equal(checkReviews, foundReviews);
        }
예제 #2
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Get["/cuisine/form"] = _ => {
                return(View["cuisine_form.cshtml"]);
            };
            Get["/restaurant/form"] = _ => {
                return(View["restaurant_form.cshtml"]);
            };
            Get["/cuisines"] = _ => {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Post["/cuisines"] = _ => {
                Cuisine newCuisine = new Cuisine(Request.Form["cuisine"]);
                newCuisine.Save();
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Get["/restaurants"] = _ => {
                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Post["/restaurants"] = _ => {
                if (Cuisine.IsNewCuisine(Request.Form["restaurant-cuisine"]) != -1)
                {
                    Restaurant newRestaurant = new Restaurant(
                        Request.Form["restaurant-name"],
                        Request.Form["restaurant-address"],
                        Request.Form["restaurant-phonenumber"],
                        Cuisine.IsNewCuisine(Request.Form["restaurant-cuisine"]));
                    newRestaurant.Save();
                }
                else
                {
                    Cuisine newCuisine = new Cuisine(Request.Form["restaurant-cuisine"]);
                    newCuisine.Save();
                    Restaurant newRestaurant = new Restaurant(
                        Request.Form["restaurant-name"],
                        Request.Form["restaurant-address"],
                        Request.Form["restaurant-phonenumber"],
                        Cuisine.IsNewCuisine(Request.Form["restaurant-cuisine"]));
                    newRestaurant.Save();
                }

                List <Cuisine> allCuisines = Cuisine.GetAll();
                return(View["index.cshtml", allCuisines]);
            };
            Get["/cuisine/{id}"] = parameters =>
            {
                Cuisine newCuisine = Cuisine.Find(parameters.id);
                return(View["cuisine.cshtml", newCuisine]);
            };
            Post["/delete/cuisine/{id}"] = parameters =>
            {
                Cuisine targetCuisine = Cuisine.Find(parameters.id);
                targetCuisine.DeleteCuisineAndRestaurants();
                return(View["index.cshtml", Cuisine.GetAll()]);
            };
            Post["/delete/restaurant/{id}"] = parameters =>
            {
                Restaurant targetRestaurant = Restaurant.Find(parameters.id);
                int        cuisineId        = targetRestaurant.GetCuisineId();
                Restaurant.Delete(parameters.id);
                return(View["cuisine.cshtml", Cuisine.Find(cuisineId)]);
            };
            Get["/review/restaurant/{id}"] = parameters =>
            {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Restaurant    targetRestaurant    = Restaurant.Find(parameters.id);
                List <Review> allReviews          = Review.FindAll(parameters.id);
                model.Add("restaurant", targetRestaurant);
                model.Add("reviews", allReviews);
                return(View["restaurant.cshtml", model]);
            };
            Post["/review/restaurant/{id}"] = parameters =>
            {
                Review newReview = new Review(Request.Form["review"], Request.Form["stars"], parameters.id);
                newReview.Save();
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Restaurant    targetRestaurant    = Restaurant.Find(parameters.id);
                List <Review> allReviews          = Review.FindAll(parameters.id);
                model.Add("restaurant", targetRestaurant);
                model.Add("reviews", allReviews);
                return(View["restaurant.cshtml", model]);
            };
            Post["/update/cuisine/{id}"] = parameters =>
            {
                Cuisine updatedCuisine = Cuisine.Find(parameters.id);
                updatedCuisine.Update(Request.Form["updated-name"]);
                return(View["cuisine.cshtml", updatedCuisine]);
            };
        }