예제 #1
0
        public void T2_Return_DishObjectsOverride()
        {
            Dish firstdish = new Dish("Pizza",13,3);
            Dish seconddish = new Dish("Pizza",13,3);

            Assert.Equal(firstdish, seconddish);
        }
예제 #2
0
        public void Test_GetAllDishesInStore_true()
        {
            Store myStore = new Store("lo-main",5);
              myStore.Save();

              Dish firstDish = new Dish("Pizza",13,myStore.GetId());
              firstDish.Save();
              Dish secondDish = new Dish("tacos",13,myStore.GetId());
              secondDish.Save();

              List<Dish> testDishList = new List<Dish> {firstDish,secondDish};
              List<Dish> resultDishList = myStore.GetDish();

              Assert.Equal(testDishList, resultDishList);
        }
예제 #3
0
        public void Test_DeleteOneStore_true()
        {
            Dish firstStoreDish = new Dish("burger",87,2);
              firstStoreDish.Save();

              Dish secondStoreDsih= new Dish("toco",56,9);
              secondStoreDsih.Save();

              firstStoreDish.Delete();

              List<Dish> resultDish=Dish.GetAll();
              List<Dish> afterDeleteOneStoreDish= new List<Dish> {secondStoreDsih};

              Assert.Equal(afterDeleteOneStoreDish,resultDish);
        }
예제 #4
0
        public void Test_Find_FindsDishInDatabase()
        {
            //Arrange
              Dish oneDish = new Dish("Pizza",13,3);
              oneDish.Save();

              //Act
              Dish foundDish  = Dish.Find(oneDish.GetId());
              Console.WriteLine(foundDish.GetName());
              Console.WriteLine(foundDish.GetPrice());
              Console.WriteLine(foundDish.GetStoreId());
              Console.WriteLine(foundDish.GetId());
              Console.WriteLine(oneDish.GetName());
              Console.WriteLine(oneDish.GetPrice());
              Console.WriteLine(oneDish.GetStoreId());
              Console.WriteLine(oneDish.GetId());
              //Assert
              Assert.Equal(oneDish, foundDish);
        }
예제 #5
0
        public void Test_DeleteOneStore_true()
        {
            Store firstStore = new Store("A",3);
            firstStore.Save();
            Store secondStore = new Store("B",2);
            secondStore.Save();

            Dish firstStoreDish = new Dish("burger",87,firstStore.GetId());
            firstStoreDish.Save();

            Dish secondStoreDsih= new Dish("toco",56,secondStore.GetId());
            secondStoreDsih.Save();

            firstStore.Delete();
            List<Store> allStores = Store.GetAll();
            List<Store> afterDeleteOneStore= new List<Store> {secondStore};

            List<Dish> resultDish=Dish.GetAll();
            List<Dish> afterDeleteOneStoreDish= new List<Dish> {secondStoreDsih};

            Assert.Equal(afterDeleteOneStore,allStores);
            Assert.Equal(afterDeleteOneStoreDish,resultDish);
        }
예제 #6
0
        public static Dish Find(int Id)
        {
            SqlConnection conn = DB.Connection();
               conn.Open();

               SqlCommand cmd = new SqlCommand("SELECT * FROM dish WHERE id = @dishId;", conn);
               SqlParameter DishParameter = new SqlParameter();
               DishParameter.ParameterName = "@dishId";
               DishParameter.Value = Id;
               cmd.Parameters.Add(DishParameter);
               SqlDataReader rdr = cmd.ExecuteReader();

               string foundName=null;
               int foundPrice=0;
               int foundStoreId=0;
               int foundId=0;

               while(rdr.Read())
               {
             foundId=rdr.GetInt32(0);
             foundName=rdr.GetString(1);
             foundPrice=rdr.GetInt32(2);
             foundStoreId=rdr.GetInt32(3);
               }
               Dish foundDish= new Dish(foundName, foundPrice, foundStoreId, foundId);

               if (rdr!= null)
               {
             rdr.Close();
               }
               if (conn != null)
               {
             conn.Close();
               }
               return foundDish;
        }
예제 #7
0
        public static List<Dish> GetAll()
        {
            List<Dish> allDishes = new List<Dish>{};

              SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM dish", conn);
              SqlDataReader rdr = cmd.ExecuteReader();

              while(rdr.Read())
              {
            int dishId = rdr.GetInt32(0);
            string dishName=rdr.GetString(1);
            int dishPrice= rdr.GetInt32(2);
            int dishStoreId=rdr.GetInt32(3);
            Dish oneDish=new Dish(dishName,dishPrice,dishStoreId,dishId);
            allDishes.Add(oneDish);
              }
               if (rdr != null)
               {
             rdr.Close();
               }

               if (conn != null)
               {
             conn.Close();
               }
               return allDishes;
        }
