static void Main(string[] args) { #region Creational Patterns SafeAccountProxy safeAccount = new SafeAccountProxy();//there is only one account used per mobile device safeAccount.RealSubject = ClientAccount.Instance(); safeAccount.Deposit(1000, 5000, 2000); ICurrencyProfile eurProfile = new CurrencyEUR { Client = ClientAccount.Instance(), ProfileCurrency = ECurrencyProfile.EUR }; ICurrencyProfile ronProfile = new CurrencyEUR { Client = ClientAccount.Instance(), ProfileCurrency = ECurrencyProfile.RON }; ICurrencyProfile usdProfile = new CurrencyEUR { Client = ClientAccount.Instance(), ProfileCurrency = ECurrencyProfile.USD }; #endregion ConstructBrasovLocations(); ConstructIBANs(); XmlReader.ReadCurrency(); LoginToAccount(safeAccount, out sw); while (sw >= 0) { switch (sw) { //Change password case 1: { Console.WriteLine("Introdu parola:"); string password = Console.ReadLine(); safeAccount.Activate(password); break; } //See currencies case 2: { XmlReader.PrintCurrency(); break; } //Exchange case 3: { Exchange(); break; } //Send money to another account case 4: { string iban = null; ICurrencyProfile profile = null; while (true) { Console.WriteLine("Dati contul IBAN in care doriti sa faceti depunerea:"); iban = Console.ReadLine(); if (IBANs.Contains(iban)) { break; } else { Console.WriteLine("Cont iban inexistent!"); } } Console.WriteLine("Dati suma:"); Double.TryParse(Console.ReadLine(), out double sum); Console.WriteLine("Alegeti contul din care sa se retraga suma: eur, ron sau usd"); string option = Console.ReadLine(); option = option.Trim().ToUpper(); switch (option) { case "EUR": { profile = eurProfile; break; } case "RON": { profile = ronProfile; break; } case "USD": { profile = usdProfile; break; } default: { Console.WriteLine("Pentru contul dumneavoastra sunt disponibile doar 3 profile: Euro, Dolar si Ron"); break; } } if (profile != null) { profile.SendMoney(iban, sum); } break; } case 5: { Console.WriteLine("Introduceti cifrele codului de bare de pe factura:"); Int32.TryParse(Console.ReadLine(), out int code); Console.WriteLine("Alegeti tipul facturii: 1-Electricitate, 2-Apa, 3-Telefon, 4-Gaz"); Int32.TryParse(Console.ReadLine(), out int option); EBillType type = EBillType.NO_BILL; switch (option) { case 1: { type = EBillType.EElectricityBill; break; } case 2: { type = EBillType.EWaterBill; break; } case 3: { type = EBillType.EPhoneBill; break; } case 4: { type = EBillType.EGasBill; break; } default: { Console.WriteLine("Optiunea este momentan indisponibila."); break; } } if (type != EBillType.NO_BILL) { string randomIBAN = IBANs.ElementAt(random.Next(0, IBANs.Count)); ronProfile.SendMoney(randomIBAN, valFactura); Console.WriteLine($"{type.ToString()} : A fost retrasa suma de {valFactura} ron."); } break; } case 6: { Console.WriteLine("Alegeti reteaua: 1-Telekom, 2-Vodafone, 3-Digi, 4-Orange"); Int32.TryParse(Console.ReadLine(), out int optionResult); Console.WriteLine("Introduceti numarul de telefon:"); Int32.TryParse(Console.ReadLine(), out int phone); EMobilePhoneNetwork network = EMobilePhoneNetwork.NO_AVAIBLE_NETWORK; switch (optionResult) { case 1: { network = EMobilePhoneNetwork.Telekom; break; } case 2: { network = EMobilePhoneNetwork.Vodafone; break; } case 3: { network = EMobilePhoneNetwork.Digi; break; } case 4: { network = EMobilePhoneNetwork.Orange; break; } default: { Console.WriteLine("Momentan nu se pot face plati in reteaua aleasa."); break; } } if (network != EMobilePhoneNetwork.NO_AVAIBLE_NETWORK) { string randomIBAN = IBANs.ElementAt(random.Next(0, IBANs.Count)); int valCartela = valoriCartela.ElementAt(random.Next(0, valoriCartela.Count)); eurProfile.SendMoney(randomIBAN, valCartela); Console.WriteLine($"Reincarcare cartela {network.ToString()} : A fost retrasa suma de {valCartela} eur."); } break; } //Balance from all accounts case 7: { safeAccount.DisplayBalance(); break; } case 8: { PrintAgencies(); break; } case 0: { LoginToAccount(safeAccount, out sw); break; } default: ReadInputCommand(out sw); break; } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Doriti sa continuati? y - yes, n - no"); if (Char.TryParse(Console.ReadLine(), out char opt)) { if (opt == 'y') { ReadInputCommand(out sw); } else { sw = 0; } } } }
static void Main(string[] args) { var admin = new SafeAccountProxy(); List <User> userList = new List <User>(); ChatRoom chatRoom = new ChatRoom("Notifications"); while (true) { Console.WriteLine("----------------" + "\n1. Admin " + "\n2. User " + "\n3. Existing user" + "\n----------------"); string option = Console.ReadLine(); switch (option) { case "1": Console.WriteLine("\nPlease log in as admin: "); Console.Write(" Username: "******" Password: "******"\n----------------------------------------------------------" + "\nWelcome Admin"); bool usr = true; do { Console.WriteLine("-------------\n" + "1. Activate \n" + "2. Order computers \n" + "3. Display stock \n" + "4. Display cash in register \n" + "5. Add cash \n" + "6. Set computer free \n" + "7. Chatrooms \n" + "8. Summary \n" + "9. Exit \n" + "-----------------"); string optionAdmin = Console.ReadLine(); switch (optionAdmin) { case "1": if (admin.isActivated == false) { Console.WriteLine("\nPlease select a new password to activate your account"); Console.Write(" New Password: "******" Account already active !"); break; } case "2": Console.WriteLine("\n--------------------------\n" + "1. Asus Desktop - 1500$\n" + "2. HP Laptop - 2000$\n" + "3. Lenovo Desktop - 1500$\n" + "4. Mac Laptop - 5000$\n" + "5. Back\n" + "--------------------------"); admin.DisplayCash(); int orderComputerChoice = Convert.ToInt32(Console.ReadLine()); if (orderComputerChoice == 5) { break; } admin.OrderComputer(orderComputerChoice, admin.GetCashVar()); break; case "3": admin.DisplayStock(); break; case "4": admin.DisplayCash(); break; case "5": Console.Write("\nInsert amount of money you want to cash in: "); int money = Convert.ToInt32(Console.ReadLine()); admin.CashIn(money); break; case "6": admin.DisplayStock(); Console.Write("Select computer id to change the state: "); int opt = Convert.ToInt32(Console.ReadLine()); admin.SetComputerFree(opt); break; case "7": chatRoom.DisplayUsers(); Console.WriteLine($"\n{chatRoom.Name}" + "\nChoose client:"); int selectedUserId = Convert.ToInt32(Console.ReadLine()); User selectedUser = new User(); if (userList.Find(x => userList.IndexOf(x) == selectedUserId) != null) { selectedUser = userList.Find(x => userList.IndexOf(x) == selectedUserId); Console.WriteLine("Message..."); string message = Console.ReadLine(); admin.Send(message, selectedUser, chatRoom); } break; case "8": admin.Summary(); break; case "9": usr = false; break; default: break; } } while (usr); } else { Console.WriteLine("\n Credentials unavailable !!!\n"); } break; case "2": Console.WriteLine("\nWelcome user"); User user = new User(); Console.Write("Enter username: "******"3": userList.ForEach(element => { Console.WriteLine($"Id: {userList.IndexOf(element)} Username: {element.Name}"); }); Console.Write("Type your id: "); int userId = Convert.ToInt32(Console.ReadLine()); if (userList.Find(x => userList.IndexOf(x) == userId) != null) { User connectedUser = userList.Find(x => userList.IndexOf(x) == userId); bool usr = true; do { Console.WriteLine("\n1.Display computers. \n2.Notifications \n3.Exit "); string optionUser = Console.ReadLine(); switch (optionUser) { case "1": connectedUser.ViewComputers(); Console.Write("Enter the computer id you want: "); int opt = Convert.ToInt32(Console.ReadLine()); Console.Write("For how many hours would you like the computer(min. 1H, max. 10H): "); int optHours = Convert.ToInt32(Console.ReadLine()); if (optHours >= 1 && optHours <= 10) { connectedUser.ChooseComputer(opt, optHours); chatRoom.Register(connectedUser); connectedUser.Accept(ManageComputer.summary); } else { Console.WriteLine("The number of hours introduced is invalid"); } break; case "2": foreach (var item in connectedUser.messageList) { Console.WriteLine(item); } break; case "3": usr = false; break; } } while (usr); } else { Console.WriteLine("Try again."); } break; default: break; } } }