Esempio n. 1
0
        public void Welcome()
        {
            Console.WriteLine("Tindahan ni Aling Nena");
            Console.WriteLine("Welcome BacK! What would you like to view?");
            Console.WriteLine(" [0] Location \n [1] Customer  \n [2] Orders \n [3] Exit");
            string input = Console.ReadLine();

            switch (input)
            {
            case "0":
                //go to the Locations UI
                AdminLocation al = new AdminLocation();
                al.Menu();
                break;

            case "1":
                //go to customer UI
                AdminCustomer ac = new AdminCustomer();
                ac.MainMenu();
                break;

            case "2":
                //go to order UI
                AdminOrder ao = new AdminOrder();
                ao.Menu();
                break;

            case "3":
                //go to exit
                ExitMenu exit = new ExitMenu();
                exit.Exit();
                break;

            default:
                //error handler
                ErrorHandler err = new ErrorHandler();
                err.InvalidInputMsg();
                Log.Error("Invalid Input.");
                Welcome();
                break;
            }
        }
        ///<summary>
        ///Method that returns a customer based on user input
        /// The customer is validated by taking valid customers via data handler that match conditions given by the user and asking the user to choose among them
        ///</summary>
        private Customer EnterCustomerDetails()
        {
            string choice;

            try
            {
                AdminCustomer   ac      = new AdminCustomer();
                List <Customer> choices = ac.SearchCustomer();
                do
                {
                    Console.WriteLine("Choose customer ");
                    choice = Console.ReadLine();
                } while (ErrorHandler.InvalidIntInput(choice));

                return(choices[int.Parse(choice)]);
            }
            catch (CustomerException ex)
            {
                Console.WriteLine(ex.Message);
                Log.Error(ex.Message);
                EnterCustomerDetails();
            }
            catch (NotImplementedException ex)
            {
                Console.WriteLine(ex.Message);
                Log.Error(ex.Message);
                EnterCustomerDetails();
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex.Message);
                Log.Error(ex.Message);
                EnterCustomerDetails();
            }
            catch (CustomerNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                Log.Error(ex.Message);
                Menu();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Log.Error(ex.Message);
                string input;
                do
                {
                    Console.WriteLine("Try Again? \n Y^(Yes) N^(No)");
                    input = Console.ReadLine();
                } while (ErrorHandler.InvalidInput(input));
                switch (input)
                {
                case "Y":
                    EnterCustomerDetails();
                    break;

                case "N":
                    Menu();
                    break;

                default:
                    break;
                }
            }
            return(new Customer());
        }
        ///<summary>
        ///Method to place order by passing business logic order object to data handler
        ///</summary>
        private void AddOrder()
        {
            OrderHandler    oh = new OrderHandler();
            LocationHandler lh = new LocationHandler();
            Customer        c  = new Customer();

            Console.WriteLine("New Customer? \n Y^(YES) N^(NO))");
            string input = Console.ReadLine();

            switch (input)
            {
            case "Y":
                AdminCustomer ac = new AdminCustomer();
                c = ac.AddNewCustomer();
                break;

            case "N":
                c = EnterCustomerDetails();
                break;

            default:
                ErrorHandler err = new ErrorHandler();
                err.InvalidInputMsg();
                AddOrder();
                break;
            }

            Location         l = EnterLocationDetails();
            string           choice;
            List <Inventory> custOrder = new List <Inventory>();

            do
            {
                Console.WriteLine("Choose Product to Order (Enter Index Number):");
                List <Inventory> availInvent = lh.GetAvailInventory(l);
                int j = 0;
                foreach (Inventory i in availInvent)
                {
                    Console.WriteLine("[" + j + "] " + " Name: " + i.Prod.Name + "\n Price: " + i.Prod.Price + "\n Remaining Stock: " + i.Stock);
                    j++;
                }
                input = Console.ReadLine();
                Console.WriteLine("Enter Quantity: ");
                string amount = Console.ReadLine();
                try
                {
                    lh.UpdateInventory(new Inventory()
                    {
                        Prod = availInvent[int.Parse(input)].Prod, Stock = int.Parse(amount)
                    }, l);
                }
                catch (InsufficientStockException ex)
                {
                    Console.WriteLine(ex.Message);
                    choice = "";
                    Log.Error("Insufficient Stock Exception. User tried to buy products more than available inventory");
                    continue;
                }
                catch (FormatException ex)
                {
                    Console.WriteLine(ex.Message);
                    choice = "";
                    Log.Error("Format Exception. User tried to input invalid format");
                    continue;
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine(ex.Message);
                    choice = "";
                    Log.Error(ex.Message);
                    continue;
                }
                catch (InvalidStockException ex)
                {
                    Console.WriteLine(ex.Message);
                    choice = "";
                    Log.Error(ex.Message);
                    continue;
                }
                custOrder.Add(new Inventory()
                {
                    Prod = availInvent[int.Parse(input)].Prod, Stock = int.Parse(amount)
                });
                do
                {
                    Console.WriteLine("Would you like to order another product? \n N^(NO) Y^(YES)");
                    choice = Console.ReadLine();
                } while (ErrorHandler.InvalidInput(choice));
            } while (choice != "N");
            Orders o = new Orders()
            {
                Cust      = c,
                Stor      = l,
                Date      = DateTime.Now,
                CustOrder = custOrder
            };

            oh.AddOrder(o);
            oh.PrintOrderDetails(o);
            Log.Information("Order Added");
            Log.Information($"Order was made by customer {c.FirstName} {c.LastName} at {l.BranchName} store");
            Menu();
        }