public void getItemsInCart(Customer activeCustomer) { START: Console.Clear(); _consoleHelper.WriteHeaderToConsole("Items in Cart"); char spacePad = ' '; _consoleHelper.WriteLine("Product Qty Unit Price Total "); Console.ForegroundColor = ConsoleColor.DarkCyan; _consoleHelper.WriteLine("*********************************************************"); Console.ForegroundColor = ConsoleColor.White; var cartItems = cartDetail.GetItemsInCart(activeCustomer.CustomerId); foreach (var item in cartItems) { _consoleHelper.WriteLine(item.ProductName.PadRight(23, spacePad).Substring(0, 23) + item.ProductQuantity.ToString().PadRight(8, spacePad).Substring(0, 8) + '$' + item.ProductPrice.ToString().Remove(item.ProductPrice.ToString().Length - 2).PadLeft(7, spacePad).PadRight(13, spacePad).Substring(0, 13) + '$' + item.Total.ToString().Remove(item.ProductPrice.ToString().Length - 2).PadLeft(7, spacePad)); } var cartRepo = new CartRepository(); var activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); if (activeCart == null) { cartRepo.AddCart(activeCustomer.CustomerId); activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); } Console.ForegroundColor = ConsoleColor.DarkCyan; _consoleHelper.WriteLine("*********************************************************"); Console.ForegroundColor = ConsoleColor.White; string cartTotalLine = $"Total: ({cartDetail.GetTotalItemsInCart(activeCart.CartId)}) {cartDetail.GetCartPrice(activeCart.CartId)}"; string space = new string(' ', (56 - cartTotalLine.Length)); _consoleHelper.WriteLine(space + cartTotalLine); string[] menuOptions = new string[] { "Checkout", "Empty Cart" }; int counter = 1; foreach (var option in menuOptions) { _consoleHelper.WriteLine($"{counter}. {option} "); counter++; } _consoleHelper.WriteExitCommand(); var selection = _consoleHelper.WriteAndReadFromConsole("> "); if (!(selection.Equals(""))) { if (_consoleHelper.CheckForUserExit(selection)) { return; } ; if (selection.Equals("1")) { (new CartController()).checkout(activeCustomer); } else if (selection.Equals("2")) { cartRepo.EmptyCart(activeCustomer.CustomerId); _consoleHelper.WriteLine("Cart has been emptied!"); Thread.Sleep(2000); return; } else { _consoleHelper.WriteLine("Invalid option selected"); Thread.Sleep(2000); Console.Clear(); goto START; } } else { _consoleHelper.WriteLine("Invalid option selected"); Thread.Sleep(2000); Console.Clear(); goto START; } }
public void addProduct(Customer activeCustomer) { SHOWPRODUCTS: Console.Clear(); _consoleHelper.WriteHeaderToConsole("Add Products to Cart"); ProductRepository repo = new ProductRepository(); var products = repo.GetAllProducts(); _consoleHelper.WriteLine("Opt Product Price "); Console.ForegroundColor = ConsoleColor.DarkCyan; _consoleHelper.WriteLine("*********************************************************"); Console.ForegroundColor = ConsoleColor.White; char spacePad = ' '; foreach (Product product in products) { StringBuilder productIdString = new StringBuilder(); string productId = productIdString.Append(product.ProductId.ToString()).Append(".").ToString(); _consoleHelper.WriteLine(productId.PadRight(8, spacePad).Substring(0, 4) + product.ProductName.PadRight(22, spacePad).Substring(0, 22) + "$" + product.ProductPrice.ToString().PadLeft(7, spacePad)); } Console.ForegroundColor = ConsoleColor.DarkCyan; _consoleHelper.WriteLine("*********************************************************"); Console.ForegroundColor = ConsoleColor.White; var cartRepo = new CartRepository(); var activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); string cartTotalLine = $"Total: ({cartDetail.GetTotalItemsInCart(activeCart.CartId)}) {cartDetail.GetCartPrice(activeCart.CartId)}"; string space = new string(' ', (56 - cartTotalLine.Length)); _consoleHelper.WriteLine(space + cartTotalLine); _consoleHelper.WriteLine($"{products.Count + 1}" + ". Save Cart and Return to Main Menu"); _consoleHelper.WriteLine($"{products.Count + 2}" + ". Checkout\n"); try { var selectedProduct = Convert.ToInt32(_consoleHelper.WriteAndReadFromConsole("> ")); if (selectedProduct >= 1 && selectedProduct <= products.Count) { var cartDetail = new CartDetailRepository(); cartDetail.AddProduct(activeCart.CartId, selectedProduct, 1); _consoleHelper.WriteLine("One item has been put into your cart."); Thread.Sleep(500); goto SHOWPRODUCTS; } else if (selectedProduct == products.Count + 1) { return; } else if (selectedProduct == products.Count + 2) { checkout(activeCustomer); } else { _consoleHelper.WriteLine("Please choose a valid product number!"); goto SHOWPRODUCTS; } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); _consoleHelper.WriteLine("Please enter the numbers showed on screen!"); Thread.Sleep(1000); goto SHOWPRODUCTS; } }
public void checkout(Customer activeCustomer) { CHOOSEPAYMENT: Console.Clear(); _consoleHelper.WriteHeaderToConsole("Check Out"); var cartRepo = new CartRepository(); var activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); if (activeCart != null) { var cartDetail = new CartDetailRepository(); if (cartDetail.GetTotalItemsInCart(activeCart.CartId) < 1) { _consoleHelper.ErrorMessage("Your cart is empty. Please continue shopping."); (new CartController()).addProduct(activeCustomer); return; } _consoleHelper.Write($"Your order total is {cartDetail.GetCartPrice(activeCart.CartId)}. Ready to purchase?\n"); _consoleHelper.WriteExitCommand(); var userInput = _consoleHelper.WriteAndReadFromConsole("Y/N > "); _consoleHelper.CheckForUserExit(userInput); if (userInput.ToLower() == "y") { Console.Clear(); _consoleHelper.WriteHeaderToConsole("Choose Payment"); // get active customer payment option and show var paymentRepo = new PaymentRepository(); var payments = paymentRepo.GetAllPayments(activeCustomer.CustomerId); if (payments.Count < 1) { var paymentController = new PaymentController(); var payment = paymentController.RequestPayment(activeCustomer); if (payment == null) { return; } ; goto CHOOSEPAYMENT; } _consoleHelper.WriteLine("\nCustomer Payment Options:\n"); int counter = 1; foreach (Payment payment in payments) { _consoleHelper.WriteLine(counter + ". " + payment.PaymentType + " ****-****-****-" + payment.PaymentAccountNumber.ToString().Substring(payment.PaymentAccountNumber.ToString().Length - 4) + "\n"); counter++; } _consoleHelper.WriteExitCommand(); // read userinput var paymentChoice = _consoleHelper.WriteAndReadFromConsole("Choose payment option > "); if (_consoleHelper.CheckForUserExit(paymentChoice)) { return; } ; try { var intPaymentChoice = Convert.ToInt32(paymentChoice); if (intPaymentChoice == counter) { return; } else if (intPaymentChoice > 0 && intPaymentChoice < counter) { var paymentId = payments[intPaymentChoice - 1].PaymentId; // update order active to false cartRepo.EditCartStatus(activeCart.CartId, paymentId); _consoleHelper.WriteLine("\nYour order is complete! Press any key to return to main menu.\n"); _consoleHelper.ReadKey(); return; } else { _consoleHelper.WriteLine("Please enter a valid option."); goto CHOOSEPAYMENT; } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } return; } _consoleHelper.WriteLine("Please add some products to your order first. Press any key to return to main menu.\n"); _consoleHelper.ReadKey(); }
static void Main(string[] args) { SplashScreen splash = new SplashScreen(); splash.GenerateSplashScreen(); Console.SetWindowSize(57, 35); Customer activeCustomer = null; ConsoleHelper consoleHelper = new ConsoleHelper(); SHOWMENU: { Console.Clear(); consoleHelper.WriteHeaderToConsole("Welcome to Bangazon!"); if (activeCustomer != null) { string custString = $"Logged In As: {activeCustomer.CustomerName}"; string cartString = ""; var cartRepo = new CartRepository(); var activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); if (activeCart == null) { cartRepo.AddCart(activeCustomer.CustomerId); activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); } else { var cartDetail = new CartDetailRepository(); cartString = $"Cart({cartDetail.GetTotalItemsInCart(activeCart.CartId)}) {cartDetail.GetCartPrice(activeCart.CartId)}"; } string space = new string(' ', (56 - cartString.Length - custString.Length)); if (cartString.Length < 1) { consoleHelper.WriteLine($"{custString}\n"); } else { consoleHelper.WriteLine($"{custString}{space}{cartString}\n"); } } consoleHelper.WriteLine( "1.Create a new customer account" + "\n" + "2.Choose an existing customer" + "\n" + "3.Create a new payment option" + "\n" + "4.Add product(s) to shopping cart" + "\n" + "5.View Items in Cart\n" + "6.Complete an order" + "\n" + "7.View product popularity" + "\n" + "8.Logout Current User" + "\n" + "9.Leave Bangazon!"); Console.ForegroundColor = ConsoleColor.White; var userInput = consoleHelper.WriteAndReadFromConsole("> "); switch (userInput) { case "1": Console.Clear(); var CustomerInfo = new CustomerController(); activeCustomer = CustomerInfo.CreateCustomer(); goto SHOWMENU; case "2": Console.Clear(); var selectCustomerCtrl = new SelectCustomerController(); activeCustomer = selectCustomerCtrl.SelectActiveCustomer(); break; case "3": if (activeCustomer == null) { Console.Clear(); selectCustomerCtrl = new SelectCustomerController(); activeCustomer = selectCustomerCtrl.SelectActiveCustomer(); if (activeCustomer == null) { break; } } Console.Clear(); var PaymentCtrl = new PaymentController(); PaymentCtrl.RequestPayment(activeCustomer); break; case "4": if (activeCustomer == null) { Console.Clear(); activeCustomer = (new SelectCustomerController()).SelectActiveCustomer(); if (activeCustomer == null) { break; } } (new CartController()).addProduct(activeCustomer); break; case "5": if (activeCustomer == null) { Console.Clear(); activeCustomer = (new SelectCustomerController()).SelectActiveCustomer(); if (activeCustomer == null) { break; } } (new ViewCartController()).getItemsInCart(activeCustomer); break; case "6": if (activeCustomer == null) { Console.Clear(); activeCustomer = (new SelectCustomerController()).SelectActiveCustomer(); if (activeCustomer == null) { break; } } (new CartController()).checkout(activeCustomer); break; case "7": Console.Clear(); var productPopularityController = new ProductPopularityController(); productPopularityController.DisplayPopularProducts(); break; case "8": if (activeCustomer != null) { consoleHelper.WriteLine($"\nUser {activeCustomer.CustomerName} is being logged out!"); activeCustomer = null; Thread.Sleep(1500); } else { consoleHelper.WriteLine($"\nNo customer currently logged in!"); Thread.Sleep(1500); } break; case "9": Console.Clear(); consoleHelper.WriteHeaderToConsole("Logging out..."); Thread.Sleep(1500); Environment.Exit(0); break; default: consoleHelper.WriteLine("please select a valid menu item..."); Thread.Sleep(1000); break; } goto SHOWMENU; } }