Exemplo n.º 1
0
        public static void Create(Creator creator, Reader reader)
        {
            do
            {
                if (Lawyer.GetYesNo("Would you like to add a category to the merchandise to sell?"))
                {
                    if (Lawyer.GetYesNo("Do you want to see all the existing categories?"))
                    {
                        ReadCategory(reader);
                    }
                    string category = Lawyer.GetResponse("What would you like to call this category to be added to the database?");
                    while (reader.DoesCategoryNameExist(category))
                    {
                        Console.WriteLine("Sorry that category already exist try again?");
                        category = Lawyer.GetResponse("What would you like to call this category to be added to the database?");
                    }
                    creator.AddCategory(category);
                }

                else if (Lawyer.GetYesNo("Would you like to add a new product?"))
                {
                    if (Lawyer.GetYesNo("Do you want to see all existing products?"))
                    {
                        ReadProduct(reader);
                    }
                    string name     = Lawyer.GetResponse("What is the name of the item to be added to the store?");
                    string category = Lawyer.GetResponse("What category do you want would this item be considered?");
                    while (!(reader.DoesCategoryNameExist(category)))
                    {
                        Console.WriteLine("Category does not exist");
                        category = Lawyer.GetResponse("What category do would you consider this item?");
                    }
                    //previous line could break the entire program thinking about another add on to lawyer class
                    decimal price = Lawyer.GetDecimal("How much does this product cost?");
                    creator.AddProduct(name, price, category);
                }

                else if (Lawyer.GetYesNo("Would you like to add a sale?"))
                {
                    if (Lawyer.GetYesNo("Do you want to see all existing sales?"))
                    {
                        ReadSale(reader);
                    }
                    string product = Lawyer.GetResponse("What is the name of the product that has been sold?");
                    while (!(reader.DoesProductNameExist(product)))
                    {
                        Console.WriteLine("That product does not exist, please enter a valid product.");
                        product = Lawyer.GetResponse("What is the name of the product that has been sold?");
                    }
                    int      quantity = Lawyer.GetInt("How many of the item did the customer buy?");
                    int      year     = Lawyer.GetInt("What year has this transaction taken place?");
                    int      month    = Lawyer.GetInt("What numerical month has this transaction taken place?");
                    int      day      = Lawyer.GetInt("What day of the month has this transaction taken place?");
                    DateTime date     = new DateTime(year, month, day);

                    creator.AddSale(product, quantity, date);
                }
            } while (Lawyer.GetYesNo("Do you want to add more records?"));
        }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 3
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);
         }
     }
 }