Esempio n. 1
0
        public void RestockUi(DbRepo repo, Product p)
        {
            // ask for product and restock
            ProductTasks  pt          = new ProductTasks(repo);
            EmployeeTasks et          = new EmployeeTasks(repo);
            Product       realProduct = new Product();

            if (pt.GetProductById(p.Id).Equals(p.Id))
            {
            }
            else
            {
                pt.AddProduct(p);
            }

            string id;
            string proceed = "0";

            do
            {
                Console.WriteLine("Please enter a valid Product id");
                id = Console.ReadLine();
                while (ValidInput(id, "\\D"))
                {
                    Console.WriteLine("Sorry, please enter a whole number!");
                    id = Console.ReadLine();
                }

                realProduct = repo.GetProductById(Convert.ToInt32(id));

                if (realProduct == null)
                {
                    Console.WriteLine("Sorry, That id number was not valid!");
                    Console.WriteLine("Please select an option: \n[0] try again \n[any other key] quit");
                }
            } while (ValidInput(proceed, "0"));

            et.RestockProductGlobal(realProduct);
        }
        public void Start()
        {
            // first step: get info to create a customer object & check if that
            // customer is in the db

            string   proceed = "";
            Customer c;

            do
            {
                c       = LogIn();
                proceed = "4";
                if (c.Id == -1)
                {
                    Console.WriteLine("Quitting now.");
                    return;
                }
                if (c.Id == -2)
                {
                    Console.WriteLine("Sorry, that account is already claimed. Select an option to proceed");
                    Console.WriteLine("[0] Try Again");
                    Console.WriteLine("[1] Quit");
                    proceed = Console.ReadLine();
                }
            } while (ValidInput(proceed, "0"));

            if (ValidInput(proceed, "1"))
            {
                Console.WriteLine("Quitting now.");
                return;
            }

            // Next Step: let customer make order and persist to db

            Console.WriteLine($"Hello {c.Name}! Here are Today's Products: ");
            Console.Write("Milk \nCheese \nIce Cream\n");

            Console.WriteLine("Would you like to place an order? \n[0] Yes \n[1] No");
            proceed = Console.ReadLine();
            while (!ValidInput(proceed, "0|1"))
            {
                Console.WriteLine("Sorry, please enter 0 to proceed or 1 to quit");
                proceed = Console.ReadLine();
            }

            StoreContext  context    = new StoreContext();
            DbRepo        repo       = new DbRepo(context);
            OrderTasks    ot         = new OrderTasks(repo);
            CustomerTasks ct         = new CustomerTasks(repo);
            EmployeeTasks et         = new EmployeeTasks(repo);
            LocationTasks lt         = new LocationTasks(repo);
            ProductTasks  pt         = new ProductTasks(repo);
            List <Order>  previousOH = new List <Order>();

            if (c.Equals(repo.GetCustomerById(c.Id)))
            {
                previousOH = repo.GetCustomerById(c.Id).OrderHistory;
                repo.AddCustomer(c);
            }
            else
            {
                previousOH = repo.GetCustomerById(c.Id).OrderHistory;
                repo.RemoveCustomer((repo.GetCustomerById(c.Id)));
                repo.AddCustomer(c);
            }

            previousOH = c.OrderHistory;

            if (ValidInput(proceed, "0"))
            {
                Console.WriteLine("Time to place an order!");
                Order newOrder = MakeOrder();
                newOrder.Id = c.Id;
                Order emptyOrder = new Order();

                if (newOrder.Equals(emptyOrder))
                {
                    Console.WriteLine("GoodBye");
                    return;
                }

                string confirm;
                double price = newOrder.OrderPrice();
                Console.WriteLine($"That will be ${price}");
                do
                {
                    Console.WriteLine("Please Select [0] to pay now or [1] to cancel your order");
                    confirm = Console.ReadLine();
                }while (!ValidInput(confirm, "0|1"));
                if (ValidInput(confirm, "0"))
                {
                    c.AddOrderToHistory(newOrder);
                    repo.UpdateCustomer(c);
                    Console.WriteLine("Your order has been processed!");
                }
                if (ValidInput(confirm, "1"))
                {
                    Console.WriteLine("Your order has been cancelled. GoodBye.");
                }
            }
            //next step:
            Console.WriteLine("What would you like to do now?");
            Console.WriteLine("[0] Check Order History \n[1]Check location inventory \n[3]Check product stock");
            Console.WriteLine("[4] Quit");
            string next = Console.ReadLine();

            while (!ValidInput(next, "0|1|2|3"))
            {
                Console.WriteLine("Please select a valid option to continue");
                Console.WriteLine("[0] Check Order History \n[1]Check location inventory");
                Console.WriteLine("[2] Quit");
            }

            if (ValidInput(next, "0"))
            {
                ShowOrderHistory(c, repo, previousOH);
            }
            if (ValidInput(next, "1"))
            {
                CheckInventory(repo);
            }
            if (ValidInput(next, "2"))
            {
                Console.WriteLine("Have a nice day! Goodbye!");
                return;
            }
        }
 public void Setup()
 {
     _repository = MockRepository.GenerateMock<INHibernateRepository<Product>>();
     _tasks = new ProductTasks(_repository);
 }