示例#1
0
        public bool UseCashPayment(RegisterService registerService, List <Product> orderList)
        {
            bool   isAmountValid = false;
            double amountGiven   = 0;

            while (!isAmountValid)
            {
                Console.WriteLine("\nEnter total cash amount: ");
                try
                {
                    amountGiven   = double.Parse(Console.ReadLine());
                    isAmountValid = validator.ValidateAmountGiven(amountGiven, registerService.GrandTotal);
                    if (!isAmountValid)
                    {
                        Console.WriteLine("Invalid cash amount. Don't be cheap!");
                    }
                }
                catch (Exception)
                {
                    isAmountValid = false;
                    Console.WriteLine("Please only input a number.");
                }
            }

            Cash cash = new Cash(amountGiven);

            cash.GetChange(registerService.GrandTotal);
            Console.WriteLine("{0,-30} {1,5}", "Your change is:", cash.Change.ToString("C", CultureInfo.CurrentCulture));
            Console.WriteLine("\nHere is your receipt");
            registerService.PrintCashReceipt(orderList, cash);
            return(true);
        }
示例#2
0
        public bool UseCardPayment(RegisterService registerService, List <Product> orderList)
        {
            bool   isValidCard       = false;
            bool   isValidExpiryDate = false;
            bool   isValidCVV        = false;
            string cardNum           = string.Empty;
            string expDate           = string.Empty;
            var    cvv = string.Empty;

            //Checks to make sure the card number is valid
            while (!isValidCard)
            {
                Console.Write("\nEnter your card number: ");
                cardNum     = Console.ReadLine();
                isValidCard = validator.ValidateCardNumber(cardNum);
                if (!isValidCard)
                {
                    Console.WriteLine("Please enter 16 digits Card Number");
                }
            }
            //checks to make sure the card expiration date is valid
            while (!isValidExpiryDate)
            {
                Console.Write("\nEnter the expiration date(MM/YYYY): ");
                expDate           = Console.ReadLine();
                isValidExpiryDate = validator.ValidateExperationDate(expDate);
                if (!isValidExpiryDate)
                {
                    Console.WriteLine("\nPlease enter a valid date (MM/YYYY)");
                }
            }
            //checks to make sure the cvv number is valid
            while (!isValidCVV)
            {
                Console.Write("\nEnter the CVV number: ");
                cvv        = Console.ReadLine();
                isValidCVV = validator.ValidateCVV(cvv);
                if (!isValidCVV)
                {
                    Console.WriteLine("Please enter a 3 digit CVV number");
                }
            }

            Card card = new Card(cardNum, expDate, cvv);

            Console.WriteLine("\nHere is your receipt");
            registerService.PrintCardReceipt(orderList, card);
            return(true);
        }
示例#3
0
        public bool UseCheckPayment(RegisterService registerService, List <Product> orderList)
        {
            var  checkNumber        = string.Empty;
            bool isVaildCheckNumber = false;

            while (!isVaildCheckNumber)
            {
                Console.Write("\nEnter check number: ");
                checkNumber        = Console.ReadLine();
                isVaildCheckNumber = validator.ValidateCheckNumber(checkNumber);
                if (!isVaildCheckNumber)
                {
                    Console.WriteLine("Please enter a 10 digit check number");
                }
            }
            Check check = new Check(checkNumber);

            Console.WriteLine("\nHere is your receipt");
            registerService.PrintCheckReceipt(orderList, check);
            return(true);
        }
