Ejemplo n.º 1
0
        public void RemoveProductFromCart()
        {
            if (myOrder.PurchaseList.Count > 0)
            {
                IView productListView = new ProductListView(myOrder.PurchaseList);
                productListView.Display();


                new MessageView().Display($"Enter item#(1-{myOrder.PurchaseList.Count}): ");
                int input = UserInput.GetUserInputAsInteger("");

                while (input <= 0 || input > myOrder.PurchaseList.Count)
                {
                    input = UserInput.GetUserInputAsInteger("");
                }
                input--;
                new MessageView().Display("Quantity(Press ENTER to delete 1): ");
                int     quantity       = UserInput.GetUserInputAsIntegerOrReturnOne("");
                string  nameOfItem     = myOrder.PurchaseList[input].Name;
                Product deletedProduct = myOrder.PurchaseList.Find(x => x.Name == nameOfItem);


                if (quantity >= deletedProduct.Qty)
                {
                    for (int i = 0; i < deletedProduct.Qty; i++)
                    {
                        myOrder.Subtotal -= deletedProduct.Price;
                    }
                    myOrder.PurchaseList.Remove(deletedProduct);
                }
                else
                {
                    for (int i = 0; i < quantity; i++)
                    {
                        deletedProduct.Qty--;
                        myOrder.Subtotal -= deletedProduct.Price;
                    }
                }
                myOrder.Tax = myOrder.Subtotal * Tax.tax;
            }
            else
            {
                new MessageView().Display("No items in current checkout....\n\n");
            }
        }
Ejemplo n.º 2
0
        public void Display()
        {
            IView productListView = new ProductListView(productList);

            productListView.Display();
        }
Ejemplo n.º 3
0
        public void AddProductToCart()
        {
            ProductListView productListView = new ProductListView(productList);
            IMessage        view            = new MessageView();
            int             quantity        = 0;

            view.Display("1: Search By Name\n2: Search By Category\n3: List All Products\n4: Go Back\n\nMake a selection: ");


            bool goBack = false;

            while (!goBack)
            {
                int input = UserInput.GetUserInputAsInteger("");

                switch (input)
                {
                case 1:
                    goBack = true;

                    ProductListView filteredList;

                    do
                    {
                        view.Display("Enter product name: ");
                        string name = UserInput.GetUserInput("");
                        filteredList = new ProductListView(productListView.GetFilteredList("name", name));
                    }while (filteredList.ProductList.Count < 1);

                    filteredList.Display();
                    do
                    {
                        view.Display(string.Format("\nChoose a product (1-{0}): ", filteredList.ProductList.Count));
                        input = UserInput.GetUserInputAsIntegerOrReturnOne("");
                    } while (!IsItemInProductList(input, 0, filteredList.ProductList.Count));
                    input--;
                    view.Display("Enter Quantity: ");
                    quantity = UserInput.GetUserInputAsIntegerOrReturnOne("");

                    if (myOrder.PurchaseList.Contains(filteredList.ProductList[input]))
                    {
                        myOrder.PurchaseList.Find(x => x.Name == filteredList.ProductList[input].Name).Qty += quantity;
                    }
                    else
                    {
                        filteredList.ProductList[input].Qty += quantity;
                        myOrder.PurchaseList.Add(filteredList.ProductList[input]);
                    }


                    break;

                case 2:
                    goBack = true;
                    string category;
                    bool   proceed = false;
                    do
                    {
                        view.Display("Enter product category (food/beverage): ");
                        category = UserInput.GetUserInput("").ToLower();
                        switch (category)
                        {
                        case "food":
                            proceed = true;
                            break;

                        case "beverage":
                            proceed = true;
                            break;

                        default:
                            proceed = false;
                            break;
                        }
                    } while (!proceed);

                    ProductListView filteredListByCat = new ProductListView(productListView.GetFilteredList("category", category));
                    filteredListByCat.Display();

                    do
                    {
                        view.Display(string.Format("\nChoose a product (1-{0})", filteredListByCat.ProductList.Count));
                        input = UserInput.GetUserInputAsInteger("");
                    } while (!IsItemInProductList(input, 0, filteredListByCat.ProductList.Count));

                    input--;
                    view.Display("Enter Quantity: ");
                    quantity = UserInput.GetUserInputAsIntegerOrReturnOne("");


                    if (myOrder.PurchaseList.Contains(filteredListByCat.ProductList[input]))
                    {
                        myOrder.PurchaseList.Find(x => x.Name == filteredListByCat.ProductList[input].Name).Qty += quantity;
                    }
                    else
                    {
                        myOrder.PurchaseList.Add(filteredListByCat.ProductList[input]);
                        myOrder.PurchaseList.Find(x => x.Name == filteredListByCat.ProductList[input].Name).Qty += quantity;
                    }

                    break;

                case 3:
                    goBack = true;
                    productListView.Display();

                    do
                    {
                        view.Display(string.Format("\nChoose a product (1-{0})", productList.Count));
                        input = UserInput.GetUserInputAsInteger("");
                    }while (!IsItemInProductList(input, 0, productList.Count));

                    input--;

                    view.Display("Enter Quantity: ");
                    quantity = UserInput.GetUserInputAsIntegerOrReturnOne("");


                    if (myOrder.PurchaseList.Contains(productList[input]))
                    {
                        myOrder.PurchaseList.Find(x => x.Name == productList[input].Name).Qty += quantity;
                    }
                    else
                    {
                        myOrder.PurchaseList.Add(productList[input]);
                        myOrder.PurchaseList.Find(x => x.Name == productList[input].Name).Qty += quantity;
                    }

                    break;

                case 4:
                    goBack = true;
                    break;


                default:

                    break;
                }
            }
        }