// Display all the banks and prompts user to select a bank from that.
        public Models.Bank DisplayAndSelectBank()
        {
            IList <Models.Bank> banks;

            Models.Bank selectedBank;
            int         index;
            int         banksCount;
            int         selectedIndex;

            banks      = _bankService.GetAllBanks();;
            banksCount = banks.Count;

            if (banksCount == 0)
            {
                _UIStyling.ChangeForegroundForErrorMessage();
                _UIBuffer.WriteLine("There are no banks in the application\n");
                _UIStyling.RestoreForegroundColor();
            }
            while (true)
            {
                index = 0;
                _UIBuffer.WriteLine("Press number corresponding to the bank");
                _UIBuffer.WriteLine("-------------------------------");
                _UIBuffer.WriteLine(String.Format("  {0,-8}   {1,-10}\n", "S.No", "Bank Name"));
                foreach (Models.Bank bank in banks)
                {
                    _UIBuffer.WriteLine(String.Format("  {0,-8}   {1,-10}", index + 1, bank.Name));
                    index++;
                }
                _UIBuffer.WriteLine("-------------------------------\n");
                if (int.TryParse(_UIBuffer.ReadLine(), out selectedIndex))
                {
                    _UIBuffer.WriteLine("");
                    if (selectedIndex > 0 && selectedIndex <= banksCount)
                    {
                        selectedBank = banks[selectedIndex - 1];
                        return(selectedBank);
                    }
                    else
                    {
                        _UIStyling.ChangeForegroundForErrorMessage();
                        _UIBuffer.WriteLine(String.Format("Enter numbers between 1 and {0}\n", banksCount));
                        _UIStyling.RestoreForegroundColor();
                    }
                }
                else
                {
                    _UIBuffer.WriteLine("");
                    _UIStyling.ChangeForegroundForErrorMessage();
                    _UIBuffer.WriteLine("Enter only numeric values\n");
                    _UIStyling.RestoreForegroundColor();
                }
            }
        }
Exemple #2
0
        public void Run()
        {
            Models.User.User AuthenticatedUser;
            string           PressedKey;
            int selectedOperation;

            // UI for user logging or exiting from the application.
            while (true)
            {
                try
                {
                    _currentBank = _bankUI.DisplayAndSelectBank();
                }
                catch
                {
                    _UIBuffer.WriteLine("Failed to Log JSON FILE ERROR MESSAGE: ");
                    return;
                }
                while (true)
                {
                    _UIBuffer.WriteLine(_UIStyling.PadBoth("Welcome to ", '*'));
                    _UIBuffer.WriteLine(_UIStyling.PadBoth(_currentBank.Name, '*'));
                    _UIBuffer.WriteLine("  Press 1 to Login");
                    _UIBuffer.WriteLine("  Press 2 to Signup");
                    _UIBuffer.WriteLine("  Press 3 to Goback");
                    _UIBuffer.WriteLine("  Press 4 to Exit\n");
                    PressedKey = _UIBuffer.ReadLine();
                    _UIBuffer.WriteLine("\n");
                    if (PressedKey == "3")
                    {
                        _UIBuffer.Clear();
                        break;
                    }
                    switch (PressedKey)
                    {
                    case "1":
                        // Iterate the loop till user enter current correct details.
                        while (true)
                        {
                            AuthenticatedUser = _userAuthentication.Authenticate(_currentBank.ID);
                            if (AuthenticatedUser == null)
                            {
                                _UIBuffer.WriteLine("  Wrong Credentials");
                                continue;
                            }
                            else
                            {
                                _UIBuffer.WriteLine("  WELCOME TO " + AuthenticatedUser.Name);
                                break;
                            }
                        }
                        // If the user is staff then staff UI will be displayed or else customer UI will be displayed.
                        if (AuthenticatedUser.Type == Models.User.UserType.StaffMember)
                        {
                            while (true)
                            {
                                _UIBuffer.WriteLine("  Press 1 for Staff Member Operations");
                                _UIBuffer.WriteLine("  Press 2 for Customer Operations");
                                _UIBuffer.WriteLine("  Press 3 to GoBack");
                                if (int.TryParse(_UIBuffer.ReadLine(), out selectedOperation))
                                {
                                    if (selectedOperation == 3)
                                    {
                                        break;
                                    }
                                    switch (selectedOperation)
                                    {
                                    case 1:
                                        _UIBuffer.Clear();
                                        new BankApplication.UI.User.StaffMember.StaffMemberUI(AuthenticatedUser.ID, AuthenticatedUser.Name, _currentBank.ID, _JsonFilePath, _UIStyling, _UIBuffer).run();
                                        _UIBuffer.Clear();
                                        break;

                                    case 2:
                                        _UIBuffer.Clear();
                                        new BankApplication.UI.User.Customer.CustomerUI(AuthenticatedUser.ID, AuthenticatedUser.Name, _currentBank.ID, _JsonFilePath, _UIStyling, _UIBuffer).run();
                                        _UIBuffer.Clear();
                                        break;

                                    default:
                                        _UIBuffer.WriteLine("Enter numbers between 1 and 3");
                                        break;
                                    }
                                }
                                else
                                {
                                    _UIBuffer.WriteLine("Enter only numeric values");
                                }
                            }
                        }
                        else
                        {
                            _UIBuffer.Clear();
                            new BankApplication.UI.User.Customer.CustomerUI(AuthenticatedUser.ID, AuthenticatedUser.Name, _currentBank.ID, _JsonFilePath, _UIStyling, _UIBuffer).run();
                            _UIBuffer.Clear();
                        }
                        break;

                    case "2":
                        _userSignUp.SignUpRequest(_currentBank.ID, _JsonFilePath);
                        break;

                    case "4":
                        return;

                    default:
                        _UIStyling.ChangeForegroundForErrorMessage();
                        _UIBuffer.WriteLine("Pressed incorrect key\n");
                        _UIStyling.RestoreForegroundColor();
                        break;
                    }
                }
            }
        }