Exemplo n.º 1
0
        public BaseModelValidationResult Validate()
        {
            var validationResult = new BaseModelValidationResult();

            if (string.IsNullOrWhiteSpace(Name))
            {
                validationResult.Append($"Name cannot be empty");
            }
            if (string.IsNullOrWhiteSpace(SurName))
            {
                validationResult.Append($"Surname cannot be empty");
            }
            if (!(0 < Age && Age < 100))
            {
                validationResult.Append($"Age {Age} is out of range (0..100)");
            }

            if (!string.IsNullOrEmpty(Name) && !char.IsUpper(Name.FirstOrDefault()))
            {
                validationResult.Append($"Name {Name} should start from capital letter");
            }
            if (!string.IsNullOrEmpty(SurName) && !char.IsUpper(SurName.FirstOrDefault()))
            {
                validationResult.Append($"Surname {SurName} should start from capital letter");
            }

            return(validationResult);
        }
Exemplo n.º 2
0
        public BaseModelValidationResult Validate()
        {
            var validationResult = new BaseModelValidationResult();

            if (string.IsNullOrWhiteSpace(Name))
            {
                validationResult.Append($"Name cannot be empty");
            }
            else
            {
                if (!char.IsUpper(Name.FirstOrDefault()))
                {
                    validationResult.Append($"Name {Name} should start from capital letter");
                }
            }
            if (string.IsNullOrWhiteSpace(SurName))
            {
                validationResult.Append($"SurName cannot be empty");
            }
            else
            {
                if (!char.IsUpper(SurName.FirstOrDefault()))
                {
                    validationResult.Append($"SurName {SurName} should start from capital letter");
                }
            }
            if (Age < 18)
            {
                validationResult.Append($"FullYears should not be under 18");
            }
            return(validationResult);
        }