/// <summary> /// Choose menu "Change user data" /// </summary> public static void ChangeUserDataByAdmin() { string inputName, inputUserId; int userId; Print.PrintHeader("Change user data", ConsoleColor.DarkYellow); inputUserId = Print.ReadInput("Enter user ID:"); userId = ParseInput.IsCorrectId(inputUserId); if (userId == -1) { return; } inputName = Print.ReadInput("Enter new user name (at least 3 characters):"); if (!ParseInput.IsCorrectName(inputName)) { return; } if (!StartActions.AdminLogic.ChangeUserName(inputName, userId)) { Console.WriteLine("Username hasn't changed!"); } else { Console.WriteLine("Username has changed!"); } }
/// <summary> /// Choose menu "Receiving Order" /// </summary> public static void ReceivingOrder() { string inputOrderId; int orderId; Print.PrintHeader("Receiving Order", ConsoleColor.DarkYellow); inputOrderId = Print.ReadInput("Enter order ID:"); orderId = ParseInput.IsCorrectId(inputOrderId); if (orderId == -1) { return; } if (!StartActions.UserLogic.ReceivingOrder(orderId)) { Console.WriteLine("\nSuch order doesn't exist!"); } else { Console.WriteLine("\nOrder received!"); } }
/// <summary> /// Choose menu "Change order status" /// </summary> public static void ChangeStatus() { string inputUserId, inputOrderId; int userId, orderId; Print.PrintHeader("Change order status", ConsoleColor.DarkYellow); inputUserId = Print.ReadInput("\nEnter user ID: "); userId = ParseInput.IsCorrectId(inputUserId); if (userId == -1) { return; } inputOrderId = Print.ReadInput("\nEnter order ID: "); orderId = ParseInput.IsCorrectId(inputOrderId); if (orderId == -1) { return; } if (!StartActions.AdminLogic.UserExist(userId)) { Console.WriteLine("Such user doesn't exist!"); return; } if (!StartActions.AdminLogic.OrderExist(userId, orderId)) { Console.WriteLine("Such order doesn't exist!"); return; } Console.WriteLine("Choose status: "); foreach (var item in StartActions.AdminLogic.GetStatuses()) { Console.WriteLine(item); } string inputStatus = Print.ReadInput("\nEnter status number: "); if (!StartActions.AdminLogic.ChangeStatus(userId, orderId, inputStatus)) { Console.WriteLine("Incorrect input status!"); } else { Console.WriteLine("Status changed!"); } }
/// <summary> /// Choose menu "Change password" /// </summary> public static void ChangePassword() { string inputPassword; Print.PrintHeader("Change password", ConsoleColor.DarkYellow); inputPassword = Print.ReadInput("Enter new password (at least 3 characters):"); if (!ParseInput.IsCorrectPassword(inputPassword)) { return; } if (!StartActions.UserLogic.ChangePassword(inputPassword)) { Console.WriteLine("Password hasn't changed!"); } else { Console.WriteLine("Password has changed!"); } }
/// <summary> /// Choose menu ("Change username" /// </summary> public static void ChangeName() { string inputName; Print.PrintHeader("Change username", ConsoleColor.DarkYellow); inputName = Print.ReadInput("Enter new username (at least 3 characters):"); if (!ParseInput.IsCorrectName(inputName)) { return; } if (!StartActions.UserLogic.ChangeName(inputName)) { Console.WriteLine("Username hasn't changed!"); } else { Console.WriteLine("Username has changed!"); } }
/// <summary> /// Choose menu "Add New Product" /// </summary> public static void AddNewProduct() { string inputName, inputPrice; decimal price; Print.PrintHeader("Add New Product", ConsoleColor.DarkYellow); Console.WriteLine("Choose product category: "); foreach (var item in StartActions.AdminLogic.GetCategories()) { Console.WriteLine(item); } string inputCategory = Print.ReadInput("\nEnter category number: "); inputName = Print.ReadInput("Enter name (at least 3 characters):"); if (!ParseInput.IsCorrectName(inputName)) { return; } inputPrice = Print.ReadInput("Enter price:"); price = ParseInput.IsCorrectPrice(inputPrice); if (price == -1) { return; } if (!StartActions.AdminLogic.AddNewProduct(inputCategory, inputName, price)) { Console.WriteLine("Incorrect input data\nProduct hasn't added!"); } else { Console.WriteLine("Product has added!"); } }
/// <summary> /// Choose menu "Add to shopping cart" /// </summary> public static void AddToShoppingCart() { string inputProductId; int productId; Print.PrintHeader("Add to shopping cart", ConsoleColor.DarkYellow); inputProductId = Print.ReadInput("\nEnter ID of the product you want to add to the cart: "); productId = ParseInput.IsCorrectId(inputProductId); if (productId == -1) { return; } if (!StartActions.UserLogic.AddToShoppingCart(productId)) { Console.WriteLine("\nSuch product doesn't exist!"); } else { Console.WriteLine($"\nProduct with ID:{productId} added!"); } }
/// <summary> /// Choose menu "Remove from shopping cart" /// </summary> public static void RemoveFromShoppingCart() { string inputProductId; int productId; Print.PrintHeader("Remove from shopping cart", ConsoleColor.DarkYellow); inputProductId = Print.ReadInput("\nEnter ID of the product you want to remove from the cart: "); productId = ParseInput.IsCorrectId(inputProductId); if (productId == -1) { return; } if (!StartActions.UserLogic.RemoveFromShoppingCart(productId)) { Console.WriteLine("\nThis product is not in the cart!"); } else { Console.WriteLine($"\nProduct with ID:{productId} removed!"); } }
/// <summary> /// Choose menu "Change product data" /// </summary> public static void ChangeProductDataByAdmin() { string inputName, inputPrice, inputProductId; int productId; decimal price; Print.PrintHeader("Change product data", ConsoleColor.DarkYellow); inputProductId = Print.ReadInput("Enter product ID:"); productId = ParseInput.IsCorrectId(inputProductId); if (productId == -1) { return; } if (!StartActions.AdminLogic.ProductExist(productId)) { Console.WriteLine("Such product doesn't exist!"); return; } string input = Print.ReadInput("Enter what you need to change\n[1] Product name\n[2] Product price"); if (input == "1") { inputName = Print.ReadInput("Enter new name:"); if (!ParseInput.IsCorrectName(inputName)) { return; } if (StartActions.AdminLogic.ChangeProductName(productId, inputName)) { Console.WriteLine("Name changed!"); } else { Console.WriteLine("Incorrect input!"); } } else if (input == "2") { inputPrice = Print.ReadInput("Enter new price:"); price = ParseInput.IsCorrectPrice(inputPrice); if (price == -1) { return; } if (StartActions.AdminLogic.ChangeProductPrice(productId, price)) { Console.WriteLine("Price changed!"); } else { Console.WriteLine("Incorrect input!"); } } else { Console.WriteLine("Incorrect input!"); } }
/// <summary> /// Choose menu 'Register' /// </summary> public static void Register() { GuestLogic = new GuestLogic(); string name, email, password, input; while (true) { Console.Clear(); Print.PrintHeader("REGISTER", ConsoleColor.DarkYellow); name = Print.ReadInput("\nEnter your name (at least 3 characters): "); if (!ParseInput.IsCorrectName(name)) { Console.WriteLine("\nIncorrect name!"); input = Print.ReadInput("\n[1] Try again\nor enter any other key to return"); if (input != "1") { return; } else { continue; } } email = Print.ReadInput("\nEnter user email (*****@***): "); if (!ParseInput.IsCorrectEmail(email)) { Console.WriteLine("\nIncorrect email!"); input = Print.ReadInput("\n[1] Try again\nor enter any other key to return"); if (input != "1") { return; } else { continue; } } password = Print.ReadInput("\nEnter password (at least 3 characters): "); if (!ParseInput.IsCorrectPassword(password)) { Console.WriteLine("\nIncorrect password!"); input = Print.ReadInput("\n[1] Try again\nor enter any other key to return"); if (input != "1") { return; } else { continue; } } if (!GuestLogic.Register(name, email, password)) { Console.WriteLine("\nUser with this email already exists!"); input = Print.ReadInput("\n[1] Try again\nor enter any other key to return"); if (input != "1") { return; } } else { break; } } GuestLogic.LogIn(email, password); Console.Clear(); if (UserLogic.GetAccountType().Equals("USER")) { UserActions.UserMode(); } else { UserActions.AdminMode(); } while (true) { Print.PrintHeader($"{UserLogic.GetAccountType()}: {UserLogic.GetAccountName()}", ConsoleColor.Green); UserActions.GetActions(); input = Console.ReadLine(); Console.Clear(); Print.PrintHeader($"{UserLogic.GetAccountType()}: {UserLogic.GetAccountName()}", ConsoleColor.Green); if (input.ToLower() == "q") { UserLogic.LogOut(); break; } UserActions.ChooseAction(input); } }