示例#1
0
        public void GenerateMainMenu()
        {
            while (true)
            {
                Console.WriteLine("-------------------------- Ngân Hàng Spring Hero Bank --------------------------");
                Console.WriteLine("1. Đăng ký tài khoản.");
                Console.WriteLine("2. Đăng Nhập hệ thống.");
                Console.WriteLine("3. Thoát");
                Console.WriteLine("---------------------------------------------------------------------------------");
                Console.WriteLine("Nhập lựa chọn của bạn (1, 2, 3)");
                var choice = PromptHelper.GetUserChoice(1, 3);
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Đăng ký tài khoản");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    //goi controller -> de navigate user
                    break;

                case 2:
                    Console.WriteLine("Đằng nhập hệ thống");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    if (!LoginSuccess)
                    {
                        Console.WriteLine("login failed");
                    }
                    else if (LoginSuccess && IsAdmin)
                    {
                        GenerateAdminMenu();
                    }
                    else
                    {
                        GenerateCustomMenu();
                    }


                    break;

                case 3:
                    Console.WriteLine("Thoát");
                    break;

                default:
                    Console.WriteLine("không hợp lệ");
                    break;
                }

                if (choice == 3)
                {
                    break;
                }
            }
        }
        public void GenerateAdminMenu()
        {
            Console.Clear();
            while (true)
            {
                Console.Clear();

                Console.WriteLine("-------------------------- Ngân Hàng Spring Hero Bank --------------------------");
                Console.WriteLine($"Chào mừng admin {CurrentLogin.FullName} quay trỏ lại. Vui lòng chọn thao tác");
                Console.WriteLine("1. Danh sách người dùng");
                Console.WriteLine("2. Danh sách lịch sử giao dịch.");
                Console.WriteLine("3. Tìm kiếm người dùng theo tên.");
                Console.WriteLine("4. Tìm kiếm người dùng theo số tài khoản");
                Console.WriteLine("5. Tìm kiếm người dùng theo số điện thoại");
                Console.WriteLine("6. Thêm người dùng mới");
                Console.WriteLine("7. Khoá và mở tài khoản người dùng");
                Console.WriteLine("8. Tìm kiếm lịch sử giao dịch theo số tài khoản");
                Console.WriteLine("9. Thay đổi thông tin tài khoản.");
                Console.WriteLine("10. Thay đổi thông tin mật khẩu");
                Console.WriteLine("11. Thoát");
                Console.WriteLine("---------------------------------------------------------------------------------");
                Console.WriteLine("Nhập lựa chọn của bạn (từ 1 đến 11)");
                var choice = PromptHelper.GetUserChoice(1, 11);
                switch (choice)
                {
                case 1:
                    Console.Clear();
                    Console.WriteLine("Danh sách người dùng");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    List <Account> listAccounts = _accountController.ListAccount();
                    if (listAccounts == null)
                    {
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để tiếp tục...");
                        break;
                    }

                    if (listAccounts.Count == 0)
                    {
                        Console.WriteLine("Không có người dùng nào");
                        break;
                    }

                    Console.WriteLine($"đã tìm thấy {listAccounts.Count} tài khoản");
                    PromptHelper.StopConsole("Bấm phím bất kỳ để hiển thị danh sách tài khoản...");
                    //chuyển sang list string để lấy page view
                    List <string> listPages = new List <string>();
                    foreach (var account in listAccounts)
                    {
                        listPages.Add(account.ToString());
                    }

                    //generate page view
                    GeneratePageView(listPages);
                    break;

                case 2:
                    Console.Clear();
                    Console.WriteLine("Danh sách lịch sử giao dịch");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    var listAllTransactions = _accountController.GetListTransactions();
                    if (listAllTransactions == null)
                    {
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để quay lại menu...");
                        break;
                    }

                    if (listAllTransactions.Count == 0)
                    {
                        Console.WriteLine("Không có giao dịch nào");
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để quay lại menu...");
                        break;
                    }

                    Console.WriteLine($"Đã tìm thấy {listAllTransactions.Count} giao dịch");
                    PromptHelper.StopConsole("Bấm phím bất kỳ để hiển thị danh sách giao dịch...");
                    //chuyển sang list <string>
                    List <string> listTransactionString = new List <string>();
                    foreach (var transaction in listAllTransactions)
                    {
                        listTransactionString.Add(transaction.ToString());
                    }

                    //generate page view
                    GeneratePageView(listTransactionString);
                    break;

                case 3:
                    Console.Clear();
                    Console.WriteLine("Tìm kiếm người dùng theo tên");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    var searchResult = _accountController.SearchAccountByName();
                    if (searchResult == null)
                    {
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để quay lại menu...");
                        break;
                    }

                    if (searchResult.Count == 0)
                    {
                        Console.WriteLine("Không có tài khoản nào khớp");
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để quay lại menu...");
                        break;
                    }

                    Console.WriteLine($"Đã tìm thấy {searchResult.Count} tài khoản");
                    PromptHelper.StopConsole("Bấm phím bất kỳ để hiển thị danh sách tài khoản...");
                    //chuển sang list string
                    List <string> listResultString = new List <string>();
                    foreach (var account in searchResult)
                    {
                        listResultString.Add(account.ToString());
                    }

                    //generate page view
                    GeneratePageView(listResultString);
                    break;

                case 4:
                    Console.Clear();
                    Console.WriteLine(" Tìm kiếm người dùng theo số tài khoản");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    var resultAccount = _accountController.SearchAccountByAccountNumber();
                    if (resultAccount == null)
                    {
                        PromptHelper.StopConsole("Ấn phím bất kỳ để quay lại menu...");
                        break;
                    }

                    var listAccountString = new List <string>()
                    {
                        resultAccount.ToString()
                    };
                    GeneratePageView(listAccountString);
                    break;

                case 5:
                    Console.Clear();
                    Console.WriteLine("Tìm kiếm người dùng theo số điện thoại");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    var resultAccountByPhoneNumber = _accountController.SearchAccountByPhoneNumber();
                    if (resultAccountByPhoneNumber == null)
                    {
                        PromptHelper.StopConsole("Ấn phím bất kỳ để quay lại menu...");
                        break;
                    }

                    var listSearchAccountByPhoneNumber = new List <string>()
                    {
                        resultAccountByPhoneNumber.ToString()
                    };
                    GeneratePageView(listSearchAccountByPhoneNumber);
                    break;

                case 6:
                    Console.Clear();
                    Console.WriteLine("Thêm người dùng mới");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    var newUser = _accountController.AddUser();
                    if (newUser == null)
                    {
                        Console.WriteLine("Thêm người dùng thất bại ");
                        PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục...");
                        break;
                    }

                    Console.WriteLine("Đã thêm thành công tài khoản: ");
                    Console.WriteLine(newUser.ToString());
                    PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục...");
                    break;

                case 7:
                    Console.Clear();
                    Console.WriteLine("Khoá và mở tài khoản người dùng");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    Console.WriteLine("1. Khóa tài khoản theo số tài khoản");
                    Console.WriteLine("2. Mở tài khoản theo số tài Khoản");
                    Console.WriteLine("3. Quay lại menu");
                    Console.WriteLine("Nhập lựa chọn (1, 2)");
                    var actionChoice = PromptHelper.GetUserChoice(1, 3);
                    switch (actionChoice)
                    {
                    case 1:
                        Console.WriteLine("Khóa tài khoản");
                        _accountController.LockAccount();
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để tiếp tục...");
                        break;

                    case 2:
                        Console.WriteLine("Mở khóa tài khoản");
                        _accountController.UnLockAccount();
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để tiếp tục...");
                        break;

                    case 3:
                        Console.WriteLine("Quay lại menu chính");
                        break;
                    }

                    break;

                case 8:
                    Console.Clear();
                    Console.WriteLine("Tìm kiếm lịch sử giao dịch theo số tài khoản");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    Console.WriteLine("Nhập số tài khoản bạn muốn tìm kiếm lịch sử giao dịch: ");
                    var accountNumber    = Console.ReadLine();
                    var listTransactions = _accountController.GetTransactionsByAccountNumber(accountNumber);
                    if (listTransactions == null)
                    {
                        PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục....");
                        break;
                    }

                    List <string> listPage = new List <string>();
                    if (listTransactions.Count == 0)
                    {
                        Console.WriteLine("Không có giao dịch nào được thực hiện");
                        PromptHelper.StopConsole("Ấn phím bất kỳ để quay lại menu...");
                        break;
                    }

                    Console.WriteLine($"Đã tìm thấy {listTransactions.Count} giao dịch");
                    foreach (var transaction in listTransactions)
                    {
                        listPage.Add(transaction.ToString());
                    }

                    PromptHelper.StopConsole("Ấn phím bất kỳ để hiển thị danh sách giao dịch...");
                    GeneratePageView(listPage);
                    break;

                case 9:
                    Console.Clear();
                    Console.WriteLine("Thay đổi thông tin tài khoản");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    while (true)
                    {
                        Console.Clear();
                        Console.WriteLine("Lựa chọn thông tin muốn thay đổi: ");
                        Console.WriteLine("1. Thay đổi tên đầy đủ");
                        Console.WriteLine("2. Thay đổi email");
                        Console.WriteLine("3. Thay đổi số điện thoại");
                        Console.WriteLine("4. Quay lại menu");
                        Console.WriteLine("Nhập lựa chọn của bạn từ 1 đến 4");
                        var updateChoice = PromptHelper.GetUserChoice(1, 4);
                        switch (updateChoice)
                        {
                        case 1:
                            Console.Clear();
                            _accountController.UpdateFullName(CurrentLogin.AccountNumber);
                            PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục...");
                            break;

                        case 2:
                            Console.Clear();
                            _accountController.UpdateEmail(CurrentLogin.AccountNumber);
                            PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục...");
                            break;

                        case 3:
                            Console.Clear();
                            _accountController
                            .UpdatePhoneNumber(CurrentLogin.AccountNumber);
                            PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục...");
                            break;

                        case 4:
                            break;
                        }

                        if (updateChoice == 4)
                        {
                            break;
                        }
                    }

                    break;

                case 10:
                    Console.Clear();
                    Console.WriteLine(" Thay đổi thông tin mật khẩu");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    if (_accountController.UpdatePassWord(CurrentLogin.AccountNumber) == false)
                    {
                        Console.WriteLine("Câp nhật mật khẩu thất bại...");
                        Console.WriteLine("Phiên đăng nhập đã hết hạn...");
                        PromptHelper.StopConsole("Bấm phím bất kỳ để quay lại menu chính...");
                        return;
                    }

                    Console.WriteLine("Mời bạn đăng nhập lại...");
                    PromptHelper.StopConsole("Bấm phím bất kỳ để tiếp tục....");
                    return;

                case 11:
                    Console.Clear();
                    Console.WriteLine("Thoát");
                    break;
                }

                if (choice == 11) // break ve main menu ngay sau khi update password hoac chon thoát
                {
                    break;
                }
            } // end while true
        }     //end function
        }     //end function

        public void GenerateCustomMenu()
        {
            Console.Clear();
            while (true)
            {
                Console.Clear();
                Console.WriteLine("-------------------------- Ngân Hàng Spring Hero Bank --------------------------");
                Console.WriteLine($"Chào mừng {CurrentLogin.FullName} quay trở lại. Vui lòng chọn thao tác");
                Console.WriteLine("1. Gửi tiền");
                Console.WriteLine("2. Rút tiền");
                Console.WriteLine("3. Chuyển khoản");
                Console.WriteLine("4. Truy vấn số dư");
                Console.WriteLine("5. Thay đổi thông tin cá nhân");
                Console.WriteLine("6. Thay đổi thông tin mật khẩu.");
                Console.WriteLine("7. Truy vấn lịch sử giao dịch");
                Console.WriteLine("8. Thoát");
                Console.WriteLine("---------------------------------------------------------------------------------");
                Console.WriteLine("Nhập lựa chọn của bạn (từ 1 đến 8)");
                int choice = PromptHelper.GetUserChoice(1, 8);
                switch (choice)
                {
                case 1:
                    Console.Clear();
                    Console.WriteLine("Gửi tiền");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    if (_accountController.Deposit(CurrentLogin.AccountNumber) == false)
                    {
                        Console.WriteLine("Gửi tiền không thành công, hãy thử lại sau !!!");
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để quay lại menu....");
                        break;
                    }

                    Console.WriteLine("Thao tác thành công");
                    PromptHelper.StopConsole("Nhấn phím bất kỳ để tiếp tục...");
                    break;

                case 2:
                    Console.Clear();
                    Console.WriteLine("Rút tiền");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    if (_accountController.WithDraw(CurrentLogin.AccountNumber) == false)
                    {
                        Console.WriteLine("Rút tiền không thành công....");
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để quay lại menu....");
                        break;
                    }

                    Console.WriteLine("Thao tác thành công");
                    PromptHelper.StopConsole("Nhấn phím bất kỳ để tiếp tục...");
                    break;

                case 3:
                    Console.Clear();
                    Console.WriteLine("Chuyển khoản");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    if (_accountController.Transfer(CurrentLogin.AccountNumber) == false)
                    {
                        Console.WriteLine("Chuyển khoản thất bại");
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để quay lại menu....");
                        break;
                    }

                    Console.WriteLine("Thao tác thành công");
                    PromptHelper.StopConsole("Nhấn phím bất kỳ để tiếp tục...");
                    break;

                case 4:
                    Console.Clear();
                    Console.WriteLine("Truy vấn số dư");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    var balance = _accountController.GetBalance(CurrentLogin.AccountNumber);
                    if (balance > -1)
                    {
                        Console.WriteLine("Số dư của tài khoản: " + balance);
                    }

                    PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục...");
                    break;

                case 5:
                    Console.Clear();
                    Console.WriteLine("Thay đổi thông tin cá nhân");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    while (true)
                    {
                        Console.WriteLine("Lựa chọn thông tin muốn thay đổi: ");
                        Console.WriteLine("1. Thay đổi tên đầy đủ");
                        Console.WriteLine("2. Thay đổi email");
                        Console.WriteLine("3. Thay đổi số điện thoại");
                        Console.WriteLine("4. Quay lại menu");
                        var updateChoice = PromptHelper.GetUserChoice(1, 4);
                        switch (updateChoice)
                        {
                        case 1:
                            _accountController.UpdateFullName(CurrentLogin.AccountNumber);
                            PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục");
                            break;

                        case 2:
                            _accountController.UpdateEmail(CurrentLogin.AccountNumber);
                            PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục");
                            break;

                        case 3:
                            _accountController.UpdatePhoneNumber(CurrentLogin.AccountNumber);
                            PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục");
                            break;

                        case 4:
                            break;
                        }

                        if (updateChoice == 4)
                        {
                            break;
                        }
                    }

                    break;

                case 6:
                    Console.Clear();
                    Console.WriteLine("Thay đổi thông tin mật khẩu");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    if (_accountController.UpdatePassWord(CurrentLogin.AccountNumber) == false)
                    {
                        Console.WriteLine("Câp nhật mật khẩu thất bại...");
                        Console.WriteLine("Phiên đăng nhập đã hết hạn...");
                        PromptHelper.StopConsole("Bấm phím bất kỳ để quay lại menu chính...");
                        return;
                    }

                    Console.WriteLine("Cập nhật mật khẩu thành công mời bạn đăng nhập lại...");
                    PromptHelper.StopConsole("Bấm phím bất kỳ để tiếp tục....");
                    return;

                case 7:
                    Console.Clear();
                    Console.WriteLine("Truy vấn lịch sử giao dịch");
                    List <SHBTransaction> listTransactions =
                        _accountController.GetTransactionsByAccountNumber(CurrentLogin.AccountNumber);
                    if (listTransactions.Count == 0)
                    {
                        Console.WriteLine("Chưa có giao dịch nào được thực hiện");
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để quay lại menu....");
                        break;
                    }

                    List <string> listPage = new List <string>();
                    foreach (var shbTransaction in listTransactions)
                    {
                        listPage.Add(shbTransaction.ToString());
                    }

                    GeneratePageView(listPage);
                    PromptHelper.StopConsole("Nhấn phím bất kỳ để tiếp tục...");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 8:
                    Console.WriteLine("Thoát");
                    break;
                } //end swtich case

                if (choice == 8) // sau khi update mat khau -> break về main menu luôn
                {
                    break;
                }
            } //end outer while loop
        }     //end of the function
        public void GenerateMainMenu()
        {
            Console.Clear();
            while (true)
            {
                Console.Clear();
                Console.WriteLine("-------------------------- Ngân Hàng Spring Hero Bank --------------------------");
                Console.WriteLine("1. Đăng ký tài khoản.");
                Console.WriteLine("2. Đăng nhập hệ thống.");
                Console.WriteLine("3. Thoát");
                Console.WriteLine("---------------------------------------------------------------------------------");
                Console.WriteLine("Nhập lựa chọn của bạn (1, 2, 3)");
                var choice = PromptHelper.GetUserChoice(1, 3);
                switch (choice)
                {
                case 1:
                    Console.Clear();
                    Console.WriteLine("Đăng ký tài khoản");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    Account newAccount = _accountController.Register();
                    if (newAccount == null)
                    {
                        Console.WriteLine("Đăng ký tài khoản không thành công");
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để quay lại menu chính...");
                        break;
                    }

                    Console.WriteLine("Bạn đã đăng ký thành công tài khoản với thông tin: ");
                    Console.WriteLine($"Họ và tên: {newAccount.FullName}\n" +
                                      $"Số tài khoản: {newAccount.AccountNumber}\n" +
                                      $"Sô dư hiện tại: {newAccount.Balance}\n" +
                                      $"Số điện thoại: {newAccount.PhoneNumber}\n" +
                                      $"Email: {newAccount.Email}\n" +
                                      $"Tên đăng nhập: {newAccount.Username}");
                    PromptHelper.StopConsole("Ấn phím bất kỳ để tiếp tục....");
                    break;

                case 2:
                    Console.Clear();
                    Console.WriteLine("Đăng nhập hệ thống");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    var currentAccount = _accountController.Login();
                    if (currentAccount == null)
                    {
                        Console.WriteLine("Đăng nhập không thành công");

                        Console.WriteLine("Đăng nhập không thành công. Vui lòng thử lại!. ");
                        PromptHelper.StopConsole("Nhấn phím bất kỳ để quay lại menu chính...");
                        break;
                    }

                    CurrentLogin = currentAccount;
                    if (CurrentLogin.Role == AccountRole.ADMIN)
                    {
                        GenerateAdminMenu();
                    }

                    if (CurrentLogin.Role == AccountRole.GUEST)
                    {
                        GenerateCustomMenu();
                    }

                    break;

                case 3:
                    Console.WriteLine("Thoát");
                    Console.WriteLine("Cảm ơn quý khách đã sử dụng dịch vụ của ngân hàng SHB");
                    break;

                default:
                    Console.WriteLine("Không hợp lệ");
                    break;
                }

                if (choice == 3)
                {
                    break;
                }
            }
        }