示例#4
0
        public List <Product> GetOrderInfo(bool proceed, RegisterService registerService, List <Product> productList, List <Product> orderList)
        {
            do
            {
                Console.WriteLine("");
                registerService.PrintMenu(productList);
                Console.WriteLine("\n\nPlease choose the number of the item you want");
                var productChoiceInput = Console.ReadLine();

                //Checks to make sure you are entering a number
                if (!int.TryParse(productChoiceInput, out var productChoice))
                {
                    Console.Clear();
                    Console.WriteLine("Please enter valid number");
                    continue;
                }
                var product = productList.FirstOrDefault(x => x.ID == productChoice);

                //Checks to make sure you are entering a valid item
                if (product == null)
                {
                    Console.Clear();
                    Console.WriteLine("Please enter valid item from the menu");
                    continue;
                }

                Console.WriteLine("How many would you like to order: ");
                var productQuantityInput = Console.ReadLine();

                //Checks to make sure you are entering a number
                if (!int.TryParse(productQuantityInput, out var productQuantity))
                {
                    Console.Clear();
                    Console.WriteLine("Please enter valid number");
                    continue;
                }

                //Checks to make sure the quantity is greater than 0
                if (productQuantity <= 0)
                {
                    Console.Clear();
                    Console.WriteLine("Please enter quantity greater than zero");
                    continue;
                }
                var lineTotal = registerService.CalculateLineTotal(productQuantity, product.Price);

                Console.WriteLine($"Here is your line total: {lineTotal.ToString("C", CultureInfo.CurrentCulture)}\n");

                for (int i = 1; i <= productQuantity; i++)
                {
                    orderList.Add(product);
                }

                var askForMoreItems = false;
                do
                {
                    Console.WriteLine("Press Y to add more items or N for total");
                    var addMoreItems = Console.ReadLine();
                    if (addMoreItems.ToUpper() == "Y")
                    {
                        askForMoreItems = true;
                        proceed         = false;
                    }
                    else if (addMoreItems.ToUpper() == "N")
                    {
                        askForMoreItems = true;
                        proceed         = true;
                    }
                    else
                    {
                        askForMoreItems = false;
                    }
                } while (askForMoreItems == false);
            } while (proceed == false);

            return(orderList);
        }
示例#5
0
        static void Main(string[] args)
        {
            FileService    fileService    = new FileService();
            PaymentService paymentService = new PaymentService();
            OrderService   orderService   = new OrderService();
            MenuService    menuService    = new MenuService();
            var            productList    = fileService.GetProductList();

            int CASH  = 1;
            int CARD  = 2;
            int CHECK = 3;

            do
            {
                var             orderList       = new List <Product>();
                RegisterService registerService = new RegisterService();
                Console.WriteLine("Welcome to Grand Circus Coffee Shop!!");
                Console.WriteLine("What would you like to do?:");
                Console.WriteLine("   1. Add items to the menu");
                Console.WriteLine("   2. Place an order");
                var userInput = Console.ReadLine();
                if (userInput == "1")
                {
                    var productID  = productList.Count() + 1;
                    var newProduct = menuService.ModifyMenu(productID);
                    fileService.AddProductToProductList(true, newProduct.ID, newProduct.Name, newProduct.Category, newProduct.Description, newProduct.Price, productList);
                    productList = fileService.GetProductList();
                }
                else if (userInput == "2")
                {
                    Console.WriteLine("Menu");
                    bool proceed = false;

                    orderList = orderService.GetOrderInfo(proceed, registerService, productList, orderList);
                    registerService.PrintOrderTotals(orderList);

                    bool paymentProceed = false;
                    do
                    {
                        Console.WriteLine("\n\nPayment Options:");
                        Console.WriteLine("   1. Cash");
                        Console.WriteLine("   2. Credit");
                        Console.WriteLine("   3. Check");
                        Console.Write("\nHow will you be paying? ");
                        var paymentChoiceInput = Console.ReadLine();

                        if (!int.TryParse(paymentChoiceInput, out var paymentChoice))
                        {
                            Console.WriteLine("Please choose a valid payment option");
                            continue;
                        }

                        if (paymentChoice == CASH)
                        {
                            paymentProceed = paymentService.UseCashPayment(registerService, orderList);
                        }
                        else if (paymentChoice == CARD)
                        {
                            paymentProceed = paymentService.UseCardPayment(registerService, orderList);
                        }
                        else if (paymentChoice == CHECK)
                        {
                            paymentProceed = paymentService.UseCheckPayment(registerService, orderList);
                        }
                        else
                        {
                            Console.WriteLine("Please choose a valid payment option");
                            continue;
                        }
                    } while (paymentProceed == false);
                }
                else
                {
                    Console.WriteLine("You did not enter a valid option.");
                }
                Console.WriteLine("\nEnter 'Y' to place a new order/update menu or 'N' to end program");
            } while (UserContinue());
        }