Exemplo n.º 1
0
        static void Main(string[] args)
        {
            System.AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var user = UserInputServices.UserLogin();

            user.OrderPaid    += OrderPaidHandler;
            user.OrderShipped += OrderShippedHandler;

            EShopProgram(VendorsRepository.VendorsAndProducts, user);
        }
Exemplo n.º 2
0
        public static void EShopProgram(Dictionary <string, List <Product> > vendorsAndProducts, User user)
        {
            WriteLine(
                @"Choose what you want to do:

1. Get a list of all the vendors
2. Search the product catalog by vendor name or product name
3. Create an order for a product
4. View the products in the shopping cart
5. Remove an order for a product
6. Get an order receipt, proceed to payment and provide a shipping address
7. View your purchased orders
8. Exit the shop");

            string userInput = ReadLine();

            if (!Int32.TryParse(userInput, out int userInputNumber) || userInputNumber < 0 || userInputNumber > 9)
            {
                Message.Logo();
                Message.Print("Please try again and input a number between 1 and 8", ConsoleColor.DarkRed);
                EShopProgram(vendorsAndProducts, user);
            }
            else
            {
                Message.Logo();
                switch (userInputNumber)
                {
                case 1:
                    VendorsRepository.GetVendorsNames();
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 2:
                    UserInputServices.SearchProductCatalog();
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 3:
                    UserInputServices.OrderProduct(user);
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 4:
                    UserInputServices.ViewProductsInCart(user);
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 5:
                    UserInputServices.RemoveOrder(user);
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 6:
                    if (user.GetShoppingCart().Count > 0)
                    {
                        user.PrintOrderReceipt();
                        WriteLine($"{Message.textDivider}\n");
                        UserInputServices.EnterShippingAddress(user);
                        UserInputServices.EnterPaymentMethod(user);
                    }
                    else
                    {
                        Message.Print("You have no products in your shopping cart yet.", ConsoleColor.Yellow);
                    }
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 7:
                    UserInputServices.GetOrdersByPrice(user);
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 8:
                    Message.Print($"Thank you for visiting our shop, {user.UserName}! Please visit us again.", ConsoleColor.DarkGreen);
                    Environment.Exit(0);
                    break;

                default:
                    Message.Logo();
                    Message.Print("Please try again and input a number between 1 and 8", ConsoleColor.DarkRed);
                    EShopProgram(vendorsAndProducts, user);
                    break;
                }
            }
        }