Пример #1
0
        public void Validate(string fieldName, dynamic fieldValue)
        {
            if (fieldValue != null)
            {
                switch (fieldValue.GetType())
                {
                case Type a when(a == typeof(int) || a == typeof(int?) && a.GetType() == _valueToComare.GetType()):
                case Type b when(b == typeof(uint) || b == typeof(uint?) && b.GetType () == _valueToComare.GetType()):
                case Type c when(c == typeof(long) || c == typeof(long?) && c.GetType () == _valueToComare.GetType()):
                case Type d when(d == typeof(ulong) || d == typeof(ulong?) && d.GetType () == _valueToComare.GetType()):
                case Type e when(e == typeof(short) || e == typeof(short?) && e.GetType () == _valueToComare.GetType()):
                case Type f when(f == typeof(ushort) || f == typeof(ushort?) && f.GetType () == _valueToComare.GetType()):
                case Type g when(g == typeof(double) || g == typeof(double?) && g.GetType () == _valueToComare.GetType()):
                case Type h when(h == typeof(decimal) || h == typeof(decimal?) && h.GetType () == _valueToComare.GetType()):
                case Type i when(i == typeof(byte) || i == typeof(byte?) && i.GetType () == _valueToComare.GetType()):
                case Type j when(j == typeof(sbyte) || j == typeof(sbyte?) && j.GetType () == _valueToComare.GetType()):
                    if ((fieldValue == null && fieldValue != _valueToComare) || fieldValue < _valueToComare)
                    {
                        _roleBuilder.AddErrorMessage(fieldName, RuleValidationMessage.GreaterThanOrEqual(fieldName, fieldValue));
                    }

                    break;

                default:
                    throw new Exception("The property's type isn't allowed in method GreaterThanOrEqual of class Validation.");
                }
            }
        }
Пример #2
0
        public void Validate(string fieldName, dynamic fieldValue)
        {
            if (fieldValue != null)
            {
                var message = RuleValidationMessage.Numeric(fieldName);

                Regex regex = new Regex(@"^\d+$");

                if (!regex.IsMatch(fieldValue))
                {
                    _roleBuilder.AddErrorMessage(fieldName, message);
                }
            }
        }
Пример #3
0
        public void Validate(string fieldName, dynamic fieldValue)
        {
            var isInvalid = false;
            var message   = RuleValidationMessage.NotNull(fieldName);

            if (fieldValue is null)
            {
                isInvalid = true;
            }

            if (isInvalid)
            {
                _roleBuilder.AddErrorMessage(fieldName, message);
            }
        }
Пример #4
0
        public void Validate(string fieldName, dynamic fieldValue)
        {
            if (fieldValue != null)
            {
                if (fieldValue.GetType() == typeof(string))
                {
                    var caracteres    = ((string)fieldValue)?.ToArray();
                    var regex         = new Regex("^[a-zA-Z0-9 ]*$");
                    var isNumber      = false;
                    var isUpperCase   = false;
                    var isSpecialChar = false;

                    foreach (var item in caracteres ?? new char[] { })
                    {
                        if (_hasNumber && !isNumber)
                        {
                            isNumber = char.IsDigit(item);
                        }

                        if (_hasUpperCase && !isUpperCase)
                        {
                            isUpperCase = char.IsUpper(item);
                        }

                        if (_hasSpecialChar && !isSpecialChar)
                        {
                            isSpecialChar = !regex.IsMatch(item.ToString());
                        }
                    }

                    if (_hasNumber && !isNumber)
                    {
                        _roleBuilder.AddErrorMessage(fieldName, RuleValidationMessage.PasswordNumericChar(fieldName));
                    }

                    if (_hasUpperCase && !isUpperCase)
                    {
                        _roleBuilder.AddErrorMessage(fieldName, RuleValidationMessage.PasswordUpperCaseChar(fieldName));
                    }

                    if (_hasSpecialChar && !isSpecialChar)
                    {
                        _roleBuilder.AddErrorMessage(fieldName, RuleValidationMessage.PasswordSpecialChar(fieldName));
                    }
                }
            }
        }
