Beispiel #1
0
        /// <summary>
        /// This is the start of the application. it will present main menue to useers
        /// </summary>
        public void start()
        {
            Log.Information("Store App started");

            // connecting to the DB
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();

            string connectionString = configuration.GetConnectionString("StoreDB");
            DbContextOptions <p0storeContext> options = new DbContextOptionsBuilder <p0storeContext>()
                                                        .UseSqlServer(connectionString).Options;

            var context = new p0storeContext(options);

            Console.WriteLine("\n***\tWELCOME TO OUR FLOWER SHOP\t***");
            bool repeat = true;

            do
            {
                Console.WriteLine("\nMAIN MENU");
                Console.WriteLine("Please enter \"1\" if you are a customer");
                Console.WriteLine("Please enter \"2\" if you are a manager");
                Console.WriteLine("Please enter \"3\" to Exit");
                string Response = Console.ReadLine();

                switch (Response)
                {
                case "1":
                    CustomerMenu newCustomerMenu = new CustomerMenu(new CustomerBL(new CustomerDB(context)), new OrderBL(new OrderDB(context)), new LocationBL(new LocationDB(context)));
                    newCustomerMenu.start();
                    break;

                case "2":
                    ManagerMenu newManager = new ManagerMenu(new LocationBL(new LocationDB(context)), new CustomerBL(new CustomerDB(context)), new OrderBL(new OrderDB(context)));
                    newManager.start();
                    break;

                case "3":
                    System.Console.WriteLine("\tThank you for Visiting Our store\n\t\t BYE BYE :)");
                    repeat = false;
                    break;

                default:
                    System.Console.WriteLine("Invalid input");
                    break;
                }
            } while(repeat);
        }
        public void Start()
        {
            Boolean stay = true;

            do
            {
                Console.Clear();
                Console.WriteLine(_menu);
                Console.WriteLine("Enter a #, 'Back' or 'Exit': ");
                string userInput = Console.ReadLine();

                IMenu menu;
                switch (userInput)
                {
                case "0":
                    try
                    {
                        if (Login())
                        {
                            menu = new CustomerMenu(_customer, _customerBL, _locationBL, _productBL, _inventoryLineItemsBL, _customerCartBL, _customerOrderLineItem, _customerOrderHistory);
                            menu.Start();
                        }
                        else
                        {
                            _customer = null;
                        }
                    }
                    catch (ArgumentNullException e)
                    {
                        Console.WriteLine("\nThe provided email is not associated with a customer!");
                        Console.ReadLine();
                        continue;
                    }
                    finally
                    {
                        _customer = null;
                    }
                    break;

                case "1":
                    try
                    {
                        CreateCustomer();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("\ninvalid input." + e.Message);
                        Console.ReadLine();
                        continue;
                    }
                    break;

                case "2":
                    Console.Clear();
                    GetCustomers();
                    break;

                /*case "3":
                 *  DeleteCustomer();
                 *  break;*/
                case "Back":
                    stay = false;
                    break;

                case "Exit":
                    System.Environment.Exit(1);
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Invalid input! Please select a menu item");
                    Console.WriteLine("Press Enter to view menu");
                    Console.ReadLine();
                    break;
                }
            } while (stay);
        }