static void Main()
 {
     ///DbOptions options = new DbOptions();    //options needs to be initialized in constructor (without static)
     using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
     UI(pizzaboxRepository);
     pizzaboxRepository.Dispose();
 }
        public void Inventory()
        {
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();

            string locationid = "";
            int    tried      = trials = 3;
            int    id         = 0;

            do
            {
                Console.WriteLine("Please select your location:");
                int count = Locations();
                Console.Write("Store ID (enter digit): ");
                locationid = Console.ReadLine();
                Console.Clear();
                if (int.TryParse(locationid, out id))
                {
                    if (id < 1 || id > count)
                    {
                        if (trials > 1)
                        {
                            Console.WriteLine("Please enter a digit according to store IDs displayed below:");
                            trials--;
                        }
                        else
                        {
                            Console.WriteLine("You have failed to identify your shop " + tried + " times.");
                            Exit();
                            return;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            } while (trials > 0);

            var query = pizzaboxRepository.GetInventoryByStore(id);
            var store = pizzaboxRepository.GetStoreById(id);

            if (query == null)
            {
                if (store == null)
                {
                    Console.WriteLine("There is no such store.");
                    return;
                }

                Console.WriteLine("Inventory at location #" + store.StoreId + " is currently unavailable. Please contact your administrator.");
                return;
            }

            Console.WriteLine("Store #" + id.ToString().PadLeft(12 - id.ToString().Length, '0'));
            Console.WriteLine("Has enough ingredients for " + query.Preset + " Presets");
            Console.WriteLine("Has enough ingredients for " + query.Custom + " Customs");

            Console.WriteLine();
        }
예제 #3
0
        public static User Login()
        {
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            User Me = new User();

            trials = 3;
            do
            {
                #region Username and Password Entry
                Console.WriteLine("USER LOGIN");
                Console.Write("Username: "******"Password: "******"authentication");
                    continue;
                }
                #endregion

                #region Authentication
                Me = AuthorizedUser;
                bool success = false;
                switch (Me.SessionLive)
                {
                //ALREADY LOGGED IN
                case 1:
                /*
                 * Error("session");
                 * break;
                 */

                //NOT LOGGED IN
                case 0:
                    Console.WriteLine("Login successful\n");
                    Me.SessionLive = 1;
                    pizzaboxRepository.UpdateUser(Me);
                    success = true;
                    break;
                }

                if (success)
                {
                    break;
                }
                #endregion
            } while (trials > 0);

            return(Me);
        }
        }   //!!! Marked for refinement

        public void Logout()
        {
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            Console.Write("Signing you out ");

            #region Loading Animation
            Loading('.', 3, 2);
            #endregion

            CurrentUser.SessionLive = 0;
            pizzaboxRepository.UpdateUser(CurrentUser);
        }
        static void UI(IPizzaboxRepository pizzaboxRepository)
        {
            string header1 = "Welcome to Pizza Box";
            string header2 = "Please sign in to your account to get started.\nIf you don't have an account, sign up with us now and get 50% off your first purchase!";

            bool shown = false;

            while (!exit_proc)
            {
                do
                {
                    if (!priority)
                    {
                        Console.WriteLine(header1);
                        if (!shown)
                        {
                            Console.WriteLine(header2);
                            shown = true;
                        }

                        Run.InitRun();
                    }
                    else
                    {
                        Console.WriteLine("Who are you signing in for?");
                        Console.Write("Enter name here: ");
                        string answer = Console.ReadLine();
                        Console.Clear();
                        CurrentUser = Run.Login("sa-admin", answer);
                        alive       = CurrentUser.SessionLive;
                    }
                } while (alive == 0);
                shown = false;
                bool clearin = false;
                while (alive == 1)
                {
                    if (!clearin)
                    {
                        Thread.Sleep(600);
                        Console.Clear();
                        clearin = true;
                    }
                    if (Session() == 1)
                    {
                        priority = true;
                    }
                }
                Console.Clear();
            }
            Utilities.Exit();
        }
        public void Fail_Authentication()
        {
            // ARRANGE
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            User Expected = null;

            string[] username_auth = { "admin", "Uname23", "Admin", "uname23", "ad", "Uname", "Password123", "adminpass" };
            string[] password_auth = { "adminpas", "Password", "adminpass", "Password123", "admin", "password123", "Uname23", "admin" };

            for (int i = 0; i < username_auth.Length; i++)
            {
                // ACT
                User Actual = pizzaboxRepository.UserAuthentication(username_auth[i], password_auth[i]);

                // ASSERT
                Assert.Equal(Expected, Actual);
            }
        }
        public void Check_UpdateUser()
        {
            // ARRANGE
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            User U1 = new User()
            {
                Username    = "******",
                Pass        = "******",
                FullName    = "That Way",
                SessionLive = 1
            };
            User Expected = U1;

            // ACT
            pizzaboxRepository.UpdateUser(U1);
            User Actual = pizzaboxRepository.GetUserById("Uname23");

            // ASSERT
            Assert.Equal(Expected, Actual);
        }
        public void Check_AddUser()
        {
            // ARRANGE
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            User U1 = new User
            {
                Username    = "******",
                Pass        = "******",
                FullName    = "Yah Who",
                SessionLive = 0
            };
            User Expected = U1;

            // ACT
            pizzaboxRepository.AddUser(U1);
            User Actual = pizzaboxRepository.GetUserById("whaa");

            // ASSERT
            Assert.Equal(Expected, Actual);
        }
예제 #9
0
        internal static User Signup()
        {
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            User newUser = new User
            {
                Username    = "",
                Pass        = "",
                FullName    = "",
                SessionLive = 0
            };

            #region Header
            Console.WriteLine("SIGN UP");
            Console.WriteLine("You're one step away from being a Pizza Box member!");
            Console.WriteLine("___________________________________________________");
            #endregion

            #region Choose Account Type
            trials = 3;
            string answer;
            do
            {
                Console.Write("Account Type (customer or employee): ");
                answer = Console.ReadLine();

                if (answer.ToLower() == "employee")
                {
                    if (pizzaboxRepository.GetUserById("admin") != null)
                    {
                        Utilities.Error("exists");
                    }

                    /*
                     * if (DB.User.Any(u => u.Username == "admin"))
                     *  Error("exists");
                     */
                    else
                    {
                        newUser.Username = "******";
                        break;
                    }
                }
                else if (answer.ToLower() == "customer")
                {
                    break;
                }
                else
                {
                    Utilities.Error("entry");
                }
            } while (trials > 0);
            #endregion

            #region Choose Username
            trials = 3;
            bool pass = false;
            do
            {
                Console.Write("Username: "******"admin":
                    Console.WriteLine("admin");
                    pass = true;
                    break;

                default:
                    newUser.Username = Console.ReadLine();
                    if (newUser.Username.ToLower() == "admin")
                    {
                        newUser.Username = "";
                    }
                    else if (pizzaboxRepository.GetUserById(newUser.Username) != null)
                    {
                        Utilities.Error("exists");
                    }

                    /*
                     * else if (DB.User.Any(u => u.Username == newUser.Username))
                     *  Error("exists");
                     */
                    else
                    {
                        pass = true;
                    }
                    break;
                }

                if (newUser.Username.Length == 0)
                {
                    Utilities.Error("user");
                }
            } while (!pass);
            #endregion

            #region Choose Password
            Console.Write("Password: "******"Full Name: ");
            newUser.FullName = Console.ReadLine();
            #endregion

            Console.Write("\nGetting your account ready ");

            #region loading animation
            Utilities.Loading('.', 3, 3);
            Console.WriteLine();
            #endregion

            newUser.SessionLive = 1;
            pizzaboxRepository.AddUser(newUser);
            return(newUser);
        }
        public int Locations()
        {
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            var results = pizzaboxRepository.GetAllStores();

            //***
            if (results.Count() == 0)
            {
                bool flag = false;
                Console.WriteLine("We are still in construction. We should be finished soon.");
                Console.WriteLine("Would you like to sign up for updates?");
                Console.Write("Enter (Y/N): ");
                string answer  = Console.ReadLine();
                bool   updates = false;
                Console.Clear();
                switch (answer.ToLower())
                {
                case "y":
                case "yes":
                case "sure":
                case "alright":
                case "ok":
                case "okay":
                    updates = true;
                    break;

                case "n":
                case "no":
                case "nah":
                case "nope":
                case "no thank you":
                case "no thanks":
                case "im good":
                case "i'm good":
                case "im ok":
                case "i'm ok":
                case "im okay":
                case "i'm okay":
                default:
                    break;
                }

                if (updates)
                {
                    do
                    {
                        if (flag)
                        {
                            Console.WriteLine("*Make sure your email contains '@' and ends with an extension (e.g .com)");
                            Console.WriteLine("If you would like to navigate back, just leave it blank or enter anything that could be interpreted as 'go back'");
                            flag = false;
                        }
                        Console.Write("Enter Email: ");
                        answer = Console.ReadLine();
                        switch (answer.ToLower())
                        {
                        case "back":
                        case "go back":
                        case "that way":
                        case "<<<-":
                        case "<<-":
                        case "<-":
                        case "<<<":
                        case "<<":
                        case "<":
                        case "-":
                        case "..":
                        case "/..":
                        case "previous":
                        case "":
                            return(0);
                        }

                        if (!answer.Contains("@") || answer[answer.Length - 4] != '.')
                        {
                            Console.Clear();
                            Console.WriteLine("Email Invalid Format");
                            flag = true;
                        }
                        else
                        {
                            Console.WriteLine("You have successfully signed up for updates.");
                            Console.WriteLine();
                            return(0);
                        }
                    } while (answer.Length > 0);
                }
                return(0);
            }

            foreach (Store s in results)
            {
                if (s.City.Length < 9)
                {
                    Console.Write(s.StoreId + "\t" + s.City);
                    for (int i = 0; i < 9 - s.City.Length; i++)
                    {
                        Console.Write(" ");
                    }
                    Console.WriteLine("\t" + s.State + "\t" + s.Zip);
                }
                else
                {
                    Console.WriteLine(s.StoreId + "\t" + s.City + "\t" + s.State + "\t" + s.Zip);
                }

                //count++;
            }
            Console.WriteLine();
            return(results.Count());
        }   //!!! Marked for refinement
        public override void History()
        {
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();

            Console.WriteLine("1. Recent Orders by Shop");
            Console.WriteLine("2. All Orders");
            Console.Write("Please make a selection (enter digit): ");
            string answer = Console.ReadLine();

            Console.Clear();
            bool all = false;

            switch (answer.ToLower())
            {
            case "1":
            case "recent orders by shop":
            case "by shop":
            case "shop":
            case "store":
            case "store orders":
                all = false;
                break;

            case "2":
            case "all orders":
            case "all":
            case "everything":
            case "all stores":
            case "all shops":
            case "all locations":
                all = true;
                break;

            default:
                Console.WriteLine("Invalid selection.");
                return;
            }

            IEnumerable <Orders> results;

            if (all)
            {
                Console.WriteLine("ORDER HISTORY AT ALL LOCATIONS");
                results = pizzaboxRepository.GetOrdersBy("", "all");
            }
            else
            {
                #region ADMIN INPUT STORE LOCATION
                string locationid = "";
                int    count      = 0;
                int    id         = 0;
                trials = 3;
                do
                {
                    count = Locations();
                    Console.Write("Pick a location (Enter ID Here): ");
                    locationid = Console.ReadLine();
                    Console.Clear();
                    if (int.TryParse(locationid, out id))
                    {
                        if (id < 1 || id > count)
                        {
                            if (trials > 1)
                            {
                                Console.WriteLine("Please enter a digit according to store IDs displayed below:");
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (trials > 1)
                        {
                            Console.WriteLine("Please enter a digit according to store IDs displayed below:");
                        }
                    }

                    trials--;
                } while (trials > 0);
                if (trials < 1)
                {
                    Console.WriteLine("Sorry, we tend to think inside the box.\nYou can always contact us directly at 7499274992 (PIZZAPIZZA).\n");
                    Exit();
                    return;
                }
                #endregion

                var store = pizzaboxRepository.GetStoreById(id);
                Console.WriteLine("ORDERS AT " + store.City.ToUpper() + " SHOP");

                results = pizzaboxRepository.GetOrdersBy(locationid, "store");
            }

            if (results.Count() < 1)
            {
                Console.WriteLine("No orders have been made.\n");
                return;
            }

            Orders[]    O   = new Orders[results.Count()];
            Ordertype[] OT  = new Ordertype[results.Count()];
            int[]       ids = new int[results.Count()];

            #region Initialization of O, OT, and ids
            int i;
            for (i = 0; i < results.Count(); i++)
            {
                O[i] = new Orders()
                {
                    OrderId  = 0,
                    StoreId  = 0,
                    Username = ""
                };
                OT[i] = new Ordertype()
                {
                    OrderId = 0,
                    Preset  = "",
                    Custom  = "",
                    Dt      = "",
                    Tm      = ""
                };
                ids[i] = new int();
            }
            #endregion

            #region Map Orders results
            i = 0;
            foreach (var val in results)
            {
                O[i]   = val;
                ids[i] = val.OrderId;

                #region NOTE:
                ///NOTE: DataReader can not use result from Entity1 query while querying data in Entity2
                #endregion
                i++;
            }

            for (i = 0; i < results.Count(); i++)
            {
                OT[i] = pizzaboxRepository.GetOrdertypeById(ids[i]);

                #region OT[i] can be assumed != null as long as developers don't mess with it.  Make sure they can't

                /*
                 * if (OT[i] == null)
                 * {
                 *  //handle it
                 * }
                 */
                #endregion
            }
            #endregion

            #region Display Full List of Recent Orders
            i = 0;
            while (i < results.Count())
            {
                int    j = 0, n = 0;
                string nums, sequence;

                ///DISPLAY ORDER# AND DATE/TIME
                Console.WriteLine("Order #" + O[i].OrderId.ToString().PadLeft(12 - O[i].OrderId.ToString().Length, '0'));
                string D = OT[i].Dt.Replace('.', '/');
                string T = OT[i].Tm.Replace('.', ':');
                Console.WriteLine(D + " " + T);

                ///PRESET TRANSLATION TO HUMAN-READABLE FORMAT
                do
                {
                    ///RESET TRANSLATED SEQUENCE AFTER EACH PRINT
                    nums     = "";
                    sequence = "";

                    if ((OT[i].Preset.Length > 0 && OT[i].Preset[0] == '-') || OT[i].Preset.Length == 0)
                    {
                        break;
                    }

                    ///GET FULL DIGIT FROM ORIGINAL SEQUENCE UNTIL ISLETTER - Worst O(3)
                    while (j < OT[i].Preset.Length && Char.IsDigit(OT[i].Preset[j]))
                    {
                        nums += OT[i].Preset[j];
                        j++;
                    }

                    //NUMS IS NOT A NUMBER? SKIP
                    if (!int.TryParse(nums, out n))
                    {
                        break;
                    }

                    ///GET FULL CHAR SEQUENCE FROM ORIGINAL UNTIL NEXT DIGIT/END - Worst O(2)
                    while (j < OT[i].Preset.Length && Char.IsLetter(OT[i].Preset[j]))
                    {
                        switch (OT[i].Preset[j])
                        {
                        case 'S':
                            sequence += "Small Preset, ";
                            break;

                        case 'M':
                            sequence += "Medium Preset, ";
                            break;

                        case 'L':
                            sequence += "Large Preset, ";
                            break;

                        case 'k':
                            sequence += "thick crust pizza";
                            if (n > 1)
                            {
                                sequence += "s";
                            }
                            break;

                        case 'n':
                            sequence += "thin crust pizza";
                            if (n > 1)
                            {
                                sequence += "s";
                            }
                            break;
                        }

                        j++;
                    }

                    ///PRINT AMOUNT AND ORDER IN READABLE FORMAT
                    Console.WriteLine(Convert.ToInt32(nums) + " " + sequence);
                } while (j < OT[i].Preset.Length);

                ///CUSTOM TRANSLATION TO HUMAN-READABLE FORMAT
                j = 0; n = 0;
                do
                {
                    ///RESET TRANSLATED SEQUENCE AFTER EACH PRINT
                    nums     = "";
                    sequence = "";

                    if ((OT[i].Custom.Length > 0 && OT[i].Custom[0] == '-') || OT[i].Custom.Length == 0)
                    {
                        break;
                    }

                    ///GET FULL DIGIT FROM ORIGINAL SEQUENCE UNTIL ISLETTER - Worst O(3)
                    while (j < OT[i].Custom.Length && Char.IsDigit(OT[i].Custom[j]))
                    {
                        nums += OT[i].Custom[j];
                        j++;
                    }

                    if (!int.TryParse(nums, out n))
                    {
                        break;
                    }

                    ///GET FULL CHAR SEQUENCE FROM ORIGINAL UNTIL NEXT DIGIT/END - Worst O(2)
                    while (j < OT[i].Custom.Length && Char.IsLetter(OT[i].Custom[j]))
                    {
                        switch (OT[i].Custom[j])
                        {
                        case 'S':
                            sequence += "Small Custom, ";
                            break;

                        case 'M':
                            sequence += "Medium Custom, ";
                            break;

                        case 'L':
                            sequence += "Large Custom, ";
                            break;

                        case 'k':
                            sequence += "thick crust pizza";
                            if (n > 1)
                            {
                                sequence += "s";
                            }
                            break;

                        case 'n':
                            sequence += "thin crust pizza";
                            if (n > 1)
                            {
                                sequence += "s";
                            }
                            break;
                        }

                        j++;
                    }

                    ///PRINT AMOUNT AND ORDER IN READABLE FORMAT
                    Console.WriteLine(Convert.ToInt32(nums) + " " + sequence);
                } while (j < OT[i].Custom.Length);

                Console.WriteLine();
                i++;
            }
            #endregion
        }
예제 #12
0
        public void Order()
        {
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            Orders               MyOrder  = new Orders();
            Ordertype            ODetails = new Ordertype();
            Order_tracker        Tracker;
            List <Order_tracker> Q = new List <Order_tracker>();

            MyOrder.Username = CurrentUser.Username;

            decimal total_cost = 0.00m;
            int     pizzas     = 0;
            int     preset_amt = 0;
            int     custom_amt = 0;

            string p_sequence = "";           //save sequence (holds full order for preset)
            string c_sequence = "";           //save sequence (holds full order for custom)

            //USER INPUT DESIRED LOCATION
            int count = 0;

            trials = 3;
            do
            {
                count = Locations();
                Console.Write("Pick a location (Enter ID Here): ");
                var locationid = Console.ReadLine();
                Console.Clear();
                if (int.TryParse(locationid, out int id))
                {
                    if (id < 1 || id > count)
                    {
                        if (trials > 1)
                        {
                            Console.WriteLine("Please enter a digit according to store IDs displayed below:");
                        }
                    }
                    else
                    {
                        MyOrder.StoreId = id;
                        break;
                    }
                }
                else
                {
                    if (trials > 1)
                    {
                        Console.WriteLine("Please enter a digit according to store IDs displayed below:");
                    }
                }

                trials--;
            } while (trials > 0);
            if (trials < 1)
            {
                Console.WriteLine("Sorry, we tend to think inside the box.\nYou can always contact us directly at 7499274992 (PIZZAPIZZA).\n");
                Exit();
                return;
            }

            var result = pizzaboxRepository.GetStoreById(MyOrder.StoreId);
            //var results = from s in DB.Store where s.StoreId == MyOrder.StoreId select s;
            string answer;
            bool   another, shown, ispreset, iscustom, error;

            do
            {
                answer   = "";
                shown    = false;
                error    = false;
                ispreset = false;
                iscustom = false;
                another  = false;

                Tracker.preset       = false;
                Tracker.preset_order = "";
                Tracker.size         = "";
                Tracker.sauce        = "";
                Tracker.crust        = "";
                Tracker.cheese       = "";
                Tracker.amt          = 0;
                Tracker.toppings     = new string[toppings_arraylen];
                Tracker.cost         = 0.00m;
                for (int i = 0; i < Tracker.toppings.Length; i++)
                {
                    Tracker.toppings[i] = "";
                }

                //PRESET OR CUSTOM
                Console.WriteLine("You are ordering from the " + result.City + " store.\n");

                trials = 3;
                do
                {
                    Console.WriteLine("Would you like a Preset or Custom pizza?");
                    if (!shown)
                    {
                        Console.WriteLine();
                        Console.WriteLine("For menu, just enter \"menu\" at any time.");
                        Console.WriteLine("For additional information, just enter \"info\" or \"help\".");
                        shown = true;
                    }

                    Console.Write("Order (style): ");
                    answer = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine("You are ordering from the " + result.City + " store.\n");
                    switch (answer.ToLower())
                    {
                    case "menu":
                    case "\"menu\"":
                    case "m":
                        Console.WriteLine("MENU");
                        Menu();
                        break;

                    case "info":
                    case "help":
                    case "\"info\"":
                    case "\"help\"":
                    case "i":
                    case "h":
                        Console.WriteLine("Sure thing...");
                        Console.WriteLine("Our pizzas come in two styles:");
                        Console.WriteLine("1. Preset - Pre-built specialty pizzas designed by our chef");
                        Console.WriteLine("2. Custom - Be a boss and choose your own toppings\n");
                        break;

                    case "preset":
                    case "1. preset":
                    case "1":
                    case "p":
                        ispreset       = true;
                        Tracker.preset = true;
                        break;

                    case "custom":
                    case "2. custom":
                    case "2":
                    case "c":
                        iscustom = true;
                        break;

                    default:
                        CLError(answer);
                        break;
                    }

                    // now that Tracker.preset, these are unnecessary variables (deal with it later)!!!
                    if (ispreset || iscustom)
                    {
                        break;
                    }
                } while (trials > 0);
                if (trials < 1)
                {
                    return;
                }

                //AMOUNT PRESET/CUSTOM
                trials = 3;
                do
                {
                    Console.WriteLine("How many would you like?");
                    Console.Write("Order (enter digit): ");
                    answer = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine("You are ordering from the " + result.City + " store.\n");
                    if (int.TryParse(answer, out int number))
                    {
                        if (number < 1)
                        {
                            //computecost(); make this a method and return out!!!
                            //or make a jump (take the leap)
                            ComputeOrder(Tracker, Q, total_cost);
                            //add order to db!!!
                            return;
                        }
                        pizzas += number;
                        if (pizzas > 100)
                        {
                            pizzas -= number;

                            if (trials > 1)
                            {
                                Console.Write("Orders limited to 100 pizzas at a time: ");
                                if (100 - pizzas > 0)
                                {
                                    Console.WriteLine(100 - pizzas + " remaining");
                                }

                                error = true;
                            }
                            else
                            {
                                Console.WriteLine("Sorry, we tend to think inside the box.\nYou can always contact us directly at 7499274992 (PIZZAPIZZA).\n");
                                Exit();
                                return;
                            }
                        }
                        else if (ispreset)
                        {
                            preset_amt += number;
                            p_sequence += answer;
                        }
                        else
                        {
                            custom_amt += number;
                            c_sequence += answer;
                        }

                        if (!error)
                        {
                            Tracker.amt = number;
                            break;
                        }
                    }
                    else
                    {
                        if (trials > 1)
                        {
                            Console.WriteLine("Please enter a digit amount.");
                        }
                        else
                        {
                            CLError(answer);
                            return;
                        }
                    }

                    trials--;
                } while (trials > 0);

                //PRESET ORDER SPECIFIC
                if (ispreset)
                {
                    //PRESET NAME
                    trials = 3;
                    do
                    {
                        Console.WriteLine("Please choose from the menu below:");
                        Console.WriteLine("Preset");
                        Console.WriteLine("1. Vegan | Small $4 | Medium $8 | Large $12");
                        Console.WriteLine("2. Pepperoni | Small $5 | Medium $10 | Large $15");
                        Console.WriteLine("3. BBQ Chicken | Small $6 | Medium $12 | Large $18");
                        Console.WriteLine("4. Meatball | Small $7 | Medium $14 | Large $21");
                        Console.WriteLine("5. Supreme | Small $8 | Medium $16 | Large $24");
                        Console.WriteLine("6. Greek | Small $9 | Medium $18 | Large $27\n");

                        Console.Write("Order (enter digit): ");
                        answer = Console.ReadLine();
                        Console.Clear();
                        Console.WriteLine("You are ordering from the " + result.City + " store.\n");
                        switch (answer.ToLower())
                        {
                        case "1":
                        case "vegan":
                            Tracker.preset_order = "VEGAN";
                            break;

                        case "2":
                        case "pepperoni":
                            Tracker.preset_order = "PEPPERONI";
                            break;

                        case "3":
                        case "bbq":
                        case "chicken":
                        case "bbq chicken":
                            Tracker.preset_order = "BBQ CHICKEN";
                            break;

                        case "4":
                        case "meatball":
                        case "meat":
                            Tracker.preset_order = "MEATBALL";
                            break;

                        case "5":
                        case "supreme":
                            Tracker.preset_order = "SUPREME";
                            break;

                        case "6":
                        case "greek":
                            Tracker.preset_order = "GREEK";
                            break;

                        default:
                            CLError(answer);
                            break;
                        }

                        if (Tracker.preset_order.Length > 0)
                        {
                            break;
                        }
                    } while (trials > 0);
                    if (trials < 1)
                    {
                        return;
                    }
                }

                //SIZE
                trials = 3;
                do
                {
                    Console.WriteLine("Would you like that in a Small, Medium, or Large?");
                    Console.Write("Order (size): ");
                    answer = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine("You are ordering from the " + result.City + " store.\n");
                    switch (answer.ToLower())
                    {
                    case "s":
                    case "sm":
                    case "small":
                        if (ispreset)
                        {
                            p_sequence += "S";
                        }
                        else
                        {
                            c_sequence   += "S";
                            Tracker.cost += Tracker.amt * 3.00m;
                        }

                        Tracker.size = "SMALL";
                        break;

                    case "m":
                    case "md":
                    case "medium":
                        if (ispreset)
                        {
                            p_sequence += "M";
                        }
                        else
                        {
                            c_sequence   += "M";
                            Tracker.cost += Tracker.amt * 6.00m;
                        }

                        Tracker.size = "MEDIUM";
                        break;

                    case "l":
                    case "lg":
                    case "large":
                        if (ispreset)
                        {
                            p_sequence += "L";
                        }
                        else
                        {
                            c_sequence   += "L";
                            Tracker.cost += Tracker.amt * 9.00m;
                        }

                        Tracker.size = "LARGE";
                        break;

                    default:
                        CLError(answer);
                        break;
                    }

                    if (Tracker.size.Length > 0)
                    {
                        break;
                    }
                } while (trials > 0);
                if (trials < 1)
                {
                    return;
                }

                //IF PRESET, GO AHEAD AND CALCULATE COST
                if (Tracker.preset)
                {
                    switch (Tracker.preset_order)
                    {
                    case "VEGAN":
                        //put the entire switch statement in a method and take in as parameter decimal starting val (V:4.00, P:5.00, etc) and Tracker.size
                        //then just call the method in each case with different arguments
                        switch (Tracker.size)
                        {
                        case "SMALL":
                            Tracker.cost = Tracker.amt * 4.00m;
                            break;

                        case "MEDIUM":
                            Tracker.cost = Tracker.amt * 8.00m;
                            break;

                        case "LARGE":
                            Tracker.cost = Tracker.amt * 12.00m;
                            break;
                        }
                        break;

                    case "PEPPERONI":
                        switch (Tracker.size)
                        {
                        case "SMALL":
                            Tracker.cost = Tracker.amt * 5.00m;
                            break;

                        case "MEDIUM":
                            Tracker.cost = Tracker.amt * 10.00m;
                            break;

                        case "LARGE":
                            Tracker.cost = Tracker.amt * 15.00m;
                            break;
                        }
                        break;

                    case "BBQ CHICKEN":
                        switch (Tracker.size)
                        {
                        case "SMALL":
                            Tracker.cost = Tracker.amt * 6.00m;
                            break;

                        case "MEDIUM":
                            Tracker.cost = Tracker.amt * 12.00m;
                            break;

                        case "LARGE":
                            Tracker.cost = Tracker.amt * 18.00m;
                            break;
                        }
                        break;

                    case "MEATBALL":
                        switch (Tracker.size)
                        {
                        case "SMALL":
                            Tracker.cost = Tracker.amt * 7.00m;
                            break;

                        case "MEDIUM":
                            Tracker.cost = Tracker.amt * 14.00m;
                            break;

                        case "LARGE":
                            Tracker.cost = Tracker.amt * 21.00m;
                            break;
                        }
                        break;

                    case "SUPREME":
                        switch (Tracker.size)
                        {
                        case "SMALL":
                            Tracker.cost = Tracker.amt * 8.00m;
                            break;

                        case "MEDIUM":
                            Tracker.cost = Tracker.amt * 16.00m;
                            break;

                        case "LARGE":
                            Tracker.cost = Tracker.amt * 24.00m;
                            break;
                        }
                        break;

                    case "GREEK":
                        switch (Tracker.size)
                        {
                        case "SMALL":
                            Tracker.cost = Tracker.amt * 9.00m;
                            break;

                        case "MEDIUM":
                            Tracker.cost = Tracker.amt * 18.00m;
                            break;

                        case "LARGE":
                            Tracker.cost = Tracker.amt * 27.00m;
                            break;
                        }
                        break;
                    }
                }

                //CRUST
                trials = 3;
                do
                {
                    Console.WriteLine("Crust Thick or Thin?");
                    Console.Write("Order (crust): ");
                    answer = Console.ReadLine();
                    Console.Clear();
                    Console.WriteLine("You are ordering from the " + result.City + " store.\n");
                    switch (answer.ToLower())
                    {
                    case "1":
                    case "thick":
                    case "thick crust":
                        if (ispreset)
                        {
                            p_sequence += "k";
                        }
                        else
                        {
                            c_sequence += "k";
                        }

                        Tracker.crust = "THICK";
                        break;

                    case "2":
                    case "thin":
                    case "thin crust":
                        if (ispreset)
                        {
                            p_sequence += "n";
                        }
                        else
                        {
                            c_sequence += "n";
                        }

                        Tracker.crust = "THIN";
                        break;

                    default:
                        CLError(answer);
                        break;
                    }

                    if (Tracker.crust.Length > 0)
                    {
                        break;
                    }
                } while (trials > 0);
                if (trials < 1)
                {
                    return;
                }

                //CUSTOM ORDER SPECIFIC
                if (iscustom)
                {
                    //SAUCE
                    trials = 3;
                    do
                    {
                        Console.WriteLine("Choose a sauce:");
                        Console.WriteLine("1. Traditional $0.50");
                        Console.WriteLine("2. BBQ $1");
                        Console.WriteLine("3. Alfredo $1\n");

                        Console.Write("Order (enter digit): ");
                        answer = Console.ReadLine();
                        Console.Clear();
                        Console.WriteLine("You are ordering from the " + result.City + " store.\n");
                        switch (answer.ToLower())
                        {
                        case "1":
                        case "traditional":
                        case "trad":
                            Tracker.sauce = "TRADITIONAL";
                            Tracker.cost += Tracker.amt * 0.50m;
                            break;

                        case "2":
                        case "bbq":
                        case "barbeque":
                            Tracker.sauce = "BBQ";
                            Tracker.cost += Tracker.amt * 1.00m;
                            break;

                        case "3":
                        case "alfredo":
                        case "fredo":
                            Tracker.sauce = "ALFREDO";
                            Tracker.cost += Tracker.amt * 1.00m;
                            break;

                        default:
                            CLError(answer);
                            break;
                        }

                        if (Tracker.sauce.Length > 0)
                        {
                            break;
                        }
                    } while (trials > 0);
                    if (trials < 1)
                    {
                        return;
                    }

                    //CHEESE
                    trials = 3;
                    do
                    {
                        Console.WriteLine("Pick a cheese:");
                        Console.WriteLine("0. None");
                        Console.WriteLine("1. Regular $0.50");
                        Console.WriteLine("2. Goat (Greek) $1");
                        Console.WriteLine("3. Queso $2\n");

                        Console.Write("Order (enter digit): ");
                        answer = Console.ReadLine();
                        Console.Clear();
                        Console.WriteLine("You are ordering from the " + result.City + " store.\n");
                        switch (answer.ToLower())
                        {
                        case "":
                        case "0":
                        case "none":
                        case "no":
                        case "no cheese":
                        case "no thanks":
                        case "no thankyou":
                        case "no thank you":
                            Tracker.cheese = "NONE";
                            break;

                        case "1":
                        case "regular":
                        case "reg":
                            Tracker.cheese = "REGULAR";
                            Tracker.cost  += Tracker.amt * 0.50m;
                            break;

                        case "2":
                        case "goat":
                        case "greek":
                        case "goat (greek)":
                        case "goat greek":
                        case "greek goat":
                            Tracker.cheese = "GOAT";
                            Tracker.cost  += Tracker.amt * 1.00m;
                            break;

                        case "3":
                        case "queso":
                        case "queso fresco":
                        case "fresco":
                            Tracker.cheese = "QUESO";
                            Tracker.cost  += Tracker.amt * 2.00m;
                            break;

                        default:
                            CLError(answer);
                            break;
                        }

                        if (Tracker.cheese.Length > 0)
                        {
                            break;
                        }
                    } while (trials > 0);
                    if (trials < 1)
                    {
                        return;
                    }

                    //TOPPINGS
                    trials = 3;
                    do
                    {
                        Console.WriteLine("Pick your toppings.");
                        Console.WriteLine("For multiple toppings, simply enter a stream of digits up to four.");
                        Console.WriteLine("For any less, you will need to press enter twice:");
                        Console.WriteLine("0. None");
                        Console.WriteLine("1. Veggies/Fruit $0.50");
                        Console.WriteLine("2. Pepperoni $1");
                        Console.WriteLine("3. Chicken $1");
                        Console.WriteLine("4. Meatballs $3\n");

                        Console.Write("Order (enter digit/s): ");
                        answer = Console.ReadLine();
                        Console.Clear();
                        Console.WriteLine("You are ordering from the " + result.City + " store.\n");

                        if (answer.Length == 0 || answer[0] == '0')
                        {
                            break;
                        }

                        int i = 0;
                        while ((i < answer.Length) && (i < toppings_arraylen))
                        {
                            if (Char.IsDigit(answer[i]))
                            {
                                switch (answer[i])
                                {
                                case '1':
                                    Tracker.toppings[i] = "VEGGIES/FRUIT";
                                    Tracker.cost       += Tracker.amt * 0.50m;
                                    break;

                                case '2':
                                    Tracker.toppings[i] = "PEPPERONI";
                                    Tracker.cost       += Tracker.amt * 1.00m;
                                    break;

                                case '3':
                                    Tracker.toppings[i] = "CHICKEN";
                                    Tracker.cost       += Tracker.amt * 1.00m;
                                    break;

                                case '4':
                                    Tracker.toppings[i] = "MEATBALLS";
                                    Tracker.cost       += Tracker.amt * 3.00m;
                                    break;

                                default:
                                    CLError(answer);
                                    break;
                                }

                                if (Tracker.toppings[i].Length == 0)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                CLError(answer);
                                break;
                            }

                            i++;
                        }

                        if (Tracker.toppings[toppings_arraylen - 1].Length > 0)
                        {
                            break;
                        }
                    } while (trials > 0);
                    if (trials < 1)
                    {
                        return;
                    }
                }

                if (pizzas < 100)
                {
                    //CALCULATE CURRENT COST & SAVE STATE OF VARS for PRINTOUT
                    Console.WriteLine("Should I mark this order as complete?");
                    Console.Write("Enter Y/N: ");
                    answer = Console.ReadLine();
                    Console.Clear();
                    switch (answer.ToLower())
                    {
                    case "n":
                    case "no":
                    case "not yet":
                    case "nope":
                        Console.WriteLine("Wow, this must be some good pizza!");
                        another = true;
                        break;

                    case "y":
                    case "yes":
                    case "sure":
                    case "ok":
                    case "k":
                    case "okay":
                    case "alright":
                        break;

                    default:
                        Console.Write("I'll take that as a yes. One moment please ");
                        Loading('.', 3, 2);
                        break;
                    }
                }

                total_cost += Tracker.cost;
                Q.Add(Tracker);

                if (total_cost > 250.00m)
                {
                    Console.Clear();
                    trials = 3;
                    do
                    {
                        Console.WriteLine("Orders can not exceed $250.");
                        Console.WriteLine("Choose which items you would like to remove:\n");

                        for (int i = 0; i < Q.Count; i++)
                        {
                            if (Q[i].preset)
                            {
                                Console.WriteLine(i + 1 + ": (" + Q[i].amt + ") " + Q[i].size + ", " + Q[i].crust + " " + Q[i].preset_order);
                            }
                            else
                            {
                                Console.WriteLine(i + 1 + ": (" + Q[i].amt + ") " + Q[i].size + ", " + Q[i].crust + " " + Q[i].cheese + " on " + Q[i].sauce);
                                Console.Write("Toppings: ");
                                for (int j = 0; j < Q[i].toppings.Length; j++)
                                {
                                    Console.Write(Q[i].toppings[j]);

                                    if (j < Q[i].toppings.Length - 1)
                                    {
                                        Console.Write(", ");
                                    }
                                }
                                Console.WriteLine();
                            }
                            Console.WriteLine("$" + Tracker.cost + "\n");
                        }

                        Console.WriteLine("Total: $" + total_cost);
                        Console.Write("Remove (Enter Digit): ");
                        answer = Console.ReadLine();
                        Console.Clear();
                        if (int.TryParse(answer, out int num) && num > 0 && num <= Q.Count)
                        {
                            total_cost -= Q[num - 1].cost;
                            Q.RemoveAt(num - 1);
                        }
                        else
                        {
                            if (trials > 1)
                            {
                                Console.WriteLine("Please enter a valid digit according to the list below:");
                            }
                            else
                            {
                                Console.WriteLine("Sorry, we tend to think inside the box.\nYou can always contact us directly at 7499274992 (PIZZAPIZZA).\n");
                                Exit();
                                return;
                            }

                            trials--;
                        }
                    } while (total_cost > 250.00m);

                    if (total_cost == 0.00m)
                    {
                        another = true;
                    }
                }
            } while (another);

            if (promo)
            {
                sales_price = total_cost * 0.50m;     //try not to hardcode this for next update (KeyValues<discounts,bools>)
            }
            //PRINT EACH FROM THE QUEUE
            ComputeOrder(Tracker, Q, total_cost);

            if (p_sequence.Length < 1)
            {
                p_sequence = "-";
            }
            else if (c_sequence.Length < 1)
            {
                c_sequence = "-";
            }

            //STORE IN DB
            pizzaboxRepository.AddOrder(MyOrder, ODetails, p_sequence, c_sequence);
            pizzaboxRepository.UpdateInventory(MyOrder.StoreId, preset_amt, custom_amt, "subtract");
        }
예제 #13
0
        public override void History()
        {
            using IPizzaboxRepository pizzaboxRepository = DbOptions.CreatePizzaboxRepository();
            var results = pizzaboxRepository.GetOrdersBy(CurrentUser.Username, "user");

            if (results.Count() < 1)
            {
                Console.WriteLine("You have not ordered anything yet.\n");
                return;
            }

            Orders[]    O   = new Orders[results.Count()];
            Ordertype[] OT  = new Ordertype[results.Count()];
            int[]       ids = new int[results.Count()];

            #region Initialization of O, OT, and ids
            int i;
            for (i = 0; i < results.Count(); i++)
            {
                O[i] = new Orders()
                {
                    OrderId  = 0,
                    StoreId  = 0,
                    Username = ""
                };
                OT[i] = new Ordertype()
                {
                    OrderId = 0,
                    Preset  = "",
                    Custom  = "",
                    Dt      = "",
                    Tm      = ""
                };
                ids[i] = new int();
            }
            #endregion

            #region Map Orders results
            i = 0;
            foreach (var val in results)
            {
                O[i]   = val;
                ids[i] = val.OrderId;

                #region NOTE:
                ///NOTE: DataReader can not use result from Entity1 query while querying data in Entity2
                #endregion
                i++;
            }

            for (i = 0; i < results.Count(); i++)
            {
                OT[i] = pizzaboxRepository.GetOrdertypeById(ids[i]);

                #region OT[i] can be assumed != null as long as developers don't mess with it.  Make sure they can't

                /*
                 * if (OT[i] == null)
                 * {
                 *  //handle it
                 * }
                 */
                #endregion
            }
            #endregion

            #region Display Full List of Recent Orders
            i = 0;
            while (i < results.Count())
            {
                int    j = 0, n = 0;
                string nums, sequence;

                ///DISPLAY ORDER# AND DATE/TIME
                Console.WriteLine("Order #" + O[i].OrderId.ToString().PadLeft(12 - O[i].OrderId.ToString().Length, '0'));
                string D = OT[i].Dt.Replace('.', '/');
                string T = OT[i].Tm.Replace('.', ':');
                Console.WriteLine(D + " " + T);

                ///PRESET TRANSLATION TO HUMAN-READABLE FORMAT
                do
                {
                    ///RESET TRANSLATED SEQUENCE AFTER EACH PRINT
                    nums     = "";
                    sequence = "";

                    if ((OT[i].Preset.Length > 0 && OT[i].Preset[0] == '-') || OT[i].Preset.Length == 0)
                    {
                        break;
                    }

                    ///GET FULL DIGIT FROM ORIGINAL SEQUENCE UNTIL ISLETTER - Worst O(3)
                    while (j < OT[i].Preset.Length && Char.IsDigit(OT[i].Preset[j]))
                    {
                        nums += OT[i].Preset[j];
                        j++;
                    }

                    //NUMS IS NOT A NUMBER? SKIP
                    if (!int.TryParse(nums, out n))
                    {
                        break;
                    }

                    ///GET FULL CHAR SEQUENCE FROM ORIGINAL UNTIL NEXT DIGIT/END - Worst O(2)
                    while (j < OT[i].Preset.Length && Char.IsLetter(OT[i].Preset[j]))
                    {
                        switch (OT[i].Preset[j])
                        {
                        case 'S':
                            sequence += "Small Preset, ";
                            break;

                        case 'M':
                            sequence += "Medium Preset, ";
                            break;

                        case 'L':
                            sequence += "Large Preset, ";
                            break;

                        case 'k':
                            sequence += "thick crust pizza";
                            if (n > 1)
                            {
                                sequence += "s";
                            }
                            break;

                        case 'n':
                            sequence += "thin crust pizza";
                            if (n > 1)
                            {
                                sequence += "s";
                            }
                            break;
                        }

                        j++;
                    }

                    ///PRINT AMOUNT AND ORDER IN READABLE FORMAT
                    Console.WriteLine(Convert.ToInt32(nums) + " " + sequence);
                } while (j < OT[i].Preset.Length);

                ///CUSTOM TRANSLATION TO HUMAN-READABLE FORMAT
                j = 0; n = 0;
                do
                {
                    ///RESET TRANSLATED SEQUENCE AFTER EACH PRINT
                    nums     = "";
                    sequence = "";

                    if ((OT[i].Custom.Length > 0 && OT[i].Custom[0] == '-') || OT[i].Custom.Length == 0)
                    {
                        break;
                    }

                    ///GET FULL DIGIT FROM ORIGINAL SEQUENCE UNTIL ISLETTER - Worst O(3)
                    while (j < OT[i].Custom.Length && Char.IsDigit(OT[i].Custom[j]))
                    {
                        nums += OT[i].Custom[j];
                        j++;
                    }

                    if (!int.TryParse(nums, out n))
                    {
                        break;
                    }

                    ///GET FULL CHAR SEQUENCE FROM ORIGINAL UNTIL NEXT DIGIT/END - Worst O(2)
                    while (j < OT[i].Custom.Length && Char.IsLetter(OT[i].Custom[j]))
                    {
                        switch (OT[i].Custom[j])
                        {
                        case 'S':
                            sequence += "Small Custom, ";
                            break;

                        case 'M':
                            sequence += "Medium Custom, ";
                            break;

                        case 'L':
                            sequence += "Large Custom, ";
                            break;

                        case 'k':
                            sequence += "thick crust pizza";
                            if (n > 1)
                            {
                                sequence += "s";
                            }
                            break;

                        case 'n':
                            sequence += "thin crust pizza";
                            if (n > 1)
                            {
                                sequence += "s";
                            }
                            break;
                        }

                        j++;
                    }

                    ///PRINT AMOUNT AND ORDER IN READABLE FORMAT
                    Console.WriteLine(Convert.ToInt32(nums) + " " + sequence);
                } while (j < OT[i].Custom.Length);

                Console.WriteLine();
                i++;
            }
            #endregion
        }