Example #1
0
        public static void Start(Manager manager, Bank bank)
        {
            Console.Title = $"{bank.Name}: Manager";
            var managerMenuLoop = true;

            while (managerMenuLoop)
            {
                ConsoleScreen.PrintMenu(ConsoleScreen.ManagerMenuOptions);

                var choice = ConsoleScreen.Input(ConsoleScreen.ManagerMenuOptions.Length);

                Console.Clear();

                switch ((ManagerMenuOptions)choice)
                {
                case ManagerMenuOptions.Info:
                {
                    Console.WriteLine(manager);
                    ConsoleScreen.Clear();
                    break;
                }

                case ManagerMenuOptions.Control:
                {
                    try
                    {
                        manager.Control(bank.Workers.Data);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    ConsoleScreen.Clear();
                    break;
                }

                case ManagerMenuOptions.Organize:
                {
                    try
                    {
                        bank.Ceo.Organize(bank.Workers.Data);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    ConsoleScreen.Clear();
                    break;
                }

                case ManagerMenuOptions.CalculateSalaries:
                {
                    try
                    {
                        var totalSalaries = manager.CalculateSalaries(bank.Workers.Data);

                        Console.WriteLine($"Total salaries is {totalSalaries:C2}");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    ConsoleScreen.Clear();
                    break;
                }

                case ManagerMenuOptions.Back:
                {
                    managerMenuLoop = false;
                    break;
                }
                }
            }
        }
Example #2
0
        public static void Start(Client client, Bank bank)
        {
            Console.Title = $"{bank.Name}: Client";
            var clientMenuLoop = true;

            while (clientMenuLoop)
            {
                ConsoleScreen.PrintMenu(ConsoleScreen.ClientMenuOptions);

                var choice = ConsoleScreen.Input(ConsoleScreen.ClientMenuOptions.Length);

                Console.Clear();

                switch ((ClientMenuOptions)choice)
                {
                case ClientMenuOptions.Info:
                {
                    Console.WriteLine(client);
                    ConsoleScreen.Clear();
                    break;
                }

                case ClientMenuOptions.PayCredit:
                {
                    try
                    {
                        bank.ShowClientCredits(client);
                    }
                    catch (Exception e)
                    {
                        ConsoleLogger.Error(e.Message);
                        ConsoleScreen.Clear();
                        break;
                    }

                    Guid id = Guid.Empty;

                    Console.WriteLine("Enter id: ");

                    while (true)
                    {
                        try
                        {
                            id = Guid.Parse(LoginHelper.Input());
                            break;
                        }
                        catch (Exception)
                        {
                            ConsoleLogger.Error("Invalid guid format. Try again!");
                        }
                    }

                    Console.WriteLine("Amount: ");

                    var amount = WorkerSideHelper.InputAmount();

                    try
                    {
                        var credit = bank.GetCredit(client, id, out int creditIndex);
                        bank.PayCredit(credit, amount);

                        ConsoleLogger.Info("Operation is successfully.");
                        if (!credit.isDebt)
                        {
                            bank.Credits.Delete(creditIndex);
                            ConsoleLogger.Info("Debt is closed.");
                        }
                    }
                    catch (Exception e)
                    {
                        ConsoleLogger.Error(e.Message);
                    }
                    ConsoleScreen.Clear();
                    break;
                }

                case ClientMenuOptions.Back:
                {
                    clientMenuLoop = false;
                    break;
                }
                }
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            var bank = new Bank()
            {
                Name       = "Bank of America",
                Percentage = 0.2,
                Budget     = 1_000_000
            };

            bank.Ceo = new Ceo()
            {
                Name     = "Debra",
                Surname  = "Hayes",
                Age      = 36,
                Salary   = 2000,
                Position = "CEO",
                Pin      = "7777"
            };


            var worker2 = new Worker()
            {
                Name      = "Herbert ",
                Surname   = "Young",
                Age       = 38,
                Salary    = 750,
                Position  = "Operator",
                StartTime = DateTime.Now,
                EndTime   = DateTime.Now.AddHours(8),
                Pin       = "1111"
            };

            var worker1 = new Worker()
            {
                Name      = "Nita",
                Surname   = "McKnight",
                Age       = 25,
                Salary    = 800,
                Position  = "Operator",
                StartTime = DateTime.Now,
                EndTime   = DateTime.Now.AddHours(8),
                Pin       = "2222"
            };

            bank.Workers.Add(worker2);
            bank.Workers.Add(worker1);

            bank.Managers.Add(new Manager()
            {
                Name     = "Erin",
                Surname  = "Wynn",
                Age      = 30,
                Salary   = 900,
                Position = "Operator",
                Pin      = "3333"
            });

            Console.Title = "Bank";

            var mainMenuLoop = true;

            while (mainMenuLoop)
            {
                ConsoleScreen.PrintMenu(ConsoleScreen.MainMenuOptions);

                var choice = ConsoleScreen.Input(ConsoleScreen.MainMenuOptions.Length);

                Console.Clear();

                switch ((MainMenuOptions)choice)
                {
                case MainMenuOptions.BankInfo:
                {
                    try
                    {
                        bank.CalculateProfit();
                    }
                    catch (Exception)
                    {
                    }
                    Console.WriteLine(bank);
                    ConsoleScreen.Clear();
                    break;
                }

                case MainMenuOptions.Ceo:
                {
                    var tmp = new Ceo[1] {
                        bank.Ceo
                    };

                    bank.ShortInfoEmployees(tmp);

                    while (true)
                    {
                        LoginHelper.GetLoginData(out Guid id, out string pin);

                        try
                        {
                            Login.Login.login(id, pin, tmp);

                            ConsoleLogger.Info("Login successfully!");
                            ConsoleScreen.Clear();

                            CeoSide.Start(bank);
                            break;
                        }
                        catch (Exception e)
                        {
                            ConsoleLogger.Error(e.Message);
                            ConsoleScreen.Clear();
                        }
                    }
                    break;
                }

                case MainMenuOptions.Managers:
                {
                    bank.ShortInfoEmployees(bank.Managers.Data);

                    while (true)
                    {
                        LoginHelper.GetLoginData(out Guid id, out string pin);

                        try
                        {
                            var manager = Login.Login.login(id, pin, bank.Managers.Data) as Manager;

                            ConsoleLogger.Info("Login successfully!");
                            ConsoleScreen.Clear();

                            ManagerSide.Start(manager, bank);
                            break;
                        }
                        catch (Exception e)
                        {
                            ConsoleLogger.Error(e.Message);
                            ConsoleScreen.Clear();
                        }
                    }
                    break;
                }

                case MainMenuOptions.Workers:
                {
                    bank.ShortInfoEmployees(bank.Workers.Data);

                    while (true)
                    {
                        LoginHelper.GetLoginData(out Guid id, out string pin);

                        try
                        {
                            var worker = Login.Login.login(id, pin, bank.Workers.Data) as Worker;

                            ConsoleLogger.Info("Login successfully!");
                            ConsoleScreen.Clear();

                            WorkerSide.Start(worker, bank);
                            break;
                        }
                        catch (Exception e)
                        {
                            ConsoleLogger.Error(e.Message);
                            ConsoleScreen.Clear();
                        }
                    }
                    break;
                }

                case MainMenuOptions.Clients:
                {
                    try
                    {
                        bank.ShortInfoClients();
                    }
                    catch (Exception e)
                    {
                        ConsoleLogger.Error(e.Message);
                        ConsoleScreen.Clear();
                        break;
                    }

                    while (true)
                    {
                        LoginHelper.GetLoginData(out Guid id, out string pin);

                        try
                        {
                            var client = Login.Login.login(id, pin, bank.Clients.Data) as Client;

                            ConsoleLogger.Info("Login successfully!");
                            ConsoleScreen.Clear();

                            ClientSide.Start(client, bank);
                            break;
                        }
                        catch (Exception e)
                        {
                            ConsoleLogger.Error(e.Message);
                            ConsoleScreen.Clear();
                        }
                    }
                    break;
                }

                case MainMenuOptions.Exit:
                {
                    mainMenuLoop = false;
                    break;
                }
                }
            }
        }
Example #4
0
        public static void Start(Bank bank)
        {
            Console.Title = $"{bank.Name}: CEO";
            var ceoMenuLoop = true;

            while (ceoMenuLoop)
            {
                ConsoleScreen.PrintMenu(ConsoleScreen.CeoMenuOptions);

                var choice = ConsoleScreen.Input(ConsoleScreen.CeoMenuOptions.Length);

                Console.Clear();

                switch ((CeoMenuOptions)choice)
                {
                case CeoMenuOptions.Info:
                {
                    Console.WriteLine(bank.Ceo);
                    ConsoleScreen.Clear();
                    break;
                }

                case CeoMenuOptions.Control:
                {
                    try
                    {
                        bank.Ceo.Control(bank.Workers.Data);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    ConsoleScreen.Clear();
                    break;
                }

                case CeoMenuOptions.Organize:
                {
                    try
                    {
                        bank.Ceo.Organize(bank.Workers.Data);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    ConsoleScreen.Clear();
                    break;
                }

                case CeoMenuOptions.MakeMeeting:
                {
                    try
                    {
                        bank.Ceo.Organize(bank.Workers.Data);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    ConsoleScreen.Clear();
                    break;
                }

                case CeoMenuOptions.ChangeCreditPercent:
                {
                    while (true)
                    {
                        Console.WriteLine($"Old percent: {bank.Percentage:P1}");
                        Console.WriteLine("New percent: ");
                        var percent = CeoSideHelper.InputPercent() / 100;

                        try
                        {
                            bank.Ceo.ChangePercentage(percent, bank);

                            Console.WriteLine("Bank percent changed!");
                            ConsoleScreen.Clear();
                            break;
                        }
                        catch (BankPercentException e) when(e.BankPercentage < 0)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Bank percent must be greater or equal to zero.");
                            Console.ResetColor();
                            ConsoleScreen.Clear();
                        }
                        catch (BankPercentException e) when(e.BankPercentage > 0)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Bank percent must be lower or equal to hundred.");
                            Console.ResetColor();
                            ConsoleScreen.Clear();
                        }
                    }
                    break;
                }

                case CeoMenuOptions.Back:
                {
                    ceoMenuLoop = false;
                    break;
                }
                }
            }
        }
Example #5
0
        public static void Start(Worker worker, Bank bank)
        {
            Console.Title = $"{bank.Name}: Worker";
            var workerMenuLoop = true;

            while (workerMenuLoop)
            {
                ConsoleScreen.PrintMenu(ConsoleScreen.WorkerMenuOptions);

                var choice = ConsoleScreen.Input(ConsoleScreen.WorkerMenuOptions.Length);

                Console.Clear();

                switch ((WorkerMenuOptions)choice)
                {
                case WorkerMenuOptions.Info:
                {
                    Console.WriteLine(worker);
                    ConsoleScreen.Clear();
                    break;
                }

                case WorkerMenuOptions.AddOperation:
                {
                    try
                    {
                        Console.WriteLine("-----------Operation-----------");

                        var operationName = WorkerSideHelper.InputOperationName();
                        var newOperation  = WorkerSideHelper.CreateNewOperation(operationName);
                        worker.Operations.Add(newOperation);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    ConsoleScreen.Clear();
                    break;
                }

                case WorkerMenuOptions.GiveCredit:
                {
                    Console.WriteLine("Client fullname: ");

                    var fullname       = WorkerSideHelper.InputFullname();
                    var nameComponents = BankHelper.NameSplit(fullname);


                    Client client = null;

                    try
                    {
                        var index = Array.FindIndex(bank.Clients.Data,
                                                    c => c.Name == nameComponents[0] && c.Surname == nameComponents[1]);
                        client = bank.Clients[index];
                    }
                    catch (Exception)
                    {
                        client = new Client()
                        {
                            Name = nameComponents[0], Surname = nameComponents[1], Pin = BankHelper.GenerateNewPin()
                        };
                        ConsoleLogger.Error($"There is no client associated this name -> {fullname}. Created new client!\n Client PIN is \"{client.Pin}\"");
                        bank.Clients.Add(client);
                    }

                    Console.WriteLine("Amount: ");
                    var amount = WorkerSideHelper.InputAmount();

                    Console.WriteLine("Months: ");
                    var months = WorkerSideHelper.InputMonths();

                    var newCredit = WorkerSideHelper.CreateNewCredit(client, amount, bank.Percentage, months);

                    try
                    {
                        bank.GiveCredit(newCredit);

                        ConsoleLogger.Info("New credit given.");
                    }
                    catch (Exception e)
                    {
                        ConsoleLogger.Error(e.Message);
                    }

                    ConsoleScreen.Clear();
                    break;
                }

                case WorkerMenuOptions.Back:
                {
                    workerMenuLoop = false;
                    break;
                }
                }
            }
        }