/// <summary> /// Takes in a string to create a new customer username, only is called if customer does not exist. /// </summary> /// <param name="uName">String inputted username</param> /// <returns></returns> public Customer CreateCustomer(string uName) { var info = GetLoginInfo(uName); int age = InputFunctions.ParseStringToInt(info[3]); Customer newUser = new Customer(uName, info[0], info[1], info[2], age); return(newUser); }
/// <summary> /// Prompts the user to create a new product with a name, description, price, and if it should be age restricted and then returns the Product object /// </summary> /// <returns></returns> public static Product CreateProduct() { Console.WriteLine("To create new product please enter a name for it:"); string productName = Console.ReadLine(); Console.WriteLine("To create new product please enter a desc for it:"); string productDesc = Console.ReadLine(); Console.WriteLine("To create new product please enter a price for it:"); decimal productPrice = InputFunctions.ParseStringToDecimal(Console.ReadLine()); Console.WriteLine("Is this product age restricted?"); bool isProductAgeRestricted = InputFunctions.ParseStringToBool(Console.ReadLine()); return(storeState.CreateProduct(productName, productDesc, productPrice, isProductAgeRestricted)); }
static void Main(string[] args) { int onlineState = 1; do { Console.WriteLine("Welcome to Targmart.\n\t1. Login\n\t2. Quit"); onlineState = InputFunctions.ParseStringToInt(Console.ReadLine()); if (onlineState != 1) { Console.Write("See you again soon!!!"); break; } Customer activeCustomer = null; do { Console.WriteLine("Enter a username to login or create a new account"); activeCustomer = storeState.LoginCustomer(Console.ReadLine()); } while(activeCustomer == null); int shopState = 1; do { StoreLocation currentStore = new StoreLocation(); if (activeCustomer.isAdmin == true) { Console.WriteLine($"Welcome {activeCustomer.CustomerFName}!\n\t1. Shop\n\t2. Logout\n\t3. Create Store\n\t4. Create Products\n\t5. Assign Inventory\n\t6. Store Orders \n\t7. Manage Customers"); } else { Console.WriteLine($"Welcome {activeCustomer.CustomerFName}!\n\t1. Shop\n\t2. Logout"); } shopState = InputFunctions.ParseStringToInt(Console.ReadLine()); if (shopState == 1) { int cartState = 1; do { Console.WriteLine("Welcome to TargMart! Type 1 to begin shopping, type 2 to view your cart, type 3 to checkout, type 4 to view past orders or type 5 to exit."); Console.WriteLine("\t1. Shop\n\t2. View Cart\n\t3. Checkout\n\t4. Past Orders\n\t5. Exit"); cartState = InputFunctions.ParseStringToInt(Console.ReadLine()); // creating new cart if there is none, if it exists already, grabbing it. Order currentOrder = storeState.CreateOrder(activeCustomer); if (cartState == 1) { Console.WriteLine("Welcome to TargMart! Please select your store by name to being shopping:"); currentStore = GetStore(); if (currentStore == null) { Console.WriteLine("This store does not exist"); break; } Console.WriteLine($"Logged into {currentStore.StoreLocationName} ID: {currentStore.StoreLocationId}"); Console.WriteLine("Type the name of the product to select a quantity to buy, or press 1 to go back to store selection"); List <Inventory> inventory = storeState.DisplayProducts(currentStore); foreach (Inventory i in inventory) { Console.WriteLine($"\tName: {i.Product.ProductName} | Quantity: {i.ProductQuantity} | Price: {i.Product.ProductPrice}"); } string selectedStore = Console.ReadLine(); Inventory item = storeState.SelectInventory(selectedStore, currentStore); if (item == null) { Console.WriteLine("This item does not exist at this store"); break; } Console.WriteLine($"How much {item.Product.ProductName} do you want to buy?"); int quantity = InputFunctions.ParseStringToInt(Console.ReadLine()); storeState.CreateOrderDetail(item, currentOrder, quantity); } if (cartState == 2) { PrintCurrentOrder(currentOrder); } if (cartState == 3) { storeState.CheckoutOrder(currentOrder); List <OrderDetails> cart = PrintCurrentOrder(currentOrder); Console.WriteLine($"\nChecking out with {cart.Count} product(s) totaling {currentOrder.TotalPrice}"); } if (cartState == 4) { GetOrderList(cust: activeCustomer); } } while(cartState != 5); } else if (shopState == 2) { Console.WriteLine("Logging out..."); break; } else if (shopState == 3 && activeCustomer.isAdmin == true) { currentStore = StoreCreation(); Console.WriteLine($"{currentStore.StoreLocationName} was created with and ID: {currentStore.StoreLocationId}"); } else if (shopState == 4 && activeCustomer.isAdmin == true) { Product newProduct = CreateProduct(); Console.WriteLine($"{newProduct.ProductName} created with a price of ${newProduct.ProductPrice}"); } else if (shopState == 5 && activeCustomer.isAdmin == true) { Console.WriteLine("Select store by name to add a product to it."); currentStore = GetStore(); if (currentStore == null) { Console.WriteLine("This store does not exist"); break; } Console.WriteLine($"Logged into {currentStore.StoreLocationName} ID: {currentStore.StoreLocationId}"); Console.WriteLine($"Select a product by name to add it to {currentStore.StoreLocationName}:"); List <Product> products = storeState.GetProducts(); foreach (Product p in products) { Console.WriteLine($"\t{p.ProductName}"); } string selectedProduct = Console.ReadLine(); Product currentProduct = storeState.SelectProduct(selectedProduct); if (currentProduct == null) { Console.WriteLine("Please enter a valid product"); break; } Console.WriteLine($"Selected product: {currentProduct.ProductName}\n Please enter the quantity of {currentProduct.ProductName} to add to {currentStore.StoreLocationName}"); int quantityAdd = InputFunctions.ParseStringToInt(Console.ReadLine()); storeState.AssignInventory(currentProduct, currentStore, quantityAdd); } else if (shopState == 6 && activeCustomer.isAdmin == true) { currentStore = GetStore(); if (currentStore == null) { Console.WriteLine("This store does not exist"); break; } GetOrderList(store: currentStore); } else if (shopState == 7 && activeCustomer.isAdmin == true) { GetCustomerList(); Console.WriteLine("Enter a username to make user admin"); string input = Console.ReadLine(); Customer editCustomer = storeState.SelectCustomer(input); AdminCreation(editCustomer); } } while (shopState != 2); } while(onlineState == 1); } // ends main method