Exemplo n.º 1
0
        public void EditInventory(Store store)
        {
            bool editting = true;

            while (editting)
            {
                int option = 0;
                while (!(option > 0 && option < 7))
                {
                    Outputter.WriteLine("Select an action:\n[1] Add a new product\n[2] Add inventory for existing product\n[3] Delete product from inventory\n[4] View Inventory\n[5] Quit back to main menu");
                    option = Inputter.GetIntegerInput();
                }
                switch (option)
                {
                case 1:
                    Outputter.Write("Enter a product name: ");
                    string name = Inputter.GetStringInput();
                    Outputter.Write("Enter a price: ");
                    decimal price = Inputter.GetDecimalInput();
                    Outputter.Write("How many do you want to add to inventory: ");
                    int quantity = Inputter.GetIntegerInput();
                    try
                    {
                        Product toAdd = new Product(name, price);
                        ProductRepo.AddProduct(toAdd);
                        toAdd = ProductRepo.GetProductByNameAndPrice(name, Convert.ToDecimal(price)); // This is necessary to get the ID of the product we just added
                        store.AddToInventory(toAdd, quantity);                                        // Don't think I need this
                        StoreRepo.AddToInventory(toAdd, store, quantity);
                        Outputter.WriteLine("Product added to inventory successfully!");
                    }
                    catch (ArgumentException)
                    {
                        Outputter.WriteLine("Couldn't add product to inventory.");
                    }
                    break;

                case 2:
                    PrintInventory(store.ID);
                    Outputter.Write("Enter a product ID: ");
                    try
                    {
                        int     productID = Inputter.GetIntegerInput();
                        Product p         = GetProductFromStoreByID(store, productID);
                        Outputter.Write("How many do you want to add to inventory: ");
                        int quantity2 = Inputter.GetIntegerInput();
                        if (quantity2 > 0)
                        {
                            StoreRepo.UpdateItemQuantity(p, store, quantity2);
                            Outputter.WriteLine("Product inventory added successfully!");
                        }
                        else
                        {
                            Outputter.WriteLine("Can't add 0 or negative inventory amount");
                        }
                    }
                    catch (Exception)
                    {
                        Outputter.WriteLine("Couldn't add inventory for product.");
                    }
                    break;

                case 3:
                    PrintInventory(store.ID);
                    Outputter.Write("Enter a product ID to remove: ");
                    int idRemove = Inputter.GetIntegerInput();
                    try
                    {
                        Product remove = GetProductFromStoreByID(store, idRemove);
                        StoreRepo.RemoveItemFromInventory(remove, store);
                        Outputter.WriteLine("Product successfully removed from inventory!");
                    }
                    catch (Exception)
                    {
                        Outputter.WriteLine("Couldn't remove product from inventory!");
                    }
                    break;

                case 4:
                    PrintInventory(store.ID);
                    break;

                case 5:
                    editting = false;
                    break;
                }
            }
        }