Beispiel #1
0
        public static void AddEmployee(List <object> EmployeeList)

        {
            string newName     = "";
            string newAddress  = "";
            string newPassword = "";
            string isAdmin     = "";

            while (true)
            {
                Console.WriteLine("What is the name of the Employee?");
                newName = Console.ReadLine();
                Console.WriteLine("What is the address of the Employee?");
                newAddress = Console.ReadLine();
                Console.WriteLine("What is the password of the Employee?");
                newPassword = Console.ReadLine();
                Console.WriteLine("Is the Employee an admin? true/false");
                isAdmin = Console.ReadLine();



                if (!LoginAndValidation.ValidateInput(newName) ||
                    !LoginAndValidation.ValidateInput(newAddress) ||
                    !LoginAndValidation.ValidateInput(newPassword))
                {
                    Console.WriteLine("Incorrect validation");
                    continue;
                }
                Console.WriteLine("New Employee " + newName + " has been added.\n");
                break;
            }

            string inputPassword = Encryptor.MD5Hash(newPassword);

            Employee newEmployee = new Employee();

            //Här nedan så skapar jag ett Guid och använder sedan dess värde som en sträng för id.
            var    originalGuid = Guid.NewGuid();
            string stringGuid   = originalGuid.ToString("B");

            var charsToRemove = new string[] { "{", "}" };

            foreach (var c in charsToRemove)
            {
                stringGuid = stringGuid.Replace(c, string.Empty);
            }

            newEmployee.Id       = stringGuid;
            newEmployee.Name     = newName;
            newEmployee.Password = inputPassword;
            newEmployee.Address  = newAddress;

            if (isAdmin == "true")
            {
                newEmployee.IsAdmin = true;
            }

            EmployeeList.Add(newEmployee);
        }
Beispiel #2
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);
        }
Beispiel #3
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();
        }