コード例 #1
0
        public static string EditCurrentUser(string inputName, List <object> EmployeeList)
        {
            string returnedName = inputName;
            string newName      = "";

            Console.Clear();
            string inputNumber = "";
            int    i           = 0;

            foreach (Employee item in EmployeeList)

            {
                if (item.Name == inputName)
                {
                    Console.WriteLine(
                        "Write 1 to edit name. \n" +
                        "Write 2 to edit password. \n" +
                        "Write 3 to edit address.\n" +
                        "Write 4 to exit. \n");

                    inputNumber = Console.ReadLine();

                    while (true)
                    {
                        if (inputNumber == "1")
                        {
                            while (true)
                            {
                                Console.WriteLine(item.Name);
                                Console.WriteLine("Enter a new name:");
                                newName = Console.ReadLine();

                                if (!LoginAndValidation.ValidateInput(newName))

                                {
                                    Console.WriteLine("Incorrect validation");
                                    continue;
                                }
                                Console.WriteLine("Employee " + item.Name + " has been edited.\n");
                                item.Name = newName;
                                inputName = newName;

                                break;
                            }
                        }
                        else if (inputNumber == "2")
                        {
                            while (true)
                            {
                                Console.WriteLine("Enter a new password:"******"Enter a the same password again:");
                                string newPassword2 = Console.ReadLine();

                                if (newPassword == newPassword2)
                                {
                                    string inputPassword = Encryptor.MD5Hash(newPassword);
                                    item.Password = inputPassword;
                                    Console.WriteLine("The passwords did match. Employee " + item.Name + " has been edited.\n");
                                }
                                else
                                {
                                    Console.WriteLine("The passwords did not match. Try again.");
                                    continue;
                                }

                                if (!LoginAndValidation.ValidatePasswordInput(newPassword))

                                {
                                    Console.WriteLine("Incorrect validation");
                                    continue;
                                }



                                break;
                            }
                        }
                        else if (inputNumber == "3")
                        {
                            while (true)
                            {
                                Console.WriteLine(item.Address);
                                Console.WriteLine("Enter a new address:");
                                string newAddress = Console.ReadLine();

                                if (!LoginAndValidation.ValidateInput(newAddress))

                                {
                                    Console.WriteLine("Incorrect validation");
                                    continue;
                                }
                                Console.WriteLine("Employee " + item.Address + " has been edited.\n");
                                item.Address = newAddress;

                                break;
                            }
                        }

                        break;
                    }
                }
                i++;
            }

            Console.Clear();
            if (inputNumber == "4")
            {
                Console.WriteLine("Editing complete. No changes were made. Press any key to exit.");
            }
            else
            {
                Console.WriteLine(inputName + " has been edited successfully. Press any key to exit.");
            }
            Console.ReadKey();
            Console.WriteLine();
            Console.Clear();

            return(newName);
        }
コード例 #2
0
        public static void EditEmployee(string inputName, List <object> EmployeeList)
        {
            Console.Clear();
            Console.WriteLine("What is the name of the Employee you want to edit?");

            foreach (Employee item in EmployeeList)
            {
                Console.WriteLine(item.Name);
            }

            string editEmployee = Console.ReadLine();
            int    i            = 0;
            string inputNumber  = "";

            foreach (Employee item in EmployeeList)

            {
                if (item.Name == editEmployee)
                {
                    Console.Clear();
                    Console.WriteLine(
                        "Write 1 to edit name. \n" +
                        "Write 2 to edit password. \n" +
                        "Write 3 to edit address.\n" +
                        "Write 4 to change admin status. \n" +
                        "Write 5 to exit. \n");

                    inputNumber = Console.ReadLine();

                    while (true)
                    {
                        if (inputNumber == "1")
                        {
                            while (true)
                            {
                                Console.WriteLine(item.Name);
                                Console.WriteLine("Enter a new name:");
                                string newName = Console.ReadLine();

                                if (!LoginAndValidation.ValidateInput(newName))

                                {
                                    Console.WriteLine("Incorrect validation");
                                    continue;
                                }
                                Console.WriteLine("Employee " + item.Name + " has been edited.\n");
                                item.Name = newName;

                                break;
                            }
                        }
                        else if (inputNumber == "2")
                        {
                            while (true)
                            {
                                Console.WriteLine("Edit password:"******"Incorrect validation");
                                    continue;
                                }

                                string inputPassword = Encryptor.MD5Hash(newPassword);
                                item.Password = inputPassword;
                                Console.WriteLine("Employee " + item.Name + " has been edited.\n");

                                break;
                            }
                        }
                        else if (inputNumber == "3")
                        {
                            while (true)
                            {
                                Console.WriteLine(item.Address);
                                Console.WriteLine("Enter a new address:");
                                string newAddress = Console.ReadLine();

                                if (!LoginAndValidation.ValidateInput(newAddress))

                                {
                                    Console.WriteLine("Incorrect validation");
                                    continue;
                                }
                                Console.WriteLine("Employee " + item.Address + " has been edited.\n");
                                item.Address = newAddress;

                                break;
                            }
                        }
                        else if (inputNumber == "4")
                        {
                            while (true)
                            {
                                Console.WriteLine(item.IsAdmin);
                                Console.WriteLine("Enter true or false to change admin status.");
                                string newAdminStatus = Console.ReadLine();

                                if (!LoginAndValidation.ValidateBoolInput(newAdminStatus))

                                {
                                    Console.WriteLine("Incorrect validation");
                                    continue;
                                }
                                Console.WriteLine("Employee " + item.Address + " has been edited.\n");
                                item.IsAdmin = bool.Parse(newAdminStatus);

                                break;
                            }
                        }

                        break;
                    }
                }
                i++;
            }

            Console.Clear();
            if (inputNumber == "5")
            {
                Console.WriteLine("Editing complete. No changes were made. Press any key to exit.");
            }
            else
            {
                Console.WriteLine(editEmployee + " has been edited successfully. Press any key to exit.");
            }
            Console.ReadKey();
            Console.WriteLine();
            Console.Clear();
        }