private bool processProductSelection(User currentUser, int selectedProduct) { showProductSelectionSuccess(currentUser, selectedProduct); int selectedQuantity = getQuantitySelection(); double costToPurchase = products[selectedProduct].Price * selectedQuantity; if (currentUser.balance < costToPurchase) { showInsufficientBalanceMessage(); return false; } int remainingQuantity = products[selectedProduct].Quantity; if (selectedQuantity > remainingQuantity) { showInsufficientQuantityMessage(selectedProduct); return false; } if (selectedQuantity > 0) { processPurchase(currentUser, selectedProduct, selectedQuantity); } else { showSelectedQuantityNegativeMessage(); } return true; }
private void SetUser(User newUser) { User currentUser = users.FirstOrDefault(u => u.Name.Equals(newUser.Name) && u.Password.Equals(newUser.Password)); if (currentUser != null) { currentUser.Balance = newUser.Balance; } }
public static void SaveAndClose(User currentUser, List<Product> products) { currentUser.SaveUser(); SaveProducts(products); UI.promptForClose(); return; }
internal static void DisplayUserPurchase(User user, Product product, int quantity) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("You bought " + quantity + " " + product.Name); Console.WriteLine("Your new balance is " + user.Balance.ToString("C")); Console.ResetColor(); }
internal static void DisplayUserWelcomeMessage(User user) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(); Console.WriteLine("Login successful! Welcome " + user.Name + "!"); Console.ResetColor(); }
private static void WriteSuccessfulLoginMessage(User user) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(); Console.WriteLine(String.Format("Login successful! Welcome {0}!", user.Name)); Console.ResetColor(); }
public bool validateUsername(string usernameInput) { bool validUser = false; foreach(User user in this.user) { if(user.Name == usernameInput) { validUser = true; this.currentUser = user; } } return validUser; }
private static void WriteLoginMessage(User user) { if (user != null) { WriteSuccessfulLoginMessage(user); } else { WriteInvalidLoginMessage(); } }
private static void Shop(List<Product> prods, User currUser) { ShowWelcomeMsg(currUser); // Show remaining balance double bal = 0; if (currUser != null) { bal = currUser.Bal; // Show balance Console.WriteLine(); Console.WriteLine("Your balance is " + currUser.Bal.ToString("C")); } // Show product list while (true) { // Prompt for user input Console.WriteLine(); Console.WriteLine("What would you like to buy?"); for (int i = 0; i < prods.Count; i++) { Product prod = prods[i]; Console.WriteLine(prod.Description(i)); } Console.WriteLine(prods.Count + 1 + ": Exit"); // Prompt for user input Console.WriteLine("Enter a number:"); string answer = Console.ReadLine(); int num = Convert.ToInt32(answer); num = num - 1; // Check if user entered number that equals product count if (num == prods.Count) { currUser.Bal = bal; return; } else if (num > prods.Count) { String errText = "Invalid Selection."; ShowErrMsg(errText); } else { BuyItem(prods, ref bal, num); } } }
private static void ShowWelcomeMessage(User userExists) { // Show balance Console.Clear(); Console.WriteLine(); Console.WriteLine("Your balance is " + userExists.BalanceAmount.ToString("C")); // Show welcome message Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(); Console.WriteLine("Login successful! Welcome " + userExists.UserName + "!"); Console.ResetColor(); }
private static void GoShopping(User currentUser, List<Product> products) { double userBalance = currentUser.Balance; bool exitRequested = false; while (!exitRequested) { int itemSelected = PromptForPurchaseItem(products); if (SelectedItemIsProduct(itemSelected)) { Product selectedProduct = products[itemSelected]; DisplayPurchaseSummary(selectedProduct, userBalance); int requestedQuantity = PromptForPurchaseQuantity(); if (UserDoesNotHaveEnoughMoneyForPurchase(selectedProduct, userBalance, requestedQuantity)) { DisplayNotEnoughMoneyMessage(); continue; } if (NotEnoughProductQuantityAvailable(selectedProduct, requestedQuantity)) { DisplayOutOfStockMessage(selectedProduct); continue; } if (requestedQuantity > 0) { userBalance = UpdateUserBalance(userBalance, selectedProduct, requestedQuantity); UpdateProductQuantity(selectedProduct, requestedQuantity); DisplayReceiptMessage(userBalance, selectedProduct, requestedQuantity); } else { DisplayPurchaseCancelledMessage(); } } else if (itemSelected == EXIT) { currentUser.Balance = userBalance; exitRequested = true; } else { DisplayInvalidProductSelectedMessage(); } } }
public static User validatePassword(User user, string password) { User validUser = null; if (user.password == password) { validUser = user; } else { showInvalidPasswordMessage(); } return validUser; }
private static bool LoginUser(string UserName, string UserPassword) { bool LoginStatus = false; if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(UserPassword)) { for (int i = 0; i < TuscUsers.Count() && !LoginStatus; i++) { TuscUser = TuscUsers[i]; if (TuscUser.Name == UserName) { if (TuscUser.Name == UserName && TuscUser.Pwd == UserPassword) LoginStatus = true; } } } return LoginStatus; }
private bool Login() { bool isLoggedIn = false; string name = PromptForUserInput("Enter Username:"******"Enter Password:"******"Login successful! Welcome " + name + "!"); // Show remaining balance Console.Write("Your balance is " + currentUser.Bal.ToString()); isLoggedIn = true; } else { // Invalid Password ClearAndDisplayMessage(ConsoleColor.Red, "You entered an invalid password."); Exit(); //Login(); } } else { // Invalid User ClearAndDisplayMessage(ConsoleColor.Red, "You entered an invalid user."); Exit(); //Login(); } return isLoggedIn; }
private void processUserSelections(User currentUser) { while (true) { showProductList(); int selectedProduct = getProductSelection(); if (userSelectedExit(selectedProduct)) { onExit(); return; } else { if (!processProductSelection(currentUser, selectedProduct)) { continue; } } } }
public static bool isProductOkToPurchase(User currentUser, Product currentProduct, int quantityToPurchase) { bool okToPurchase = true; if (!currentUser.IsUserBalanceSufficient(currentProduct, quantityToPurchase)) { UI.printInsufficientBalance(); okToPurchase = false; } else if (currentProduct.Qty <= quantityToPurchase) { UI.printProductOutOfStock(currentProduct); okToPurchase = false; } else if (quantityToPurchase < 0) { UI.printQuantityLessThanZero(); okToPurchase = false; } return okToPurchase; }
private static bool processSession(User user) { int selection; bool changesMade = false; do { displayProducts(); selection = readSelection(); if (selection != EXIT_CODE) { displayOrderConfirmation(selection, user); int quantity = readQty(); if (validateQuantity(quantity) && checkBalance(quantity, user, selection) && checkQuantity(quantity, selection)) { processTransaction(quantity, selection, user); changesMade = true; } } } while (selection != EXIT_CODE); return changesMade; }
private bool BeginUserLogin() { // Login Login: string enteredUserName = UserInterface.PromptForUserName(); if (string.IsNullOrEmpty(enteredUserName)) { goto Login; } // Validate Username var isUserNameValid = IsUserInList(enteredUserName); if (!isUserNameValid) { UserInterface.DisplayInvalidUserMessage(); goto Login; } _currentUser = GetUserFromList(enteredUserName); string password = UserInterface.PromptForPassword(); var isPasswordValid = ValidatePassword(password); if (!isPasswordValid) { UserInterface.DisplayInvalidPasswordMessage(); goto Login; } return true; }
private static void showTusc(List<User> usrs, List<Product> prods, User currentUser) { double balance = currentUser.Bal; showRemainingBalanceMessage(balance); while (true) { showProductList(prods); int productNumber = getUserInput("Enter a number:") - 1; if (productNumber == EXIT_NUMBER) { currentUser.Bal = balance; saveBalance(usrs); saveProductQuantity(prods); promptExitMessage(); return; } else if (productNumber < EXIT_NUMBER) { balance = purchaseProcess(prods, balance, productNumber); } } }
private static void PrintConfirmPurchaseMessage(Product product, User user) { Console.WriteLine(); Console.WriteLine(Resources.msgWantToBuy + product.Name); Console.WriteLine(string.Format(Resources.msgBalance, user.Balance.ToString("C"))); }
private static bool LogInUser() { var isValid = true; var exit = false; while (!exit) { //request UserName OutPutToConsole("Enter Username:"******"You entered an invalid user.", true, true, ConsoleColor.Red); isValid = false; } else { OutPutToConsole("Enter Password:"******"You entered an invalid password.", true, true, ConsoleColor.Red); isValid = false; } else { //valid user found exit login exit = true; } } } else { //exit login isValid = false; exit = true; } } return isValid; }
private static bool SetCurrentUser(List<User> users, string username) { bool isValidUser = false; if (!string.IsNullOrEmpty(username)) { for (int i = 0; i < users.Count; i++) { if (users[i].Name == username) { currentUser = users[i]; isValidUser = true; } } } return isValidUser; }
private static void PrintPurchaseSuccessfulMessage(User user, Product product, int quantity) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(string.Format(Resources.msgPurchased, quantity, product.Name)); Console.WriteLine(string.Format(Resources.msgNewBalance, user.Balance.ToString("C"))); Console.ResetColor(); }
public Login(List<User> user) { this.user = user; this.currentUser = null; }
public Store(User user, DataManager dataManager) { this.user = user; this.dataManager = dataManager; }
private static void TakeFundsFromUser(User user, Product product, int quantity) { user.Balance = user.Balance - product.Price * quantity; }
private static bool ValidatePassword(User selectedUser, string pwd) { if(selectedUser.Password == pwd) { return true; } else { PrintInvalidPasswordMessage(); return false; } }
private static void PrintLoginSuccessfulMessage(User user) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(); Console.WriteLine(string.Format(Resources.msgLoginSuccessful, user.Name)); Console.ResetColor(); }
private static void PrintBalance(User user) { Console.WriteLine(); Console.WriteLine(string.Format(Resources.msgBalance, user.Balance.ToString("C"))); }
private static bool ValidateUserHasEnoughMoney(User user, Product product, int quantity) { if (user.Balance < product.Price * quantity) { PrintInsufficientFundsMessage(); return false; } return true; }