예제 #8
0
 public void Test_Save_DishesToObjects()
 {
     List<Dish> onedish = new List<Dish>{};
     Dish firstDish = new Dish("Pizza", 13,3);
     onedish.Add(firstDish);
     firstDish.Save();
     List<Dish> allDishes=Dish.GetAll();
     // Console.WriteLine(allDishes[0].GetName());
     // Console.WriteLine(allDishes[0].GetPrice());
     // Console.WriteLine(allDishes[0].GetStoreId());
     // Console.WriteLine(allDishes[0].GetId());
     Assert.Equal(onedish,allDishes);
 }
예제 #9
0
        public void Test_Save_AssignsIdToObjects()
        {
            Dish oneDish = new Dish("Pizza",13,3);
            oneDish.Save();
            Dish savedDish = Dish.GetAll()[0];

            Assert.Equal(oneDish, savedDish);
        }
예제 #10
0
        public void Test_UpdateDishesInDatabase()
        {
            Dish myDish = new Dish("cfdfgdgd", 2 ,5);
              myDish.Save();
              myDish.Update("q");
              string result = myDish.GetName();

              Assert.Equal("q", result);
        }
예제 #11
0
        public HomeModule()
        {
            Get["/"] = _ => {
              return View["index.cshtml"];
            };

            Get["/dishes"] = _ => {
            List<Dish> AllDish = Dish.GetAll();
            return View["dishes.cshtml", AllDish];
            };
            Get["/stores"] = _ => {
              List<Store> AllStores = Store.GetAll();
              return View["stores.cshtml", AllStores];
            };

            Get["/stores/new"] = _ => {
            return View["stores_form.cshtml"];
            };
            Post["/stores/new"] = _ => {
              Store newStore = new Store(Request.Form["store-name"],Request.Form["store-review"]);
              newStore.Save();
              return View["success.cshtml"];
            };
            Get["/dishes/new"] = _ => {
              List<Store> AllStores = Store.GetAll();
              return View["dishes_form.cshtml", AllStores];
            };
            Post["/dishes/new"] = _ => {
              Dish newDish = new Dish(Request.Form["dish-name"],Request.Form["dish-price"],Request.Form["store-id"]);
              newDish.Save();
              return View["success.cshtml"];
            };

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

            Get["/stores/{id}"] = parameters => {
              Dictionary<string, object> model = new Dictionary<string, object>();
              var SelectedStore = Store.Find(parameters.id);
              var StoreDish = SelectedStore.GetDish();
              model.Add("category", SelectedStore);
              model.Add("dishes", StoreDish);
              return View["store.cshtml", model];
            };

            Get["/store/edit/{id}"] = parameters => {
              Dish selectDishes = Dish.Find(parameters.id);
              return View["stores_edit.cshtml", selectDishes];
            };

            Patch["/store/edit/{id}"] = parameters => {
              Store selectedStore = Store.Find(parameters.id);
              selectedStore.Update(Request.Form["store-name"]);
              return View["success.cshtml"];
            };

            Get["store/delete/{id}"] = parameters => {
              Store SelectedStore = Store.Find(parameters.id);
              return View["store_delete.cshtml", SelectedStore];
            };

            Delete["/store/delete/{id}"] = parameters => {
              Store selectedStore = Store.Find(parameters.id);
              return View["success.cshtml"];
            };

            Get["/dishes/edit/{id}"] = parameters => {
              Dish selectDishes = Dish.Find(parameters.id);
              return View["dishes_edit.cshtml", selectDishes];
            };

            Patch["/dishes/edit/{id}"] = parameters => {
              Dish selectedStore = Dish.Find(parameters.id);
              selectedStore.Update(Request.Form["dish-name"]);
              return View["success.cshtml"];
            };

            Get["/dish/delete/{id}"] = parameters => {
              Dish SelectedStore = Dish.Find(parameters.id);
              return View["dishes_delete.cshtml", SelectedStore];
            };

            Delete["/dish/delete/{id}"] = parameters => {
              Dish selectedDish = Dish.Find(parameters.id);
              return View["success.cshtml"];
            };
        }
예제 #12
0
        //newStore.GetDish();
        //id = this.GetId()
        public List<Dish> GetDish()
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM dish WHERE store_id = @StoreId;", conn);
              SqlParameter storeIdParameter = new SqlParameter();
              storeIdParameter.ParameterName = "@StoreId";
              storeIdParameter.Value = this.GetId();
              cmd.Parameters.Add(storeIdParameter);
              SqlDataReader rdr = cmd.ExecuteReader();

              List<Dish> allDishes = new List<Dish> {};
              while(rdr.Read())
              {
            int dishId = rdr.GetInt32(0);
            string dishName = rdr.GetString(1);
            int dishPrice = rdr.GetInt32(2);
            int dishStoreId = rdr.GetInt32(3);

            Dish newDish = new Dish(dishName, dishPrice,dishStoreId,dishId);
            allDishes.Add(newDish);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allDishes;
        }