public void ProcessPayment() { IMessage view = new MessageView(); //Calculate Subtotal, tax and total myOrder.Subtotal = 0; foreach (Product p in myOrder.PurchaseList) { myOrder.Subtotal += p.Price * p.Qty; } myOrder.Tax = myOrder.Subtotal * Tax.tax; myOrder.Total = myOrder.Subtotal + myOrder.Tax; //Display the information IView paymentView = new PaymentView(myOrder); paymentView.Display(); //ask how they want to pay int input; do { view.Display("Input payment type: "); input = UserInput.GetUserInputAsInteger(""); } while (!IsItemInProductList(input, 0, 3)); switch (input) { case 1: //Cash - Get amount tendered and calculate change myOrder.PayInfo.PayType = POSTerminal.PayType.Cash; do { view.Display($"{myOrder.PayInfo.AmountTenderedMessage}"); myOrder.PayInfo.AmountTendered += UserInput.GetUserInputAsDouble(""); myOrder.PayInfo.Change = myOrder.PayInfo.AmountTendered - myOrder.Total; } while (myOrder.PayInfo.AmountTendered < myOrder.Total); view.Display($"{myOrder.PayInfo.ChangeMessage} {myOrder.PayInfo.Change:C2}"); break; case 2: //Credit - ask for number, expiration and cvv string cancel = string.Empty; do { cancel = string.Empty; myOrder.PayInfo.PayType = POSTerminal.PayType.Credit; view.Display(myOrder.PayInfo.CreditCardNumberMessage); myOrder.PayInfo.CardNumber = UserInput.GetCreditCardNumber().Replace(" ", ""); view.Display(myOrder.PayInfo.ExpirationDateMessage); myOrder.PayInfo.ExpirationDate = UserInput.GetCreditCardExpiration(); if ((myOrder.PayInfo.ExpirationDate.Year == DateTime.Now.Year && myOrder.PayInfo.ExpirationDate.Month < DateTime.Now.Month) || myOrder.PayInfo.ExpirationDate.Year < DateTime.Now.Year) { view.Display("This credit card has expired."); view.Display("Enter r to re-enter the credit card information, enter c to cancel the order: "); cancel = UserInput.GetUserInput(""); if (cancel.ToLower() != "r") { return; } } } while (cancel.ToLower() == "r"); view.Display(myOrder.PayInfo.CvvMessage); myOrder.PayInfo.Cvv = UserInput.GetCreditCardCVV(); view.Display("Enter cash back (press enter or input 0 to skip): "); myOrder.PayInfo.CashBack = UserInput.GetCashBack(); myOrder.PayInfo.AmountTendered = myOrder.Total + myOrder.PayInfo.CashBack; if (myOrder.PayInfo.CashBack != 0) { view.Display($"{myOrder.PayInfo.CashBackMessage} {myOrder.PayInfo.CashBack}"); } break; case 3: //Check - ask for check number myOrder.PayInfo.PayType = POSTerminal.PayType.Check; view.Display(myOrder.PayInfo.CheckNumberMessage); myOrder.PayInfo.CheckNumber = UserInput.GetCheckNumber().Replace(" ", ""); myOrder.PayInfo.AmountTendered = myOrder.Total; break; default: Console.WriteLine("Invalid Selection"); break; } ReceiptView receiptView = new ReceiptView(myOrder); FileIO.WriteToOrderFile(myOrder); receiptView.Display(); }
public void AddToProductFile() { Product newProduct = new Product(); IView addProductView = new AddProductView(productList); IMessage view = new MessageView(); addProductView.Display(); view.Display("\nPlease enter EXIT at any time to quit.\n"); view.Display("Enter new product name: "); string input = UserInput.GetUserInput(""); if (input.ToLower() == "exit") { return; } newProduct.Name = input; view.Display("Enter new product category: "); input = UserInput.GetUserInput(""); if (input.ToLower() == "exit") { return; } newProduct.Category = input; bool checkPrice = false; while (!checkPrice) { view.Display("Enter new product price: "); input = UserInput.GetUserInput(""); if (input.ToLower() == "exit") { return; } if (double.TryParse(input, out double newPrice)) { newProduct.Price = newPrice; checkPrice = true; } } view.Display("Enter new product description: "); input = UserInput.GetUserInput(""); if (input.ToLower() == "exit") { return; } newProduct.Description = input; while (input.ToLower() != "y" && input.ToLower() != "n") { view.Display($"\nName: {newProduct.Name}\nCategory: {newProduct.Category}\nPrice: {newProduct.Price}\nDescription: {newProduct.Description}"); view.Display("\nEnter this product into the database? (y/n): "); input = UserInput.GetUserInput(""); } bool alreadyExists = false; if (input.ToLower() == "y") { foreach (Product p in productList) { if (p.Name.ToLower() == newProduct.Name.ToLower()) { view.Display("A product with this name already exists!\n"); view.Display("This new product will not be added to the database!"); Console.ReadKey(); alreadyExists = true; } } if (!alreadyExists) { FileIO.WriteToProductFile(newProduct); Console.WriteLine("Wrote to File!"); Console.ReadKey(); } } else { view.Display("The new product was not added to the database."); } }
public void AddProductToCart() { ProductListView productListView = new ProductListView(productList); IMessage view = new MessageView(); int quantity = 0; view.Display("1: Search By Name\n2: Search By Category\n3: List All Products\n4: Go Back\n\nMake a selection: "); bool goBack = false; while (!goBack) { int input = UserInput.GetUserInputAsInteger(""); switch (input) { case 1: goBack = true; ProductListView filteredList; do { view.Display("Enter product name: "); string name = UserInput.GetUserInput(""); filteredList = new ProductListView(productListView.GetFilteredList("name", name)); }while (filteredList.ProductList.Count < 1); filteredList.Display(); do { view.Display(string.Format("\nChoose a product (1-{0}): ", filteredList.ProductList.Count)); input = UserInput.GetUserInputAsIntegerOrReturnOne(""); } while (!IsItemInProductList(input, 0, filteredList.ProductList.Count)); input--; view.Display("Enter Quantity: "); quantity = UserInput.GetUserInputAsIntegerOrReturnOne(""); if (myOrder.PurchaseList.Contains(filteredList.ProductList[input])) { myOrder.PurchaseList.Find(x => x.Name == filteredList.ProductList[input].Name).Qty += quantity; } else { filteredList.ProductList[input].Qty += quantity; myOrder.PurchaseList.Add(filteredList.ProductList[input]); } break; case 2: goBack = true; string category; bool proceed = false; do { view.Display("Enter product category (food/beverage): "); category = UserInput.GetUserInput("").ToLower(); switch (category) { case "food": proceed = true; break; case "beverage": proceed = true; break; default: proceed = false; break; } } while (!proceed); ProductListView filteredListByCat = new ProductListView(productListView.GetFilteredList("category", category)); filteredListByCat.Display(); do { view.Display(string.Format("\nChoose a product (1-{0})", filteredListByCat.ProductList.Count)); input = UserInput.GetUserInputAsInteger(""); } while (!IsItemInProductList(input, 0, filteredListByCat.ProductList.Count)); input--; view.Display("Enter Quantity: "); quantity = UserInput.GetUserInputAsIntegerOrReturnOne(""); if (myOrder.PurchaseList.Contains(filteredListByCat.ProductList[input])) { myOrder.PurchaseList.Find(x => x.Name == filteredListByCat.ProductList[input].Name).Qty += quantity; } else { myOrder.PurchaseList.Add(filteredListByCat.ProductList[input]); myOrder.PurchaseList.Find(x => x.Name == filteredListByCat.ProductList[input].Name).Qty += quantity; } break; case 3: goBack = true; productListView.Display(); do { view.Display(string.Format("\nChoose a product (1-{0})", productList.Count)); input = UserInput.GetUserInputAsInteger(""); }while (!IsItemInProductList(input, 0, productList.Count)); input--; view.Display("Enter Quantity: "); quantity = UserInput.GetUserInputAsIntegerOrReturnOne(""); if (myOrder.PurchaseList.Contains(productList[input])) { myOrder.PurchaseList.Find(x => x.Name == productList[input].Name).Qty += quantity; } else { myOrder.PurchaseList.Add(productList[input]); myOrder.PurchaseList.Find(x => x.Name == productList[input].Name).Qty += quantity; } break; case 4: goBack = true; break; default: break; } } }