示例#5
0
        public Account AddUser() // cho phép thêm tài khoản khách hoặc admin
        {
            var accountNumber = "";

            while (true)
            {
                accountNumber = AccountHelper.RandomAccountNumber(15);
                var isExist = _accountModel.CheckExistAccountNumber(accountNumber);
                if (isExist == null)
                {
                    Console.WriteLine("Kiểm tra kết nối của bạn");
                    break;
                }

                if (isExist == false)
                {
                    break;
                }
            }

            //init account obj
            var newAccount = new Account()
            {
                Balance       = 0,
                Status        = AccountStatus.ACTIVE,
                Salt          = _passwordHelper.GenerateSalt(),
                AccountNumber = accountNumber,
            };

            //get Role
            Console.WriteLine("Bạn muốn tạo tài khoản thường hay tài khoản cho admin ?");
            Console.WriteLine("1. Tài khoản thường");
            Console.WriteLine("2. Tài khoản admin");
            Console.WriteLine("Chọn 1 hoặc 2");
            var choice = PromptHelper.GetUserChoice(1, 2);

            switch (choice)
            {
            case 1:
                newAccount.Role = AccountRole.GUEST;
                break;

            case 2:
                newAccount.Role = AccountRole.ADMIN;
                break;
            }

            //get full Name
            Console.WriteLine("Nhập tên đầy đủ: ");
            string fullName = Console.ReadLine();

            newAccount.FullName = fullName;
            //get email
            Console.WriteLine("Nhập email: ");
            string email;

            while (true)
            {
                email = Console.ReadLine();
                if (ValidateHelper.IsEmailValid(email))
                {
                    break;
                }

                Console.WriteLine("Email không hợp lệ mời nhập lại");
            }

            newAccount.Email = email;
            //get phone number
            Console.WriteLine("Nhập số điện thoại: ");
            string phoneNumber;

            while (true)
            {
                phoneNumber = Console.ReadLine();
                if (ValidateHelper.IsPhoneNumberValid(phoneNumber))
                {
                    break;
                }

                Console.WriteLine("Số điện thoại không hợp lệ mời nhập lại");
            }

            newAccount.PhoneNumber = phoneNumber;
            //get username
            Console.WriteLine("Nhập tên đăng nhập: ");
            //prompt for username if exsist -> prompt again
            string username;

            while (true)
            {
                username = Console.ReadLine();
                var isValid = ValidateHelper.IsUsernameValid(username);
                var isExist = _accountModel.CheckExistAccountByUsername(username);
                if (isExist == null)
                {
                    Console.WriteLine("Hãy kiểm tra kết nối của bạn");
                    return(null);
                }
                if (isValid && isExist == false)
                {
                    break;
                }

                if (!isValid)
                {
                    Console.WriteLine("tên đăng nhập không hợp lệ mời nhập lại");
                    continue;
                }

                if (isExist == true)
                {
                    Console.WriteLine("Tên đăng nhập đã tồn tại mời nhập lại");
                    continue;
                }
            }

            newAccount.Username = username;
            //get password
            Console.WriteLine("Hãy nhập vào mật khẩu:");
            string password;

            while (true)
            {
                password = PromptHelper.GetPassword();
                if (ValidateHelper.IsPasswordValid(password))
                {
                    break;
                }

                Console.WriteLine("Mật khẩu không hợp lệ mời nhập lại");
            }

            //xác nhận mật khẩu
            Console.WriteLine("Nhập lại mật khẩu của bạn để xác nhận: ");
            string confirmPass = "";

            while (true)
            {
                confirmPass = PromptHelper.GetPassword();
                if (confirmPass.Equals(password))
                {
                    break;
                }

                Console.WriteLine("Mật khẩu không khớp, mời nhập lại");
            }


            //hash pwd and salt to get password hashed
            newAccount.PasswordHash = _passwordHelper.MD5Hash(password + newAccount.Salt);

            var result = _accountModel.SaveAccount(newAccount);

            if (result == false)
            {
                return(null);
            }

            return(newAccount);
        }
