private static void SearchById()
        {
            ClearHelper.Clear();
            Console.WriteLine("Pizza Search\n");
            Console.WriteLine("Search by ID:");
            int id = Int32.Parse(Console.ReadLine());

            Console.WriteLine("\nFetching Data, please wait...");
            PizzasDataAcess pizza = controller.FindById(id);

            Console.WriteLine();

            if (pizza == null)
            {
                Console.WriteLine($"There is no Ingredient with this Id");
            }
            else
            {
                Console.WriteLine(pizza.ToString());
            }

            Console.ReadKey();
            ClearHelper.Clear();
        }
Пример #2
0
        public static void ShowForm()
        {
            Console.WriteLine("Fetching Data, please wait...");

            OrderController orderController = new OrderController();
            OrderDataAccess order           = new OrderDataAccess();

            //Customer
            CustomerController        customerController = new CustomerController();
            List <CustomerDataAccess> customersList      = customerController.getAll();
            CustomerDataAccess        customer           = null;
            int customerId = 0;

            do
            {
                ClearHelper.Clear();
                Console.WriteLine("New Order\n");

                //Show all customers
                foreach (CustomerDataAccess c in customersList)
                {
                    Console.WriteLine(c.ToString());
                }

                //Select Customer
                Console.WriteLine("\nSelect Customer:\n");
                customerId = Int32.Parse(Console.ReadLine());
                customer   = customerController.FindById(customerId);

                if (customer == null)
                {
                    Console.WriteLine("\nWrong Customer Id");
                    Console.ReadKey();
                }

                ClearHelper.Clear();
            } while (customer == null);

            order.CustomerId = customer.Id;

            //Customer Address
            Console.WriteLine("Fetching Customer Addresses, please wait...");

            AddressController          addressController = new AddressController();
            List <AddressesDataAccess> addresses         = addressController.FindByCustomerId(customer.Id);
            AddressesDataAccess        address           = null;
            int  addressId    = 0;
            bool validAddress = false;

            do
            {
                ClearHelper.Clear();
                Console.WriteLine("Customer Address\n");

                //Show all customers
                foreach (AddressesDataAccess a in addresses)
                {
                    Console.WriteLine(a.ToString());
                }

                //Select Customer
                Console.WriteLine("\nSelect Customer's Address:\n");
                addressId = Int32.Parse(Console.ReadLine());
                address   = addressController.FindById(addressId);

                if (address == null)
                {
                    Console.WriteLine("\nWrong Customer Address's Id");
                    Console.ReadKey();
                }

                Console.WriteLine("\nChecking last order from this address. Please wait!\n");
                DateTime lastOrder = orderController.getLastOrderDate(address.Id);

                if (order.canOrderFromSameAddress(lastOrder) == true)
                {
                    order.AddressId = addressId;
                    validAddress    = true;
                }
                else
                {
                    Console.WriteLine("It's been less then 2 hours from the last order from this address");
                    Console.ReadKey();
                }
            } while (validAddress != true);

            //Pizzas
            Console.WriteLine("Fetching Pizzas, please wait...");

            PizzaController        pizzaController = new PizzaController();
            List <PizzaDataAccess> pizzas          = pizzaController.getAll();
            List <PizzaDataAccess> suggestedPizzas = orderController.getSuggestedPizzas(customer.Id);
            PizzaDataAccess        pizza           = null;
            string pizzaOption = null;
            int    pizzaId     = 0;

            do
            {
                pizzas = null;
                pizzas = pizzaController.getAll();

                ClearHelper.Clear();
                Console.WriteLine("Adding Pizzas to Order\n");

                //Show all pizzas
                foreach (PizzaDataAccess p in pizzas)
                {
                    //Cannot use Console.WriteLine(p.ToString()); because after adding a pizza to order, it shows the pizza's ingredient, don't know why
                    Console.WriteLine($"ID: {p.Id} - {p.Name} {Convert.ToDecimal(string.Format("{0:0,00.00}", p.Price))}");
                }

                //Suggested Pizzas
                Console.WriteLine("\n***SUGGESTED PIZZAS***");
                foreach (PizzaDataAccess sp in suggestedPizzas)
                {
                    Console.WriteLine(sp.ToString());
                }
                Console.WriteLine("***END SUGGESTED PIZZAS***");

                Console.WriteLine("\nd - Done");

                //Select pizza
                Console.WriteLine("\nSelect Pizza's Id:\n");
                pizzaOption = Console.ReadLine();

                bool pizzaOptionIsNumber = int.TryParse(pizzaOption, out pizzaId);

                //If pizzaOption is number get pizza
                if (pizzaOptionIsNumber == true)
                {
                    pizza = pizzaController.FindById(pizzaId);

                    if (pizza == null)
                    {
                        Console.WriteLine("\nWrong Pizza's Id");
                        Console.ReadKey();
                    }

                    bool checkStock       = true;
                    bool canAddMorePizzas = true;

                    //Check Stock
                    if (pizzaController.CheckStock(pizza) == true)
                    {
                        canAddMorePizzas = order.AddPizza(pizza);

                        //Cannot add more pizzas, then pizza Option = "d" for DONE, to stop while
                        if (canAddMorePizzas == false)
                        {
                            pizzaOption = "d";
                        }
                        else
                        {
                            pizzaController.DecreaseStock(pizza);
                            Console.WriteLine($"Pizza {pizza.Id} added!");
                            Console.ReadKey();
                        }
                    }
                    else
                    {
                        Console.WriteLine("Cannot add this pizza, Pizza's Ingredient stock is low");
                        Console.ReadKey();
                    }
                }
                //else, check if is "d" for Done
                else if (pizzaOption != "d")
                {
                    Console.WriteLine("Wrong option");
                }
            } while (pizzaOption != "d");

            order.Date = DateTime.Now;
            orderController.Save(order);

            Console.WriteLine("\nOrder saved!\n");
            Console.ReadKey();
            ClearHelper.Clear();
        }
