예제 #1
0
        public override string Validate(string propertyName)
        {
            if (!DoValidation)
            {
                return(null);
            }

            switch (propertyName)
            {
            case nameof(Login):
                if (Login.IsNullOrWhiteSpace())
                {
                    return(string.Format(Constants.FieldMustBeFilledMessageFormat, nameof(Login)));
                }
                else if (!Login.IsLengthBetween(3, 20))
                {
                    return(string.Format(Constants.LengthErrorMessageFormat, nameof(Login), 3, 20));
                }
                break;

            case nameof(FirstName):
                if (FirstName.IsNullOrWhiteSpace())
                {
                    return(string.Format(Constants.FieldMustBeFilledMessageFormat, nameof(FirstName)));
                }
                else if (!FirstName.IsLengthBetween(3, 20))
                {
                    return(string.Format(Constants.LengthErrorMessageFormat, nameof(FirstName), 3, 20));
                }
                break;

            case nameof(LastName):
                if (LastName.IsNullOrWhiteSpace())
                {
                    return(string.Format(Constants.FieldMustBeFilledMessageFormat, nameof(LastName)));
                }
                else if (!LastName.IsLengthBetween(3, 20))
                {
                    return(string.Format(Constants.LengthErrorMessageFormat, nameof(LastName), 3, 20));
                }
                break;

            case nameof(Position):
                if (Position == null)
                {
                    return(string.Format(Constants.FieldMustBeFilledMessageFormat, nameof(Position)));
                }
                break;

            case nameof(Birthday):
                if (Birthday.IsNullOrWhiteSpace())
                {
                    return(string.Format(Constants.FieldMustBeFilledMessageFormat, nameof(Birthday)));
                }
                else if (DateTime.Parse(Birthday) < new DateTime(1900, 1, 1) || DateTime.Parse(Birthday) > new DateTime(2005, 1, 1))
                {
                    return(Constants.DateMustBeCorrectMessage);
                }
                break;
            }
            return(null);
        }