示例#6
0
        public bool Transfer(string senderAccountNumber)
        {
            bool result = false;

            Console.WriteLine("Nhập số tài khoản người nhận: ");
            string receiverAccountNumber = Console.ReadLine();

            if (receiverAccountNumber.Equals(senderAccountNumber))
            {
                Console.WriteLine("không thể chuyển khoản cho cùng 1 số tài khoản");
                return(false);
            }

            var receiverAccount = _accountModel.GetAccountByAccountNumber(receiverAccountNumber);

            if (receiverAccount == null)
            {
                return(false);
            }

            Console.WriteLine(
                "---------------------------------------------------------------------------------------");
            Console.WriteLine(
                "                              Thông tin người nhận                                     ");
            Console.WriteLine(
                "---------------------------------------------------------------------------------------");
            Console.WriteLine("TÊN: " + receiverAccount.FullName);
            Console.WriteLine("EMAIL: " + receiverAccount.Email);
            Console.WriteLine("SỐ ĐIỆN THOẠI: " + receiverAccount.PhoneNumber);
            Console.WriteLine(
                "---------------------------------------------------------------------------------------");
            Console.WriteLine("Bạn có muốn chuyển khoản cho người này ?");
            Console.WriteLine("1. Có");
            Console.WriteLine("2. Không");
            Console.WriteLine(
                "---------------------------------------------------------------------------------------");
            Console.WriteLine("Nhập lựa chọn của bạn");
            var choice = PromptHelper.GetUserChoice(1, 2);

            switch (choice)
            {
            case 1:
                Console.WriteLine("Nhập số tiền bạn muốn chuyển khoản: ");
                var amount = PromptHelper.GetAmount();
                //confirm transfer

                result = _accountModel.Transfer(senderAccountNumber, receiverAccountNumber, amount);
                break;

            case 2:
                Console.WriteLine("Quay lại menu chính...");
                result = true;
                break;

            default:
                Console.WriteLine("Lựa chọn không hợp lệ");
                result = false;
                break;
            }

            if (result == true)
            {
                Console.WriteLine("Chuyển khoản thành công số dư tài khoản tại thời điểm giao dịch " +
                                  _accountModel.GetCurrentBalanceByAccountNumber(senderAccountNumber));
            }

            return(result);
        }