Пример #3
0
        public static void ShowForm()
        {
            PizzasDataAcess pizza = new PizzasDataAcess();

            Console.Write("Pizza Name:\n");
            pizza.Name = Console.ReadLine();

            Console.Write("Pizza Price:\n");
            pizza.Price = Decimal.Parse(Console.ReadLine());

            Console.WriteLine("Retrieving Ingredients, please wait...\n");

            IngredientController        ingredientController = new IngredientController();
            List <IngredientsDataAcess> ingredientsList      = ingredientController.getAll();

            string option = "";

            do
            {
                Console.WriteLine();
                //Show all Ingredientes
                foreach (IngredientsDataAcess ingredient in ingredientsList)
                {
                    Console.WriteLine($"Ingredient ID: {ingredient.Id} - {ingredient.Name}");
                }
                Console.WriteLine("\nd - Done");

                Console.Write("\nIngredient ID:\n");
                option = Console.ReadLine();
                int ingredientId = 0;

                //if is integer
                if (int.TryParse(option, out ingredientId))
                {
                    IngredientsDataAcess ingredientSearch = ingredientController.FindById(ingredientId);

                    //If Ingredient exists with this ID
                    if (ingredientSearch != null)
                    {
                        pizza.PizzasIngredients.Add(new PizzasIngredientsDataAcess()
                        {
                            IngredientId = ingredientSearch.Id
                        });
                    }
                    //Not existis ingredients
                    else
                    {
                        Console.WriteLine("Invalid ID!");
                        Console.ReadKey();
                        ClearHelper.Clear();
                    }
                }
                //Not Integer, if is option d
                else if (option != "d")
                {
                    Console.WriteLine("Wrong Id or \"d\" for done");
                    Console.ReadKey();
                    ClearHelper.Clear();
                }
            } while (option != "d");


            PizzaController controller = new PizzaController();

            controller.Save(pizza);

            Console.WriteLine("\nPizza saved!\n");
            Console.ReadKey();
            ClearHelper.Clear();
        }