Exemple #1
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                //TODO: Add insert logic here
                int storeCount;
                storeCount = int.Parse(collection["storeCount"]);

                #region Locations&Inventory
                List <string> locs = new List <string>();
                locs.Add(collection["Location1"]);
                locs.Add(collection["Location2"]);
                locs.Add(collection["Location3"]);
                locs.Add(collection["Location4"]);
                locs.Add(collection["Location5"]);
                locs.Add(collection["Location6"]);

                List <string> inv = new List <string>();
                inv.Add(collection["Inventory1"]);
                inv.Add(collection["Inventory2"]);
                inv.Add(collection["Inventory3"]);
                inv.Add(collection["Inventory4"]);
                inv.Add(collection["Inventory5"]);
                inv.Add(collection["Inventory6"]);
                #endregion

                Products product = new Products
                {
                    ProductName = collection["ProductName"],
                    ProductType = collection["ProductType"],
                    ProductUrl  = collection["ProductUrl"]
                };

                prodData.AddProductsDB(product, locs, inv, storeCount);

                return(RedirectToAction(nameof(ListProducts)));
            }
            catch
            {
                return(View(AddProduct()));
            }
        }
        static void ManageProductsMenu()
        {
            int         menuChoice = 0;
            Product     product    = new Product();
            ProductData prodData   = new ProductData();

            do
            {
                Console.Clear();
                Console.WriteLine("1. Add New Product");
                Console.WriteLine("2. Display All Products");
                Console.WriteLine("3+. Go Back");

                Console.WriteLine("\nEnter Your Choice: ");
                menuChoice = Int32.Parse(Console.ReadLine());
                Log.Information("Manage Products Menu Choice: {0}", menuChoice);

                switch (menuChoice)
                {
                case 1:
                    Console.Clear();

                    string     productName, productType, storeLocation = "";
                    int        storeCount = 0, inventoryForLoc = 0, storeLoc = 0;
                    List <int> storeLocationList  = new List <int>();
                    List <int> storeInventoryList = new List <int>();

                    Console.WriteLine("Enter Product Name: ");
                    productName = Console.ReadLine();
                    Log.Information("Entered Product Name: {0}", productName);

                    Console.WriteLine("Enter Game Platform: ");
                    productType = Console.ReadLine();
                    Log.Information("Entered Product Type: {0}", productType);

                    bool addStore = true;
                    while (addStore)
                    {
                        Console.WriteLine("How many Stores? [Up to 5]");
                        storeCount = Int32.Parse(Console.ReadLine());
                        if (storeCount > 5)
                        {
                            Console.WriteLine("Invalid Amount Of Stores");
                            Log.Information("Invalide Amount Of Stores. Amount Entered: {0}", storeCount);
                            addStore = true;
                        }
                        else
                        {
                            addStore = false;
                        }
                    }

                    bool         selectStore = true;
                    LocationData loc         = new LocationData();
                    for (int i = 0; i < storeCount; i++)
                    {
                        while (selectStore)
                        {
                            Console.WriteLine("Store Location {0}: ", i + 1);
                            loc.DisplayAllLocationsDB();
                            storeLoc = Int32.Parse(Console.ReadLine());
                            Log.Information("Entered Location: {0}", storeLoc);
                            if (storeLoc > 5)
                            {
                                Console.WriteLine("Invalid Store");
                                Log.Information("Invalide Store. Entered: {0}", storeLoc);
                                selectStore = true;
                            }
                            else
                            {
                                selectStore = false;
                            }
                        }
                        storeLocationList.Add(storeLoc);
                        Console.WriteLine("Inventory for the Store {0}", i + 1);
                        inventoryForLoc = Int32.Parse(Console.ReadLine());
                        Log.Information("Inventory for Location {0}", inventoryForLoc);
                        storeInventoryList.Add(inventoryForLoc);
                        selectStore = true;
                    }

                    prodData.AddProducts(jsonFilePathProducts, productName, productType, storeLocation, inventoryForLoc, storeCount, storeLocationList, storeInventoryList);
                    prodData.AddProductsDB(productName, productType, storeLoc, inventoryForLoc, storeCount, storeLocationList, storeInventoryList);

                    Console.WriteLine("Added Product {0} of type {1} to {2} stores", productName, productType, storeCount);
                    Log.Information("Added Product {0} of type {1} to {2} stores", productName, productType, storeCount);
                    Console.ReadKey();

                    break;

                case 2:
                    Console.Clear();

                    #region Serialized Display
                    //List<Product> tempDisplayProduct = new List<Product>();
                    //tempDisplayProduct = prodData.DisplayProducts(jsonFilePathProducts);
                    //Console.Clear();
                    //Console.WriteLine("Products");
                    //if (tempDisplayProduct.Count != 0)
                    //{
                    //    for (int i = 0; i < tempDisplayProduct.Count; i++)
                    //    {
                    //        Console.WriteLine(" {0}. {1} | ID: {2}", i + 1, tempDisplayProduct[i].ProductName, tempDisplayProduct[i].Id);
                    //    }
                    //}
                    //else
                    //{
                    //    Console.WriteLine("No Data Present");
                    //}
                    #endregion

                    ProductData prod = new ProductData();

                    prod.DisplayProductsDB();

                    Console.WriteLine("Press Any Key To Continue");
                    Console.ReadKey();
                    break;
                }
            } while (menuChoice < 3);
        }