private static void AddProductMenu(Admin user) { Console.WriteLine("1.Add new book."); Console.WriteLine("2.Add new game."); Console.WriteLine("3.Add new movie."); Console.WriteLine("4.Add new music."); Console.WriteLine("5.Back"); Console.WriteLine("Make choice."); int choice = MakeChoice(1, 5); try { switch (choice) { case 1: // Create book { user.AddAvailableProduct(Book.CreateBook()); Console.WriteLine("Added successfull."); PressAnyKey(); break; } case 2: // Create game { user.AddAvailableProduct(Game.CreateGame()); Console.WriteLine("Added successfull."); PressAnyKey(); break; } case 3: // Create movie { user.AddAvailableProduct(Movie.CreateMovie()); Console.WriteLine("Added successfull."); PressAnyKey(); break; } case 4: // Create music { user.AddAvailableProduct(Music.CreateMusic()); Console.WriteLine("Added successfull."); PressAnyKey(); break; } case 5: PressAnyKey(); break; } } catch (Exception e) { Console.WriteLine(e.Message + "! Try again."); } }
public static void Register(string username, string password) { Admin admin = new Admin(username, password); ShopInformation.Administrators.Add(admin); }
public static void LogInMenu() { while (true) { Console.Clear(); Console.WriteLine("1.Login as customer."); Console.WriteLine("2.Login as admin."); Console.WriteLine("3.Exit"); Console.WriteLine("Make your choice"); int choice = MakeChoice(1, 3); if (choice == 3) return; Console.WriteLine("Enter username:"******"Enter password"); string password = Console.ReadLine(); switch (choice) { case 1: // Login as customer { try { Customer customer = new Customer(username, password); customer = (Customer)customer.LogIn(); if (customer != null) { Console.WriteLine("Logged in successful."); CustomerMenu(customer); } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } catch (Exception e) { Console.WriteLine(e.Message); } break; } case 2: // Login as admin { try { Admin admin = new Admin(username, password); admin = (Admin)admin.LogIn(); if (admin != null) { Console.WriteLine("Logged in successful."); AdminMenu(admin); } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } break; } } } }
private static void ChangeQuantityMenu(Admin user) { Console.WriteLine("1.Add quantity."); Console.WriteLine("2.Remove quantity"); int choice = MakeChoice(1, 2); Console.WriteLine("Enter product ID:"); int id = int.Parse(Console.ReadLine()); Console.WriteLine("Enter quantity to add/remove"); int quantity = int.Parse(Console.ReadLine()); if (choice == 1) { user.AddQuantity(id, quantity); } else if (choice == 2) { user.RemoveQuantity(id, quantity); } PressAnyKey(); }
private static void AdminMenu(Admin user) { while (true) { Console.Clear(); Console.WriteLine("1.Add product in shop."); Console.WriteLine("2.Remove product from shop."); Console.WriteLine("3.Change product price."); Console.WriteLine("4.Make promotion."); Console.WriteLine("5.Make premium customer."); Console.WriteLine("6.Change product quantity."); Console.WriteLine("7.View all products in shop."); Console.WriteLine("8.View all sold products."); Console.WriteLine("9.Logout."); Console.WriteLine("Make your choice"); int choice = MakeChoice(1, 9); switch (choice) { case 1: // add product { AddProductMenu(user); break; } case 2:// remove product { Console.WriteLine("Enter product id:"); int id = int.Parse(Console.ReadLine()); user.RemoveAvailableProduct(id); PressAnyKey(); break; } case 3: // change price { Console.WriteLine("Enter product id:"); int productID = int.Parse(Console.ReadLine()); Console.WriteLine("Enter new price:"); decimal price = decimal.Parse(Console.ReadLine()); user.ChangePrice(productID, price); PressAnyKey(); break; } case 4: // make promotion { try { Console.WriteLine("Enter file name:"); string file = Console.ReadLine(); user.MakePromotion(file); } catch (IOException ioe) { Console.WriteLine(ioe.Message); } PressAnyKey(); break; } case 5: // make premium customer { Console.WriteLine("Enter customer username:"******"Enter customer password:"); string customerPassword = Console.ReadLine(); user.MakePremiumCustomer(customerName, customerPassword); PressAnyKey(); break; } case 6: // change quantity { ChangeQuantityMenu(user); break; } case 7: // view all products { Console.WriteLine(ShopInformation.AvailableProducts); PressAnyKey(); break; } case 8: // view all sold products { Console.WriteLine(ShopInformation.SoldProducts); PressAnyKey(); break; } case 9: { user.LogOut(); return; } } } }