public static void Main(string[] args) { List<User> users = getUsers(); List<Product> products = getProducts(); Tusc tusc = new Tusc(users, products); tusc.Start(); }
public static void Main(string[] args) { // Load users from data file List<User> users = JsonConvert.DeserializeObject<List<User>>(File.ReadAllText(@"Data/Users.json")); // Load products from data file List<Product> products = JsonConvert.DeserializeObject<List<Product>>(File.ReadAllText(@"Data/Products.json")); Tusc tusc = new Tusc(new DataStore(users, products)); tusc.start(); }
public static void Main(string[] args) { // Load users from data file List<User> users = FileManager.LoadJsonFile<User>(@"Data/Users.json"); // Load products from data file List<Product> products = FileManager.LoadJsonFile<Product>(@"Data/Products.json"); var tusc = new Tusc(users, products); tusc.Start(); }
public static void Main(string[] args) { // Load users from data file List<User> users = JsonConvert.DeserializeObject<List<User>>(File.ReadAllText(@"Data/Users.json")); // Load products from data file List<Product> products = JsonConvert.DeserializeObject<List<Product>>(File.ReadAllText(@"Data/Products.json")); DataManager dataManager = new DataManager(users, products); WriteWelcomeToTUSCMessage(); User loggedInUser = LoginManager.LogIn(users); if (loggedInUser != null) { Store store = new Store(loggedInUser, dataManager); Tusc tusc = new Tusc(loggedInUser, store); tusc.Run(); } }
public static void Start(List<User> usrs, List<Product> prods) { Tusc tusc = new Tusc(); tusc.Login(usrs, pwd); // Write welcome message Console.WriteLine("Welcome to TUSC"); Console.WriteLine("---------------"); // Show product list while (true) { // Prompt for user input Console.WriteLine(); Console.WriteLine("What would you like to buy?"); for (int i = 0; i < 7; i++) { Product prod = prods[i]; Console.WriteLine(i + 1 + ": " + prod.Name + " (" + prod.Price.ToString("C") + ")"); } 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; /* Subtract 1 from number num = num + 1 // Add 1 to number */ // Check if user entered number that equals product count if (num == 7) { // Update balance foreach (var usr in usrs) { // Check that name and password match if (usr.Name == name && usr.Pwd == pwd) { usr.Bal = bal; } } // Write out new balance string json = JsonConvert.SerializeObject(usrs, Formatting.Indented); File.WriteAllText(@"Data/Users.json", json); // Write out new quantities string json2 = JsonConvert.SerializeObject(prods, Formatting.Indented); File.WriteAllText(@"Data/Products.json", json2); // Prevent console from closing Console.WriteLine(); Console.WriteLine("Press Enter key to exit"); Console.ReadLine(); return; } else { Console.WriteLine(); Console.WriteLine("You want to buy: " + prods[num].Name); Console.WriteLine("Your balance is " + bal.ToString("C")); // Prompt for user input Console.WriteLine("Enter amount to purchase:"); answer = Console.ReadLine(); int qty = Convert.ToInt32(answer); // Check if balance - quantity * price is less than 0 if (bal - prods[num].Price * qty < 0) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(); Console.WriteLine("You do not have enough money to buy that."); Console.ResetColor(); continue; } // Check if quantity is less than quantity if (prods[num].Qty <= qty) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(); Console.WriteLine("Sorry, " + prods[num].Name + " is out of stock"); Console.ResetColor(); continue; } // Check if quantity is greater than zero if (qty > 0) { // Balance = Balance - Price * Quantity bal = bal - prods[num].Price * qty; // Quanity = Quantity - Quantity prods[num].Qty = prods[num].Qty - qty; Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("You bought " + qty + " " + prods[num].Name); Console.WriteLine("Your new balance is " + bal.ToString("C")); Console.ResetColor(); } else { // Quantity is less than zero Console.Clear(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(); Console.WriteLine("Purchase cancelled"); Console.ResetColor(); } } } }