public static ValidatorResult ValidatePassword(UserRegisterDTO user)
        {
            ValidatorResult validatorResult = new ValidatorResult(true);

            bool passwordContainsUsername = user.Password.IndexOf(user.Username, StringComparison.OrdinalIgnoreCase) >= 0;

            if (passwordContainsUsername && user.Username.Length >= 3)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "Password could not contains the username.";
                return(validatorResult);
            }

            validatorResult = PasswordContainsFullName(user.Password, user.FullName);

            if (!validatorResult.IsValid)
            {
                return(validatorResult);
            }

            Regex regex = new Regex(@"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$");
            Match match = regex.Match(user.Password);

            if (!match.Success)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "Password must contain at less one Upper case letter, one lower case letter, one digit number and one special symbol.";
                return(validatorResult);
            }

            return(validatorResult);
        }
        public static ValidatorResult IsValidCourseCustomer(CourseCustomerCastDTO courseCustomerCast)
        {
            ValidatorResult validatorResult = new ValidatorResult(true);

            if (courseCustomerCast == null)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The courseCustomerCast is null.";
                return(validatorResult);
            }

            if (courseCustomerCast.CourseId == 0)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The courseId is required.";
                return(validatorResult);
            }
            if (courseCustomerCast.CustomerId.Trim().Equals(""))
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The customerId is required.";
                return(validatorResult);
            }
            return(validatorResult);
        }
        public static ValidatorResult IsValidUser(UserRegisterDTO user)
        {
            ValidatorResult validatorResult = new ValidatorResult(true);

            if (user == null)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The user is null.";
                return(validatorResult);
            }
            if (user.FullName.Trim().Equals(""))
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The user Full name is required.";
                return(validatorResult);
            }
            if (user.Username.Trim().Equals(""))
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The user username is required.";
                return(validatorResult);
            }
            if (user.Password.Trim().Equals(""))
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The user password is required.";
                return(validatorResult);
            }
            if (user.CustomerId.Trim().Equals(""))
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The CustomerId is required.";
                return(validatorResult);
            }
            else if (user.Password.Trim().Length < 8)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The user Password length must be at less 8 characters.";
                return(validatorResult);
            }
            else
            {
                var passwordValidatorResult = PasswordValidator.ValidatePassword(user);
                if (!passwordValidatorResult.IsValid)
                {
                    return(passwordValidatorResult);
                }
            }
            return(validatorResult);
        }
        public static ValidatorResult IsValidCourse(CourseDTO course)
        {
            ValidatorResult validatorResult = new ValidatorResult(true);

            if (course == null)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The course is null.";
                return(validatorResult);
            }

            if (course.Name.Trim().Equals(""))
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The course name is required.";
                return(validatorResult);
            }
            if (course.Description.Trim().Equals(""))
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The course description is required.";
                return(validatorResult);
            }
            if (course.Length == 0)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The course length is required.";
                return(validatorResult);
            }
            if (!course.StartDate.HasValue)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The user start date is required.";
                return(validatorResult);
            }
            if (!course.EndDate.HasValue)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "The user end date is required.";
                return(validatorResult);
            }
            return(validatorResult);
        }
        private static ValidatorResult PasswordContainsFullName(string password, string fullName)
        {
            ValidatorResult validatorResult = new ValidatorResult(true);

            bool passwordContainsFullName = password.IndexOf(fullName, StringComparison.OrdinalIgnoreCase) >= 0;

            if (passwordContainsFullName && fullName.Length >= 3)
            {
                validatorResult.IsValid           = false;
                validatorResult.ValidationMessage = "Password could not contains the full Name.";
                return(validatorResult);
            }

            var splitWithComma      = fullName.Split(',');
            var splitWithPeriod     = fullName.Split('.');
            var splitWithDashes     = fullName.Split('-');
            var splitWithunderscore = fullName.Split('_');
            var splitWithSpase      = fullName.Split(' ');

            for (int i = 0; i < splitWithComma.Length; i++)
            {
                bool containsStr = password.IndexOf(splitWithComma[i], StringComparison.OrdinalIgnoreCase) >= 0;
                if (containsStr && splitWithComma[i].Length >= 3)
                {
                    validatorResult.IsValid           = false;
                    validatorResult.ValidationMessage = "Password could not contains part of the Full name";
                    return(validatorResult);
                }
            }

            for (int i = 0; i < splitWithPeriod.Length; i++)
            {
                bool containsStr = password.IndexOf(splitWithPeriod[i].Trim(), StringComparison.OrdinalIgnoreCase) >= 0;
                if (containsStr && splitWithPeriod[i].Trim().Length >= 3)
                {
                    validatorResult.IsValid           = false;
                    validatorResult.ValidationMessage = "Password could not contains part of the Full name";
                    return(validatorResult);
                }
            }

            for (int i = 0; i < splitWithDashes.Length; i++)
            {
                bool containsStr = password.IndexOf(splitWithDashes[i].Trim(), StringComparison.OrdinalIgnoreCase) >= 0;
                if (containsStr && splitWithDashes[i].Trim().Length >= 3)
                {
                    validatorResult.IsValid           = false;
                    validatorResult.ValidationMessage = "Password could not contains part of the Full name";
                    return(validatorResult);
                }
            }


            for (int i = 0; i < splitWithunderscore.Length; i++)
            {
                bool containsStr = password.IndexOf(splitWithunderscore[i].Trim(), StringComparison.OrdinalIgnoreCase) >= 0;
                if (containsStr && splitWithunderscore[i].Trim().Length >= 3)
                {
                    validatorResult.IsValid           = false;
                    validatorResult.ValidationMessage = "Password could not contains part of the Full name";
                    return(validatorResult);
                }
            }

            for (int i = 0; i < splitWithSpase.Length; i++)
            {
                bool containsStr = password.IndexOf(splitWithSpase[i].Trim(), StringComparison.OrdinalIgnoreCase) >= 0;
                if (containsStr && splitWithSpase[i].Trim().Length >= 3)
                {
                    validatorResult.IsValid           = false;
                    validatorResult.ValidationMessage = "Password could not contains part of the Full name";
                    return(validatorResult);
                }
            }

            return(validatorResult);
        }