Exemplo n.º 1
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Cuisine> AllCuisine = Cuisine.GetAll();
                return(View["index.cshtml", AllCuisine]);
            };
            Get["/restaurants"] = _ => {
                List <Restaurant> AllResturants = Restaurant.GetAll();
                return(View["restaurants.cshtml", AllResturants]);
            };

            Get["/cuisines"] = _ => {
                List <Cuisine> AllCuisine = Cuisine.GetAll();
                return(View["cuisines.cshtml", AllCuisine]);
            };

            Get["/cuisines/new"] = _ => {
                return(View["cuisines_form.cshtml"]);
            };
            Post["/cuisines/new"] = _ => {
                Cuisine newCuisine = new Cuisine(Request.Form["cuisine-type"]);
                newCuisine.Save();
                return(View["success.cshtml"]);
            };
            Get["/restaurants/new"] = _ => {
                List <Cuisine> AllCuisine = Cuisine.GetAll();
                return(View["restaurants_form.cshtml", AllCuisine]);
            };
            Post["/restaurants/new"] = _ => {
                Restaurant newRestaurant = new Restaurant(Request.Form["restaurant-name"], Request.Form["cuisine-id"]);
                newRestaurant.Save();
                return(View["success.cshtml"]);
            };

            Post["/restaurants/delete"] = _ => {
                Restaurant.DeleteAll();
                return(View["cleared.cshtml"]);
            };

            Get["/cuisines/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var SelectedCuisine    = Cuisine.Find(parameters.id);
                var CuisineRestaurants = SelectedCuisine.GetRestaurants();
                model.Add("cuisine", SelectedCuisine);
                model.Add("restaurants", CuisineRestaurants);

                return(View["cuisine.cshtml", model]);
            };

            Get["/cuisine/edit/{id}"] = parameters => {
                Dictionary <string, object> model    = new Dictionary <string, object>();
                Cuisine           SelectedCuisine    = Cuisine.Find(parameters.id);
                List <Restaurant> CuisineRestaurants = SelectedCuisine.GetRestaurants();
                model.Add("cuisine", SelectedCuisine);
                model.Add("restaurants", CuisineRestaurants);
                return(View["cuisine_edit.cshtml", model]);
            };

            Patch["/cuisine/edit/{id}"] = parameters => {
                Cuisine SelectedCuisine = Cuisine.Find(parameters.id);
                SelectedCuisine.Update(Request.Form["cuisine-type"]);

                return(View["success.cshtml"]);
            };

            Get["/cuisine/delete/{id}"] = parameters => {
                Dictionary <string, object> model    = new Dictionary <string, object>();
                Cuisine           SelectedCuisine    = Cuisine.Find(parameters.id);
                List <Restaurant> CuisineRestaurants = SelectedCuisine.GetRestaurants();
                model.Add("cuisine", SelectedCuisine);
                model.Add("restaurants", CuisineRestaurants);
                return(View["cuisine_delete.cshtml", model]);
            };

            Delete["/cuisine/delete/{id}"] = parameters => {
                Cuisine SelectedCuisine = Cuisine.Find(parameters.id);
                SelectedCuisine.Delete();
                return(View["success.cshtml"]);
            };
        }
Exemplo n.º 2
0
 public void Dispose()
 {
     Restaurant.DeleteAll();
     Cuisine.DeleteAll();
 }
Exemplo n.º 3
0
        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"]);
            };
        }