Exemplo n.º 1
0
        public static string FinalizeOrder(Location l, Order o, PizzaStoreRepository repo)
        {
            Console.WriteLine($"Thank you for your order. Your total is ${o.Price}");
            Console.WriteLine("Here are the details of your order:");
            for (var i = 0; i < o.PizzaList.Count; i++)
            {
                Console.WriteLine($"Pizza {i + 1}:");
                Console.WriteLine($"Size: { o.PizzaList[i].PizzaSize}");
                Console.WriteLine("Toppings:");
                foreach (KeyValuePair <string, bool> entry in o.PizzaList[i].Toppings)
                {
                    if (entry.Value == true)
                    {
                        Console.WriteLine(entry.Key);
                    }
                }
                Console.WriteLine();
                Console.WriteLine();
            }
            repo.PrintOrderHistory(o);
            repo.UpdateOrder(o);
            repo.Save();

            return("Order Finished.");
        }
Exemplo n.º 2
0
        public static string BeginOrder(string name, User u, Location l, PizzaStoreRepository repo)
        {
            Console.WriteLine("View your order history?");
            string ans = Console.ReadLine();

            if (ans == "y")
            {
                repo.PrintOrderHistory(repo.GetOrdersByUser(u));
            }

            Order o = new Order
            {
                User       = u,
                UserID     = repo.GetUserID(u),
                OrderTime  = DateTime.Now,
                LocationID = l.LocationID,
                NumPizza   = 0,
                Price      = 0
            };

            repo.AddOrder(o);
            repo.Save();
            o.Id = repo.GetMostRecentOrderID();

            //First check if the user ordered within 2 hours
            //if ((repo.GetMostRecentOrderByUser(o).OrderTime - o.OrderTime).TotalMinutes < 120)
            //{
            //    return $"No, {u.FirstName}, we can't prcoess your order since you have ordered within the past 2 hours.";
            //}


            if (l.UserExistInOrderHistory(l.OrderHistory, name))
            {
                //if the user exists, give a suggestion based on the last order...
                Pizza Suggested = Location.SortOrderHistory(l.OrderHistoryByUser(l.OrderHistory, name), "latest")[0].PizzaList[0];
                Console.WriteLine($"You have ordered a {Suggested.PizzaSize} with {Suggested.Toppings} in the past. Would you like to add this to your order? [y/n]");
                string answ = Console.ReadLine();
                if (answ == "y")
                {
                    o.PizzaList.Add(Suggested);
                    o.NumPizza++;
                    o.Price += Suggested.Price;
                    Console.WriteLine("Would you like to order more pizzas? [y/n]");
                    string more = Console.ReadLine();
                    if (more == "n")
                    {
                        FinalizeOrder(l, o, repo);
                    }
                }
            }
            //Now regardless of user in system or not they can order
            while (o.Price < 500)
            {
                if (o.NumPizza > 11)
                {
                    Console.WriteLine("Cannot order more pizza since you are ordering more than 12 pizzas.");
                    return("Failed to place order");
                }
                //Actually begin to order
                Pizza p = new Pizza()
                {
                    OrderID   = repo.GetMostRecentOrderID(),
                    PizzaSize = "A"
                };

                Console.WriteLine("Please select the size of your pizza [S/M/L]");
                p.PizzaSize = Console.ReadLine();
                //Update pizza price based on size
                if (p.PizzaSize == "S")
                {
                    p.Price    += 10;
                    p.PizzaSize = "S";
                }
                if (p.PizzaSize == "M")
                {
                    p.Price    += 15;
                    p.PizzaSize = "M";
                }
                if (p.PizzaSize == "L")
                {
                    p.Price    += 20;
                    p.PizzaSize = "L";
                }
                Console.WriteLine("We have the following toppings:");
                l.Toppings.ForEach(Console.WriteLine);
                for (var i = 0; i < l.Toppings.Count; i++)
                {
                    Console.WriteLine($"Add {l.Toppings[i]}? [y/n]");
                    AddTopping(l, p, l.Toppings[i], Console.ReadLine(), repo);
                }
                repo.AddPizza(p);
                repo.Save();
                p.Id = repo.GetMostRecentPizza().Id;
                o.PizzaList.Add(p);
                o.Price += p.Price;
                o.NumPizza++;

                Console.WriteLine($"You currently have {o.NumPizza} pizza(s). Would you like to order more? [y/n]");
                string b = Console.ReadLine();
                if (b == "n")
                {
                    break;
                }
            }
            FinalizeOrder(l, o, repo);
            return("Order Finished.");
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var configBuilder = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = configBuilder.Build();

            var optionsBuilder = new DbContextOptionsBuilder <PizzaStoreDBContext>();

            optionsBuilder.UseSqlServer(configuration.GetConnectionString("PizzaStoreDB"));
            var options = optionsBuilder.Options;

            var PizzaStoreDBContext = new Data.PizzaStoreDBContext(options);
            var PizzaStoreRepo      = new PizzaStoreRepository(PizzaStoreDBContext);

            Console.WriteLine("Welcome to Revature's PizzaStore!");
            PizzaStoreRepo.PrintOrderHistory(PizzaStoreRepo.SortByLatest());
            Console.WriteLine("To begin, please enter your Name");
            Console.Write("First Name: ");
            string fn = Console.ReadLine();

            Console.Write("Last Name: ");
            string ln   = Console.ReadLine();
            string name = User.FirstandLastName(fn, ln);

            //Check if pre-existing user:


            Console.WriteLine("Here are our locations:");
            Console.WriteLine("Location 1 - 123 Alpha street");
            Console.WriteLine("Location 2 - 456 Bravo street");
            Console.WriteLine("Location 3 - 789 Charlie street");
            Console.WriteLine("Location 4 - 246 Delta street");
            Console.WriteLine("Location 5 - 135 Echo street");
            string answer;

            while (true)
            {
                Console.WriteLine("Please enter your preferred location number");
                answer = Console.ReadLine();
                if (!int.TryParse(answer, out int n))
                {
                    Console.WriteLine("Please enter a number between 1 and 5");
                }
                else if (int.Parse(answer) > 0 && int.Parse(answer) < 6)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Not a valid store! Write a number 1 to 5");
                }
            }
            int PreferredLocation = int.Parse(answer);

            PizzaStoreRepo.PrintOrderHistory(PizzaStoreRepo.GetOrdersByLocation(PreferredLocation));
            string toPrint;

            //If user exists already:
            if (PizzaStoreRepo.DoesUserExist(fn, ln))
            {
                User u = PizzaStoreRepo.GetUser(fn, ln);
                if (u.DefaultLocation != PreferredLocation)
                {
                    Console.WriteLine($"Your default location is {u.DefaultLocation}. Would you like to change it to {PreferredLocation}? [y/n]");
                    string ans = Console.ReadLine();
                    if (ans == "y")
                    {
                        u.DefaultLocation = PreferredLocation;
                        PizzaStoreRepo.UpdateUser(u);
                        PizzaStoreRepo.Save();
                        //UPDATE THE USER HERE AND SAVE TO REPO
                    }
                }
                Console.WriteLine($"Your most recent order is:");
                PizzaStoreRepo.PrintOrderHistory(PizzaStoreRepo.GetMostRecentOrderByUser(u));
                toPrint = OrderHandler.BeginOrder(name, u, Master.LocationList[PreferredLocation - 1], PizzaStoreRepo);
            }
            else
            {
                User u = new User(name)
                {
                    FirstName       = fn,
                    LastName        = ln,
                    Name            = name,
                    DefaultLocation = PreferredLocation
                };
                Master.UserDict.Add(name, u);
                PizzaStoreRepo.AddUser(u);
                PizzaStoreRepo.Save();
                Console.WriteLine($"the user id is {PizzaStoreRepo.GetUserID(u)}");
                Console.WriteLine("Delete this user?");
                string answe = Console.ReadLine();
                if (answe == "y")
                {
                    PizzaStoreRepo.DeleteUser(u);
                    PizzaStoreRepo.Save();
                    return;
                }
                toPrint = OrderHandler.BeginOrder(name, u, Master.LocationList[PreferredLocation - 1], PizzaStoreRepo);
            }
            Console.WriteLine(toPrint);
        }