Beispiel #1
0
        private void CreateCustomer()
        {
            Console.WriteLine("Enter your First Name");
            var firstName = Console.ReadLine();

            Console.WriteLine("Enter your Last Name");
            var lastName = Console.ReadLine();

            Console.WriteLine("Enter your Email");
            var email = Console.ReadLine();

            while (!email.Contains("@"))
            {
                Console.WriteLine("Email is not valid. Enter a valid email.");
                email = Console.ReadLine();
            }
            while (_customerRepository.GetCustomerEmail(email))
            {
                Console.WriteLine("This email already exists. Enter a non existing email.");
                email = Console.ReadLine();
            }

            Console.WriteLine("Enter your User Name");
            var userName = Console.ReadLine();

            while (userName != userName.ToLower())
            {
                Console.WriteLine("User name should be in lower cases");
                userName = Console.ReadLine();
            }

            Console.WriteLine("Enter your date of birth \n Year");
            var year = int.Parse(Console.ReadLine());

            Console.WriteLine("Month");
            var month = int.Parse(Console.ReadLine());

            Console.WriteLine("Day");
            var day = int.Parse(Console.ReadLine());


            while (!DateOfBirth.DateValidation(day, month, year))
            {
                Console.WriteLine("Date of brth is not correct");
                Console.WriteLine("Year");
                year = int.Parse(Console.ReadLine());
                Console.WriteLine("Month");
                month = int.Parse(Console.ReadLine());
                Console.WriteLine("Day");
                day = int.Parse(Console.ReadLine());
            }

            var      date        = $"{year}/{month}/{day}";
            DateTime dateOfBirth = Convert.ToDateTime(date);

            string password;
            string password1;

            Console.WriteLine("Create a password");
            password = Console.ReadLine();
            var regex = new Regex(@"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{12,}$");

            while (!regex.Match(password).Success)
            {
                Console.WriteLine("Password is not according to standards. Create a password");
                password = Console.ReadLine();
            }

            do
            {
                Console.WriteLine("Repeat your password");
                password1 = Console.ReadLine();

                if (password != password1)
                {
                    Console.WriteLine("Passowrd does not match");
                }
            } while (password != password1);

            customer         = _customerService.CreateCustomer(firstName, lastName, email, userName, password, dateOfBirth.Date);
            _isAuthenticated = true;


            Console.WriteLine("You registered successfuly.");

            RegistrationEmail.SendRegistrationEmail(email);
        }