Exemplo n.º 1
0
        public static PersonNameVO Create(string firstName, string lastName)
        {
            var instance = new PersonNameVO {
                FirstName = firstName, LastName = lastName
            };

            ValidateInstance(instance);

            return(instance);
        }
Exemplo n.º 2
0
        public static void ValidateInstance(PersonNameVO personName)
        {
            // Validations goes here

            if (
                string.IsNullOrWhiteSpace(personName.FirstName)
                ||
                string.IsNullOrWhiteSpace(personName.LastName)
                ||
                !Enumerable.Range(2, 50).Contains(personName.FirstName.Length)
                ||
                !Enumerable.Range(2, 50).Contains(personName.LastName.Length)
                ||
                !Regex.Match(personName.FirstName, "^([a-zA-Z]+|[ა-ჰ]+)$", RegexOptions.IgnoreCase).Success
                ||
                !Regex.Match(personName.LastName, "^([a-zA-Z]+|[ა-ჰ]+)$", RegexOptions.IgnoreCase).Success
                )
            {
                throw new DomainException(DomainExceptionCode.InvalidPersonName);
            }
        }