示例#7
0
        public void GenerateAdminMenu()
        {
            while (true)
            {
                Console.WriteLine("-------------------------- Ngân Hàng Spring Hero Bank --------------------------");
                Console.WriteLine("Chào mừng admin xuân hùng quay trỏ lại. Vui lòng chọn thao tác");
                Console.WriteLine("1. Danh sách người dùng");
                Console.WriteLine("2.Danh sách lịch sử giao dịch.");
                Console.WriteLine("3. Tìm kiếm người dùng theo tên.");
                Console.WriteLine("4. Tìm kiếm người dùng theo số tài khoản");
                Console.WriteLine("5. Tìm kiếm người dùng theo số điện thoại");
                Console.WriteLine("6. Thêm người dùng mới");
                Console.WriteLine("7. Khoá và mở tài khoản người dùng");
                Console.WriteLine("8. Tìm kiếm lịch sử giao dịch theo số tài khoản");
                Console.WriteLine("9. Thay đổi thông tin tài khoản.");
                Console.WriteLine("10. Thay đổi thông tin mật khẩu");
                Console.WriteLine("11. Thoát");
                Console.WriteLine("---------------------------------------------------------------------------------");
                Console.WriteLine("Nhập lựa chọn của bạn (từ 1 đến 11)");
                var choice = PromptHelper.GetUserChoice(1, 11);
                switch (choice)
                {
                case 1:
                    Console.WriteLine("danh sách người dùng");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");

                    break;

                case 2:
                    Console.WriteLine("Danh sách lịch sử giao dịch");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 3:
                    Console.WriteLine("Tìm kiếm người dùng theo tên");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 4:
                    Console.WriteLine(" Tìm kiếm người dùng theo số tài khoản");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 5:
                    Console.WriteLine("Tìm kiếm người dùng theo số điện thoại");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 6:
                    Console.WriteLine(" Thêm người dùng mới");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 7:
                    Console.WriteLine("Khoá và mở tài khoản người dùng");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    Console.WriteLine("1. Khóa Tài khoản theo số tài khoản");
                    Console.WriteLine("2. Mở tài khoản theo số tài Khoản");
                    Console.WriteLine("3. Quay lại menu");
                    Console.WriteLine("Nhập lựa chọn (1, 2)");
                    var actionChoice = PromptHelper.GetUserChoice(1, 3);
                    switch (actionChoice)
                    {
                    case 1:
                        Console.WriteLine("khóa tài khoản");
                        _accountController.LockAccount();
                        PromptHelper.StopConsole();
                        break;

                    case 2:
                        Console.WriteLine("Mở khóa tài khoản");
                        _accountController.UnLockAccount();
                        PromptHelper.StopConsole();
                        break;

                    case 3:
                        Console.WriteLine("quay lại menu chính");
                        break;
                    }

                    break;

                case 8:
                    Console.WriteLine("Tìm kiếm lịch sử giao dịch theo số tài khoản");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    var           listTransactions = _accountController.GetTransactionsByAccountNumber();
                    List <string> listPage         = new List <string>();

                    if (listTransactions.Count == 0)
                    {
                        Console.WriteLine("Không có giao dịch nào được thực hiện");
                        break;
                    }
                    foreach (var transaction in listTransactions)
                    {
                        listPage.Add(transaction.ToString());
                    }

                    Console.WriteLine($"Đã tìm thấy {listTransactions.Count} lịch sử giao dịch");
                    GeneratePageView(listPage);
                    PromptHelper.StopConsole();
                    break;

                case 9:
                    Console.WriteLine("Thay đổi thông tin tài khoản");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 10:
                    Console.WriteLine(" Thay đổi thông tin mật khẩu");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 11:
                    Console.WriteLine("Thoát");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                default:
                    break;
                }

                if (choice == 11)
                {
                    break;
                }
            } // end while true
        }     //end function