Пример #5
0
        public void Validate(string fieldName, dynamic fieldValue)
        {
            if (fieldValue != null)
            {
                var message = RuleValidationMessage.Email(fieldName);

                if (fieldValue.GetType() == typeof(string))
                {
                    try
                    {
                        MailAddress m = new MailAddress(fieldValue);
                    }
                    catch
                    {
                        _roleBuilder.AddErrorMessage(fieldName, message);
                    }
                }
            }
        }
Пример #6
0
        public void Validate(string fieldName, dynamic fieldValue)
        {
            if (fieldValue != null)
            {
                var message   = RuleValidationMessage.MaxLength(fieldName, _maxLength);
                var isInvalid = false;

                if (fieldValue.GetType() == typeof(string))
                {
                    if (fieldValue == null || fieldValue.Length > _maxLength)
                    {
                        isInvalid = true;
                    }
                }

                if (isInvalid)
                {
                    _roleBuilder.AddErrorMessage(fieldName, message);
                }
            }
        }
Пример #7
0
        public void Validate(string fieldName, dynamic fieldValue)
        {
            var isInvalid = false;
            var message   = RuleValidationMessage.Required(fieldName);

            if (fieldValue is null)
            {
                isInvalid = true;
            }
            else
            {
                switch (fieldValue.GetType())
                {
                case Type x when x == typeof(string):
                    if (string.IsNullOrWhiteSpace(fieldValue))
                    {
                        isInvalid = true;
                    }
                    break;

                case Type a when a == typeof(int?):
                case Type b when b == typeof(uint?):
                case Type c when c == typeof(long?):
                case Type d when d == typeof(ulong?):
                case Type e when e == typeof(short?):
                case Type f when f == typeof(ushort?):
                case Type g when g == typeof(double?):
                case Type h when h == typeof(decimal?):
                case Type i when i == typeof(byte?):
                case Type j when j == typeof(sbyte?):
                case Type k when k == typeof(char?):
                case Type l when l == typeof(bool?):
                    if (fieldValue == null)
                    {
                        isInvalid = true;
                    }
                    break;

                case Type x when(x == typeof(Guid) || x == typeof(Guid?)):
                    if (fieldValue == Guid.Empty || fieldValue == null)
                    {
                        isInvalid = true;
                    }

                    break;

                case Type x when x == typeof(int):
                    isInvalid = (int)fieldValue == default;
                    break;

                case Type x when x == typeof(uint):
                    isInvalid = (uint)fieldValue == default;
                    break;

                case Type x when x == typeof(long):
                    isInvalid = (long)fieldValue == default;
                    break;

                case Type x when x == typeof(ulong):
                    isInvalid = (ulong)fieldValue == default;
                    break;

                case Type x when x == typeof(short):
                    isInvalid = (short)fieldValue == default;
                    break;

                case Type x when x == typeof(ushort):
                    isInvalid = (ushort)fieldValue == default;
                    break;

                case Type x when x == typeof(double):
                    isInvalid = (double)fieldValue == default;
                    break;

                case Type x when x == typeof(decimal):
                    isInvalid = (decimal)fieldValue == default;
                    break;

                case Type x when x == typeof(byte):
                    isInvalid = (byte)fieldValue == default;
                    break;

                case Type x when x == typeof(sbyte):
                    isInvalid = (sbyte)fieldValue == default;
                    break;

                case Type x when x == typeof(char):
                    isInvalid = (char)fieldValue == default;
                    break;

                case Type x when x == typeof(bool):
                    isInvalid = (bool)fieldValue == default;
                    break;
                }
            }

            if (isInvalid)
            {
                _roleBuilder.AddErrorMessage(fieldName, message);
            }
        }