private void ManageLocationSection()
        {
            var locations = db.GetAllLocations();
            //bool toContinue = true;
            //do
            //{
            int storeID = ManageLocations(locations);

            PrintLocationMenu();
            int selection;

            while ((!int.TryParse(Console.ReadLine(), out selection)) && (selection == 1 || selection == 2))
            {
                Console.WriteLine("Please enter a 1 to view product Inventory or 2 to view order history.");
            }
            ;
            switch (selection)
            {
            case 1:
                DisplayProductInventory(storeID, locations);
                break;

            case 2:
                DisplayOrderHistory(storeID);
                break;

            default:
                // toContinue = false;
                break;
            }

            //} while (toContinue);
            //return toContinue;
        }
示例#2
0
        public void GetsAllLocations()
        {
            //Arrange
            var options = BuildInMemoryDb("GetsAllLocations");

            //Act
            using (var context = new P0DbContext(options))
            {
                var store = new Store
                {
                    Location = "Location1"
                };
                context.Add(store);
                store = new Store
                {
                    Location = "Location2"
                };
                context.Add(store);
                store = new Store
                {
                    Location = "Location3"
                };
                context.Add(store);
                context.SaveChanges();
            }
            //Assert
            using (var context = new P0DbContext(options))
            {
                var backend = new StoreBackend(context);
                var stores  = backend.GetAllLocations();

                Assert.Equal(3, stores.Count);
            }
        }
示例#3
0
        public void GetsCorrectInventoryCount()
        {
            //Arrange
            var options = BuildInMemoryDb("GetsInventoryCount");

            //Act
            using (var context = new P0DbContext(options))
            {
                CreateTwoproducts(context);

                var store = new Store
                {
                    StoreId           = 1,
                    Location          = "Location1",
                    AvailableProducts = new List <Inventory>
                    {
                        new Inventory
                        {
                            ProductId = 1,
                            StoreId   = 1,
                            Quantity  = 10
                        },
                        new Inventory
                        {
                            ProductId = 2,
                            StoreId   = 1,
                            Quantity  = 50
                        }
                    }
                };
                context.Add(store);
                context.SaveChanges();
            }
            //Assert
            using (var context = new P0DbContext(options))
            {
                var backend = new StoreBackend(context);
                var items   = backend.GetAllLocations().FirstOrDefault().AvailableProducts;

                Assert.Equal(2, items.Count);
            }
        }
示例#4
0
        private void ManagePlacingOrder()
        {
            //Get locations
            Console.Clear();
            PrintTitle();

            var locations = db.GetAllLocations();

            for (int i = 0; i < locations.Count; i++)
            {
                Console.WriteLine($"{i+1}. {locations[i].Location}");
            }
            //have the user select a location
            int selection;

            do
            {
                Console.Write("Select a store number to view its available products. ");
            } while (int.TryParse(Console.ReadLine(), out selection) && (selection < 0 || selection > locations.Count));
            //Display the products for that location
            Console.Clear();
            Console.WriteLine($"Inventory for location {locations[selection - 1].Location}\n");

            /*
             * if (null == locations[selection - 1].AvailableProducts || locations[selection - 1].AvailableProducts.Count == 0)
             * {
             *  Console.Write("There are no available products at that location. Press any key to return to the locations menu.");
             *  Console.ReadLine();
             *
             * }
             * else
             * {
             */
            foreach (var item in locations[selection - 1].AvailableProducts)
            {
                Console.WriteLine($"{item.ProductId}. {item.ProductDescription} available quantity {item.Quantity}");
            }
            //}

            //Have the user add products and quantites to the order
            Console.WriteLine("To add an item to the order enter an item number followed by the quantity.");
            var items = new List <ProductQuantity>();

            string[] input;
            bool     cont = true;

            do
            {
                var itemAlreadyAdded = false;
                input = Console.ReadLine().Split(' ');
                if (input.Length == 1)
                {
                    if (!(cont != string.IsNullOrEmpty(input[0])))
                    {
                        break;
                    }
                }
                if (input.Length == 2)
                {
                    foreach (var item in items)
                    {
                        if (item.ProductId == int.Parse(input[0]))
                        {
                            itemAlreadyAdded = true;
                            Console.WriteLine("That item has already been added to the order.");
                            break;
                        }
                    }
                    if (!itemAlreadyAdded)
                    {
                        items.Add(new ProductQuantity()
                        {
                            ProductId = int.Parse(input[0]),
                            Quantity  = int.Parse(input[1])
                        });
                    }
                    Console.WriteLine("You can continue to add items or press enter to finish the order.");
                }
                else
                {
                    Console.WriteLine("Enter the product number followed by a space followed by the desired quantity.");
                }
            } while (cont);
            if (DisplayPreOrderTotals(locations[selection - 1], items))
            {
                var orderInfo = db.PlaceNewOrder(locations[selection - 1].StoreId, customer.CustomerId, items);
                DisplayNewOrder(orderInfo);
            }
            else
            {
                Console.WriteLine("Order Canceled.");
            }

            Console.Write("Press any key to return to previous menu.");
            Console.ReadLine();
        }