示例#8
0
        }     //end function

        public void GenerateCustomMenu()
        {
            while (true)
            {
                Console.WriteLine("-------------------------- Ngân Hàng Spring Hero Bank --------------------------");
                Console.WriteLine("Chào mừng xuân hùng quay trỏ lại. Vui lòng chọn thao tác");
                Console.WriteLine("1. Gửi tiền");
                Console.WriteLine("2. Rút tiền");
                Console.WriteLine("3. Chuyển khoản");
                Console.WriteLine("4. Truy vấn số dư");
                Console.WriteLine("5. Thay đổi thông tin cá nhân");
                Console.WriteLine("6. Thay đổi thông tin mật khẩu.");
                Console.WriteLine("7. Truy vấn lịch sử giao dịch");
                Console.WriteLine("8. Thoát");
                Console.WriteLine("---------------------------------------------------------------------------------");
                Console.WriteLine("Nhập lựa chọn của bạn (từ 1 đến 8)");
                int choice = PromptHelper.GetUserChoice(1, 8);
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Gửi tiền");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");

                    break;

                case 2:
                    Console.WriteLine("Rút tiền");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 3:
                    Console.WriteLine("Chuyển khoản");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 4:
                    Console.WriteLine("Truy vấn số dư");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 5:
                    Console.WriteLine("Thay đổi thông tin cá nhân");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 6:
                    Console.WriteLine("Thay đổi thông tin mật khẩu");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 7:
                    Console.WriteLine("Truy vấn lịc sử giao dịch");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                case 8:
                    Console.WriteLine("Thoát");
                    Console.WriteLine(
                        "---------------------------------------------------------------------------------");
                    break;

                default:
                    break;
                } //end swtich case

                if (choice == 8)
                {
                    break;
                }
            } //end outer while loop
        }     //end of the function