예제 #1
0
 private static void DeleteCategory(Deleter deleter, Reader reader)
 {
     if (Lawyer.GetYesNo("Do you want to delete a category by CategoryID"))
     {
         int catId = Lawyer.GetInt("What is the Category Id you want to delete?");
         while (!(reader.DoesCategoryIdExist(catId)))
         {
             Console.WriteLine("Sorry that category does not exist, try again.");
             catId = Lawyer.GetInt("What is the Category Id you want to delete? ");
         }
         string categoryName = reader.GetCategoryName(catId);
         if (Lawyer.GetYesNo("Are you sure you want to delete this category " + categoryName))
         {
             deleter.DeleteCategoryById(catId);
         }
     }
     else if (Lawyer.GetYesNo("Do you want to delete a category by Name"))
     {
         string category = Lawyer.GetResponse("What is the Name of the Category you want to delete?");
         while (!(reader.DoesCategoryNameExist(category)))
         {
             Console.WriteLine("Sorry that category does not exist, try again.");
             category = Lawyer.GetResponse("What is the Name of the Category you want to delete?");
         }
         if (Lawyer.GetYesNo("Are you sure you want to delete this category :" + category))
         {
             deleter.DeleteCategoryByName(category);
         }
     }
 }
예제 #2
0
 private static void UpdateCategory(Updater updater, Reader reader)
 {
     if (Lawyer.GetYesNo("Do you want to update a category name using its name?"))
     {
         string currentName = Lawyer.GetResponse("What is the category you want to rename?");
         while (!(reader.DoesCategoryNameExist(currentName)))
         {
             Console.WriteLine("Sorry but that there is no category by that name, try again.");
             currentName = Lawyer.GetResponse("What is the category you want to rename?");
         }
         string newName = Lawyer.GetResponse("What do you want to rename the category?");
         while (reader.DoesCategoryNameExist(newName))
         {
             Console.WriteLine("Sorry but that category name already exists, try again.");
             newName = Lawyer.GetResponse("What do you want to rename the category?");
         }
         if (Lawyer.GetYesNo("Are you sure you want to rename the category: " + currentName + " to " + newName + "?"))
         {
             updater.UpdateCategoryByName(currentName, newName);
         }
     }
     else if (Lawyer.GetYesNo("Do you want to update a category name using its id?"))
     {
         int catid = Lawyer.GetInt("What is the category id name you want to rename?");
         while (!(reader.DoesCategoryIdExist(catid)))
         {
             Console.WriteLine("Sorry but that category id does not exist, try again.");
             catid = Lawyer.GetInt("What is the category id name you want to rename?");
         }
         string currentName = reader.GetCategoryName(catid);
         string newName     = Lawyer.GetResponse("What do you want to rename the category?");
         while (reader.DoesCategoryNameExist(newName))
         {
             Console.WriteLine("Sorry but that name already exist, try again.");
             newName = Lawyer.GetResponse("What do you want to rename the category?");
         }
         if (Lawyer.GetYesNo("Are you sure you want to rename the category: " + currentName + " to " + newName + "?"))
         {
             updater.UpdateCategoryById(catid, newName);
         }
     }
     else if (Lawyer.GetYesNo("Do you want to update a product's price using its current price?"))
     {
         decimal productPrice = Lawyer.GetDecimal("What is the price fo products you want to change?");
         while (!(reader.DoesProductPriceExist(productPrice)))
         {
             Console.WriteLine("Sorry there is no products with that price, try again.");
             productPrice = Lawyer.GetDecimal("What is the price fo products you want to change?");
         }
         decimal newPrice = Lawyer.GetDecimal("What price would you like to change the products of price :" + productPrice + " to be?");
         if (Lawyer.GetYesNo("Are you sure you want to change products with price " + productPrice + " to be " + newPrice + "?"))
         {
             updater.UpdateProductPriceByPrice(productPrice, newPrice);
         }
     }
 }
예제 #3
0
        public void UpdateCategoryById(int categoryid, string change)
        {
            string          catname = reader.GetCategoryName(categoryid);
            MySqlConnection conn    = new MySqlConnection(ConnStr);

            using (conn)
            {
                conn.Open();

                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "Update categories SET name = @change WHERE categoryid = @categoryid";
                cmd.Parameters.AddWithValue("categoryid", categoryid);
                cmd.Parameters.AddWithValue("change", change);
                cmd.ExecuteNonQuery();
            }
        }
예제 #4
0
 private static void DeleteProduct(Deleter deleter, Reader reader)
 {
     if (Lawyer.GetYesNo("Do you want to delete a product by Product Id?"))
     {
         int prodid = Lawyer.GetInt("What is the Product id that you want to delete?");
         while (!(reader.DoesProductIdExist(prodid)))
         {
             Console.WriteLine("Sorry but that product does not exist, try again.");
             prodid = Lawyer.GetInt("What is the Product id that you want to delete?");
         }
         string productId = reader.GetProductName(prodid);
         if (Lawyer.GetYesNo("Are you sure you want to delete this product :" + productId))
         {
             deleter.DeleteProductByID(prodid);
         }
     }
     else if (Lawyer.GetYesNo("Do you want to delete a product by Product Name?"))
     {
         string prodname = Lawyer.GetResponse("What is the Name of the product you want to delete?");
         while (!(reader.DoesProductNameExist(prodname)))
         {
             Console.WriteLine("Sorry but that product does not exist, try again.");
             prodname = Lawyer.GetResponse("What is the Name of the product you want to delete?");
         }
         if (Lawyer.GetYesNo("Are you sure you want to delete this product :" + prodname))
         {
             deleter.DeleteProductByName(prodname);
         }
     }
     else if (Lawyer.GetYesNo("Do you want to delete a product by Price?"))
     {
         decimal prodprice = Lawyer.GetDecimal("What is the price of products you want to delete?");
         while (!(reader.DoesProductPriceExist(prodprice)))
         {
             Console.WriteLine("Sorry no product has that price, try again.");
             prodprice = Lawyer.GetDecimal("What is the price of products you want to delete?");
         }
         List <string> products = reader.GetProductsByPrice(prodprice);
         if (Lawyer.GetYesNo("Are you sure you want to delete " + products.Count + " products"))
         {
             foreach (string product in products)
             {
                 deleter.DeleteProductByPrice(reader.GetProductPrice(product));
             }
         }
     }
     else if (Lawyer.GetYesNo("Do you want to delete a product by Category Id?"))
     {
         int catid = Lawyer.GetInt("What is the Category Id you want to delete products by?");
         while (!(reader.DoesProductWithCatIdExist(catid)))
         {
             Console.WriteLine("Sorry there are no products with that category id, try again");
             catid = Lawyer.GetInt("What is the Category Id you want to delete products by?");
         }
         string category = reader.GetCategoryName(catid);
         if (Lawyer.GetYesNo("Are you sure you want to delete all products that are asscoiated with:" + category + "?"))
         {
             deleter.DeleteProductByCategory(catid);
         }
     }
 }