Example #1
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);
         }
     }
 }