Exemple #1
0
        public static Store Find(int id)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM store WHERE id = @StoreId;", conn);
              SqlParameter storeIdParameter = new SqlParameter();
              storeIdParameter.ParameterName = "@StoreId";
              storeIdParameter.Value = id.ToString();
              cmd.Parameters.Add(storeIdParameter);
              SqlDataReader rdr = cmd.ExecuteReader();

              int foundStoreId = 0;
              string foundStoreName = null;
              int foundStoreReview = 0;
              while(rdr.Read())
              {
            foundStoreId = rdr.GetInt32(0);
            foundStoreName = rdr.GetString(1);
            foundStoreReview =rdr.GetInt32(2);
              }
              Store foundStore = new Store(foundStoreName,foundStoreReview,foundStoreId);

              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundStore;
        }
        public void Test_FindId()
        {
            Store myStore = new Store("kjoio",2);
              myStore.Save();
              //Save data to data base and assign id depending on table order
              Store findStore = Store.Find(myStore.GetId());

              Assert.Equal(findStore, myStore);
        }
        public void Test_Save_dish_true()
        {
            //Arrange, Act
            Store myStore= new Store("wer",5,1);
              myStore.Save();

              //Act
              List<Store> result = Store.GetAll();
              List<Store> testList = new List<Store>{myStore};

              //Assert
              Assert.Equal(testList, result);
        }
        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);
        }
        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);
        }
        public void Test_Save_ID_true()
        {
            Store myStore = new Store ("sdojofdkoedf",3);
              myStore.Save();
              //List return list of stores
              List<Store> allstores= Store.GetAll();
              //list of store in index o should be my store
              Store oneStore = allstores[0];

              int resultId= oneStore.GetId();
              int testId=myStore.GetId();

              Assert.Equal(resultId, testId);
        }
        public void Test_UpdateStoreInDatabase()
        {
            Store myStore = new Store("burger king", 2);
            myStore.Save();
            myStore.Update("burger Queen");
            string result = myStore.GetName();

            Assert.Equal("burger Queen", result);
        }
 public void Test_Store_Equal_returnTrue()
 {
     //Arrange, Act
     Store myStore= new Store("wer",5);
     Store myOtherStore= new Store("wer",5);
     //Assert
     Assert.Equal(myStore, myOtherStore);
 }
        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"];
            };
        }
Exemple #10
0
        public static List<Store> GetAll()
        {
            List<Store> allStores = new List<Store>{};

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

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

              while(rdr.Read())
              {
            int storeId = rdr.GetInt32(0);
            string storeName = rdr.GetString(1);
            int storeReview = rdr.GetInt32(2);
            Store newStore = new Store(storeName,storeReview,storeId);
            allStores.Add(newStore);
              }

              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }

              return allStores;
        }