public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var configuration = value as Domain.Values.Configuration;
            Check.Require(configuration != null, constraintMessage);

            return !((configuration.TargetVersion != null) && (configuration.NameOfScriptsToRun.Count > 1));
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null)
            {
                return true;
            }
            string strIBAN = value.ToString();
            if (string.IsNullOrEmpty(strIBAN))
            {
                return true;
            }

            string cleanIban;
            if (!GetValidatable(strIBAN, out cleanIban))
            {
                return false;
            }

            if (cleanIban.Length > WorldMaxLength || cleanIban.Length < 2)
            {
                return false;
            }

            string countryCode = cleanIban.Substring(0, 2);
            Regex syntax;
            defs.TryGetValue(countryCode, out syntax);

            if (syntax == null || !syntax.IsMatch(cleanIban))
            {
                return false;
            }

            return IsValidCin(cleanIban);
        }
Esempio n. 3
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            if (value == null)
            {
                return(true);
            }

            try
            {
                double cvalue = Convert.ToDouble(value);
                return(cvalue > Min && cvalue < Max);
            }
            catch (InvalidCastException)
            {
                if (value is char)
                {
                    int i = Convert.ToInt32(value);
                    return(i > Min && i < Max);
                }
                return(false);
            }
            catch (FormatException)
            {
                return(false);
            }
            catch (OverflowException)
            {
                return(false);
            }
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var isValid = true;
            var categoriaInvestigador = value as CategoriaInvestigador;
            if (categoriaInvestigador != null)
            {
                if (categoriaInvestigador.FechaInicial <= DateTime.Parse("1910-01-01"))
                {
                    constraintValidatorContext.DisableDefaultError();
                    constraintValidatorContext.AddInvalid<CategoriaInvestigador, DateTime>(
                        "fecha inicial inválida o nula|FechaInicial", x => x.FechaInicial);
                    isValid = false;
                }

                if (categoriaInvestigador.FechaFinal <= DateTime.Parse("1910-01-01"))
                {
                    constraintValidatorContext.DisableDefaultError();
                    constraintValidatorContext.AddInvalid<CategoriaInvestigador, DateTime>(
                        "fecha final inválida o nula|FechaFinal", x => x.FechaFinal);
                    isValid = false;
                }
                else if (categoriaInvestigador.FechaInicial >= categoriaInvestigador.FechaFinal)
                {
                    constraintValidatorContext.DisableDefaultError();
                    constraintValidatorContext.AddInvalid<CategoriaInvestigador, DateTime>(
                        "fecha inicial debe ser menor a fecha final|FechaInicial", x => x.FechaInicial);
                    constraintValidatorContext.AddInvalid<CategoriaInvestigador, DateTime>(
                        "fecha final debe ser mayor a fecha inicial|FechaFinal", x => x.FechaFinal);
                    isValid = false;
                }
            }

            return isValid;
        }
Esempio n. 5
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var isValid = true;
            var firma = value as Firma;
            if (firma != null)
            {
                if (firma.TipoProducto == 3 || firma.TipoProducto == 13 || firma.TipoProducto == 14)
                {
                    if (firma.Aceptacion2 == 1)
                    {
                        if (firma.PuntuacionSieva == 0)
                        {
                            constraintValidatorContext.DisableDefaultError();
                            constraintValidatorContext.AddInvalid<Firma, decimal>(
                                "no debe ser vacío|PuntuacionSieva", x => x.PuntuacionSieva);
                            isValid = false;
                        }
                    }
                }

                if (firma.Aceptacion2 == 2 && firma.Descripcion == String.Empty)
                {
                    constraintValidatorContext.DisableDefaultError();
                    constraintValidatorContext.AddInvalid<Firma, string>(
                        "no debe ser vacío|Descripcion", x => x.Descripcion);
                    isValid = false;
                }
            }

            return isValid;
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var isValid = true;
            var producto = value as ProductoGeneradoProyecto;
            if (producto != null)
            {
                if (producto.ProductoGenerado == 0)
                {
                    constraintValidatorContext.DisableDefaultError();
                    constraintValidatorContext.AddInvalid<ProductoGeneradoProyecto, int>(
                        "seleccione el tipo de producto generado|ProductoGenerado", x => x.ProductoGenerado);
                    isValid = false;
                }

                if (producto.FechaEntrega <= DateTime.Parse("1910-01-01"))
                {
                    constraintValidatorContext.DisableDefaultError();
                    constraintValidatorContext.AddInvalid<ProductoGeneradoProyecto, DateTime>(
                        "formato de fecha no válido|FechaEntrega", x => x.FechaEntrega);

                    isValid = false;
                }

                if (producto.FechaEntrega > DateTime.Now)
                {
                    constraintValidatorContext.DisableDefaultError();
                    constraintValidatorContext.AddInvalid<ProductoGeneradoProyecto, DateTime>(
                        "el año no puede estar en el futuro|FechaEntrega", x => x.FechaEntrega);

                    isValid = false;
                }
            }

            return isValid;
        }
Esempio n. 7
0
        public bool IsValid(object value,IConstraintValidatorContext constraintContext)
        {
            if (value == null) return true;
            String codiceFiscale = value.ToString();
            if (string.IsNullOrEmpty(codiceFiscale)) return true;
            codiceFiscale = codiceFiscale.Trim().ToUpper();
            // il codice fiscale DEVE essere composto da 16 caratteri.
            if (codiceFiscale.Length != 16) return false;

            // per il calcolo del check digit e la conversione in numero
            const string listaControllo = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            int[] listaCodiciPari = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };
            int[] listaCodiciDispari = { 1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 2, 4, 18, 20, 11, 3, 6, 8, 12, 14, 16, 10, 22, 25, 24, 23 };

            int somma = 0;
            char[] caratteriChar = codiceFiscale.ToCharArray();
            for (int i = 0; i < 15; i++)
            {
                char c = caratteriChar[i];
                int x = "0123456789".IndexOf(c);
                if (x != -1)
                    c = listaControllo[x];

                x = listaControllo.IndexOf(c);
                // Verifico che sia pari. Partendo da 0 il controllo è "scombinato"
                if ((i % 2) == 0)
                    x = listaCodiciDispari[x];
                else
                    x = listaCodiciPari[x];
                somma += x;
            }

            return (listaControllo[somma % 26] == codiceFiscale[15]);
        }
Esempio n. 8
0
 public bool IsValid(object value, IConstraintValidatorContext context)
 {
     var o = (ITipp)value;
     if (o.SID != o.Tippzahlen.Count) {
         context.DisableDefaultError();
         context.AddInvalid<ITipp, IList<int>>(String.Format(
             "number '{0}' should match SID '{1}'", o.Tippzahlen.Count, o.SID), x => o.Tippzahlen);
         return false;
     }
     if( 6 > o.SID || 13 < o.SID ){
         context.DisableDefaultError();
         context.AddInvalid<ITipp, int>(String.Format(
             "'{0}' should be between 6 and 13", o.SID), x => o.SID);
         return false;
     }
     // quick fix: if 6 < SID <14 && Tippzahlen.Count > SID (!) bad IDs are generated
     if (!Stringifier.stringify(o.Tippzahlen).Equals((value as ATipp).Id)) {
         context.DisableDefaultError();
         context.AddInvalid<ITipp, IList<int>>(String.Format(
             "number should match SID '{0}'", o.SID), x => o.Tippzahlen);
         return false;
     }
     if (o.Tippzahlen.Distinct().Count() != o.Tippzahlen.Count) {
         context.DisableDefaultError();
         context.AddInvalid("should be unique");
         return false;
     }
     if (o.Tippzahlen.Any(x => x < 1 || x > 49)) {
         context.DisableDefaultError();
         context.AddInvalid("should be between 1 and 49");
         return false;
     }
     return true;
 }
Esempio n. 9
0
        public bool IsValid(object value, IConstraintValidatorContext context)
        {
            context.DisableDefaultError();

            string name = value as string;

            if (name == null)
            {
                return(true);
            }

            if (name.Length < 2)
            {
                context.AddInvalid("The name should have at least 2 letters.");
            }

            if (name.Length > 0)
            {
                char firstLetter = name[0];

                bool isLower = firstLetter.ToString() == firstLetter.ToString().ToLower();
                context.AddInvalid("The name should begin with Upper Case.");
                if (isLower)
                {
                    return(false);
                }
            }

            return(true);
        }
 public bool IsValid(object value, IConstraintValidatorContext validatorContext)
 {
     if (value == null)
     {
         return(true);
     }
     try
     {
         return(Convert.ToDecimal(value) >= Value);
     }
     catch (InvalidCastException)
     {
         if (value is char)
         {
             return(Convert.ToInt32(value) >= Value);
         }
         return(false);
     }
     catch (FormatException)
     {
         return(false);
     }
     catch (OverflowException)
     {
         return(false);
     }
 }
Esempio n. 11
0
        public bool IsValid(object value, IConstraintValidatorContext validatorContext)
        {
            if (value == null)
            {
                return true;
            }

            int count = 0;
            var collection = value as ICollection;
            if (collection != null)
            {
                count = collection.Count;
            }
            else
            {
                var enumerable = value as IEnumerable;
                if (ReferenceEquals(null, enumerable))
                {
                    return false;
                }
                var enumerator = enumerable.GetEnumerator();
                while (enumerator.MoveNext() && count <= Max)
                {
                    count++;
                }
            }
            return count >= Min && count <= Max;
        }
Esempio n. 12
0
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null || value.ToString() == string.Empty)
            {
                return(true);
            }

            string cedula = value.ToString();

            if (cedula.Length > 8)
            {
                return(false);
            }

            if (!IsInteger(cedula))
            {
                return(false);
            }

            int[] dvs = new int[] { 2, 9, 8, 7, 6, 3, 4 };

            int sum = 0;

            for (int i = 0; i < cedula.Length - 1; i++)
            {
                int digito = Convert.ToInt32(cedula[i].ToString()) * dvs[i];
                sum += digito % 10;
            }

            return(cedula[cedula.Length - 1].ToString() == Convert.ToString((10 - sum % 10) % 10));
        }
Esempio n. 13
0
 public bool IsValid(object value, IConstraintValidatorContext validatorContext)
 {
     if (value == null)
     {
         return true;
     }
     try
     {
         return Convert.ToDecimal(value) >= Value;
     }
     catch (InvalidCastException)
     {
         if (value is char)
         {
             return Convert.ToInt32(value) >= Value;
         }
         return false;
     }
     catch (FormatException)
     {
         return false;
     }
     catch (OverflowException)
     {
         return false;
     }
 }
Esempio n. 14
0
        public bool IsValid(object value, IConstraintValidatorContext validatorContext)
        {
            if (value == null)
            {
                return(true);
            }

            int count      = 0;
            var collection = value as ICollection;

            if (collection != null)
            {
                count = collection.Count;
            }
            else
            {
                var enumerable = value as IEnumerable;
                if (ReferenceEquals(null, enumerable))
                {
                    return(false);
                }
                var enumerator = enumerable.GetEnumerator();
                while (enumerator.MoveNext() && count <= Max)
                {
                    count++;
                }
            }
            return(count >= Min && count <= Max);
        }
Esempio n. 15
0
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null || value.ToString() == string.Empty)
            {
                return true;
            }

            string cedula = value.ToString();
            if (cedula.Length > 8)
            {
                return false;
            }

            if (!IsInteger(cedula))
            {
                return false;
            }

            int[] dvs = new int[] { 2, 9, 8, 7, 6, 3, 4 };

            int sum = 0;

            for (int i = 0; i < cedula.Length - 1; i++)
            {
                int digito = Convert.ToInt32(cedula[i].ToString()) * dvs[i];
                sum += digito % 10;
            }

            return cedula[cedula.Length-1].ToString() == Convert.ToString((10 - sum % 10) % 10);
        }
Esempio n. 16
0
 protected internal virtual void OptionalValidate(IConstraintValidatorContext context)
 {
     if (Coordinates.IsSpecified &&
         !State.CoordinateBounds.Contains(Coordinates))
     {
         context.AddInvalid($"(Optional) Coordinates appear to fall outside the state's boundaries.  You might want to double check them.", nameof(Coordinates));
     }
 }
Esempio n. 17
0
 public bool IsValid(object value, IConstraintValidatorContext constraintContext)
 {
     if (value == null)
     {
         return(true);
     }
     return(regex.IsMatch(value.ToString()));
 }
Esempio n. 18
0
 protected internal virtual void RequiredValidate(IConstraintValidatorContext context)
 {
     if (IsSpecified && !Height.IsSpecified)
     {
         context.AddInvalid("You must specify proper distance and angle measurements to calculate a height.", nameof(Height));
         context.AddInvalid("You must specify proper distance and angle measurements to calculate an offset.", nameof(Offset));
     }
 }
Esempio n. 19
0
 public virtual void RequiredValidate(IConstraintValidatorContext context)
 {
     if (!Height.IsSpecified && !Girth.IsSpecified && !HeightMeasurements.IsSpecified)
     {
         context.AddInvalid <Trunk, Distance>("You must specify a height or girth.", tm => tm.Girth);
         context.AddInvalid <Trunk, Distance>("You must specify a height or girth.", tm => tm.Height);
     }
 }
Esempio n. 20
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            MethodInfo mi = value.GetType().GetMethod(MethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            constraintValidatorContext.DisableDefaultError();
            mi.Invoke(value, new object[] { constraintValidatorContext });
            return(false);
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext) {
            IEntityWithTypedId<int> entityToValidate = value as IEntityWithTypedId<int>;
            Check.Require(entityToValidate != null,
                "This validator must be used at the class level of an " +
                "IdomainWithTypedId<int>. The type you provided was " + value.GetType().ToString());

            IEntityDuplicateChecker duplicateChecker = SafeServiceLocator<IEntityDuplicateChecker>.GetService();
            return ! duplicateChecker.DoesDuplicateExistWithTypedIdOf<int>(entityToValidate);
        }
        public override bool IsValid(object value, IConstraintValidatorContext validatorContext)
        {
            var ev = value as IEnumerable;
            if (ev != null)
            {
                return ev.GetEnumerator().MoveNext();
            }

            return false;
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            if (value == null)
            {
                return false;
            }

            Check.Require(value is string, "This validator may only be used on a String");
            return (!string.IsNullOrEmpty((value as string).Trim()));
        }
Esempio n. 24
0
        /*
         *  At least one upper case english letter, (?=.*?[A-Z])
         *  At least one lower case english letter, (?=.*?[a-z])
         *  At least one digit, (?=.*?[0-9])
         *  At least one special character, (?=.*?[#?!@$%^&*-])
         *  Minimum 8 in length .{8,} (with the anchors)
         */
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            Regex regex = new Regex(@"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$");

            if (value == null || !(value is string))
            {
                return(false);
            }
            return(regex.IsMatch(value.ToString()));
        }
Esempio n. 25
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            ISpecified obj = value as ISpecified;

            if (obj != null)
            {
                return(obj.IsSpecified);
            }
            return(false);
        }
Esempio n. 26
0
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            var entity = (IDateRangeable) value;

            int result = DateTime.Compare(entity.Start, entity.End);

            if (result == 0 || result > 0)
                return false;

            return true;
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext) {
            IEntityWithTypedId<string> entityToValidate = value as IEntityWithTypedId<string>;
            Check.Require(entityToValidate != null,
                "This validator must be used at the class level of an " +
                "IdomainWithTypedId<string>. The type you provided was " + value.GetType().ToString() + ". " +
                "Other validators exist for various Id types. Please open an issue with S#arp Architecture " +
                "if you need a new Id type supported; you can make your own in the meantime.");

            IEntityDuplicateChecker duplicateChecker = SafeServiceLocator<IEntityDuplicateChecker>.GetService();
            return ! duplicateChecker.DoesDuplicateExistWithTypedIdOf<string>(entityToValidate);
        }
Esempio n. 28
0
 public bool IsValid(object value, IConstraintValidatorContext context)
 {
     var o = (ISitzung)value;
     if (0 == o.Auftraege.Count) {
         context.DisableDefaultError();
         context.AddInvalid<ISitzung, IList<Auftrag>>(
             String.Format("should be at least 1"), x => x.Auftraege);
         return false;
     }
     return true;
 }
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null || value.ToString() == string.Empty)
            {
                return(true);
            }

            string piva = value.ToString().Trim().PadLeft(11, '0');

            if (piva.Length > 11)
            {
                return(false);
            }

            if (!IsInteger(piva))
            {
                return(false);
            }

            if (
                !((int.Parse(piva.Substring(0, 7)) != 0) && (int.Parse(piva.Substring(7, 3)) >= 0) &&
                  (int.Parse(piva.Substring(7, 3)) < 201)))
            {
                return(false);
            }

            int somma = 0;

            for (int i = 0; i < 10; i++)
            {
                int j = int.Parse(piva.Substring(i, 1));

                if ((i + 1) % 2 == 0)
                {
                    j *= 2;
                    char[] c = j.ToString("00").ToCharArray();
                    somma += int.Parse(c[0].ToString());
                    somma += int.Parse(c[1].ToString());
                }
                else
                {
                    somma += j;
                }
            }

            if ((somma.ToString("00").Substring(1, 1) == "0") && (piva.Substring(10, 1) != "0"))
            {
                return(false);
            }

            somma = int.Parse(piva.Substring(10, 1)) + int.Parse(somma.ToString("00").Substring(1, 1));

            return(somma.ToString("00").Substring(1, 1) == "0");
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            IEntityWithTypedId <int> entityToValidate = value as IEntityWithTypedId <int>;

            Check.Require(entityToValidate != null,
                          "This validator must be used at the class level of an " +
                          "IdomainWithTypedId<int>. The type you provided was " + value.GetType().ToString());

            IEntityDuplicateChecker duplicateChecker = SafeServiceLocator <IEntityDuplicateChecker> .GetService();

            return(!duplicateChecker.DoesDuplicateExistWithTypedIdOf <int>(entityToValidate));
        }
Esempio n. 31
0
        /// <summary>
        /// does the object/element pass the constraints
        /// </summary>
        /// <param name="value">Object to be validated</param>
        /// <param name="constraintValidatorContext">Context for the validator constraint</param>
        /// <returns>if the instance is valid</returns>
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var animal = value as Animal;
            if (animal != null && animal.Name == "Horse" && animal.Legs != 2)
            {
                constraintValidatorContext.DisableDefaultError();
                constraintValidatorContext.AddInvalid<Animal, int>("Legs should be two.", a => a.Legs);

                return false;
            }
            return true;
        }
Esempio n. 32
0
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null || value.ToString() == string.Empty)
            {
                return true;
            }

            string piva = value.ToString().Trim().PadLeft(11, '0');
            if (piva.Length > 11)
            {
                return false;
            }

            if (!IsInteger(piva))
            {
                return false;
            }

            if (
                !((int.Parse(piva.Substring(0, 7)) != 0) && (int.Parse(piva.Substring(7, 3)) >= 0)
                  && (int.Parse(piva.Substring(7, 3)) < 201)))
            {
                return false;
            }

            int somma = 0;
            for (int i = 0; i < 10; i++)
            {
                int j = int.Parse(piva.Substring(i, 1));

                if ((i + 1) % 2 == 0)
                {
                    j *= 2;
                    char[] c = j.ToString("00").ToCharArray();
                    somma += int.Parse(c[0].ToString());
                    somma += int.Parse(c[1].ToString());
                }
                else
                {
                    somma += j;
                }
            }

            if ((somma.ToString("00").Substring(1, 1) == "0") && (piva.Substring(10, 1) != "0"))
            {
                return false;
            }

            somma = int.Parse(piva.Substring(10, 1)) + int.Parse(somma.ToString("00").Substring(1, 1));

            return somma.ToString("00").Substring(1, 1) == "0";
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null)
            {
                return(true);
            }
            String codiceFiscale = value.ToString();

            if (string.IsNullOrEmpty(codiceFiscale))
            {
                return(true);
            }
            codiceFiscale = codiceFiscale.Trim().ToUpper();
            // il codice fiscale DEVE essere composto da 16 caratteri.
            if (codiceFiscale.Length != 16)
            {
                return(false);
            }

            // per il calcolo del check digit e la conversione in numero
            const string listaControllo = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            int[] listaCodiciPari    = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };
            int[] listaCodiciDispari = { 1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 2, 4, 18, 20, 11, 3, 6, 8, 12, 14, 16, 10, 22, 25, 24, 23 };

            int somma = 0;

            char[] caratteriChar = codiceFiscale.ToCharArray();
            for (int i = 0; i < 15; i++)
            {
                char c = caratteriChar[i];
                int  x = "0123456789".IndexOf(c);
                if (x != -1)
                {
                    c = listaControllo[x];
                }

                x = listaControllo.IndexOf(c);
                // Verifico che sia pari. Partendo da 0 il controllo è "scombinato"
                if ((i % 2) == 0)
                {
                    x = listaCodiciDispari[x];
                }
                else
                {
                    x = listaCodiciPari[x];
                }
                somma += x;
            }

            return(listaControllo[somma % 26] == codiceFiscale[15]);
        }
Esempio n. 34
0
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            var entity = (IDateRangeable)value;

            int result = DateTime.Compare(entity.Start, entity.End);

            if (result == 0 || result > 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 35
0
        /// <summary>
        /// does the object/element pass the constraints
        /// </summary>
        /// <param name="value">Object to be validated</param>
        /// <param name="constraintValidatorContext">Context for the validator constraint</param>
        /// <returns>if the instance is valid</returns>
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var animal = value as Animal;

            if (animal != null && animal.Name == "Horse" && animal.Legs != 2)
            {
                constraintValidatorContext.DisableDefaultError();
                constraintValidatorContext.AddInvalid <Animal, int>("Legs should be two.", a => a.Legs);

                return(false);
            }
            return(true);
        }
        public bool IsValid(object value, IConstraintValidatorContext validatorContext)
        {
            if (value == null)
            {
                return(true);
            }

            var tp = value.GetType();

            return(tp.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0
                                ? IsFlagsValid(tp, (long)Convert.ChangeType(value, typeof(long)))
                                : Enum.IsDefined(tp, value));
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var check = new Regex(@"^\d{2}-\d{3}$", RegexOptions.Compiled);

            if (value == null)
                return true;

            string postalCode = value.ToString();

            if (postalCode == string.Empty)
                return true;

            return check.IsMatch(postalCode);
        }
Esempio n. 38
0
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null)
            {
                return(true);
            }

            if (value is DateTime)
            {
                return(DateTime.Now.CompareTo(value) > 0);
            }

            return(false);
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null)
            {
                return true;
            }

            if (value is DateTime)
            {
                return DateTime.Now.CompareTo(value) < 0;
            }

            return false;
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null)
            {
                return(false);
            }

            if (value is bool)
            {
                return(!(bool)value);
            }

            return(false);
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null)
            {
                return false;
            }

            if (value is bool)
            {
                return (bool)value;
            }

            return false;
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            IEntityWithTypedId <string> entityToValidate = value as IEntityWithTypedId <string>;

            Check.Require(entityToValidate != null,
                          "This validator must be used at the class level of an " +
                          "IdomainWithTypedId<string>. The type you provided was " + value.GetType().ToString() + ". " +
                          "Other validators exist for various Id types. Please open an issue with S#arp Architecture " +
                          "if you need a new Id type supported; you can make your own in the meantime.");

            IEntityDuplicateChecker duplicateChecker = SafeServiceLocator <IEntityDuplicateChecker> .GetService();

            return(!duplicateChecker.DoesDuplicateExistWithTypedIdOf <string>(entityToValidate));
        }
        public bool IsValid(object value, IConstraintValidatorContext validatorContext)
        {
            if (value == null)
            {
                return true;
            }

            var collection = value as ICollection;
            if (collection == null)
            {
                return false;
            }

            return collection.Count >= Min && collection.Count <= Max;
        }
 //- uniqueness
 //- range
 public bool IsValid(object value, IConstraintValidatorContext context)
 {
     var entity = (Tippzahlen)value;
     if (entity.Distinct().Count() != entity.Count) {
         context.DisableDefaultError();
         context.AddInvalid("should be unique");
         return false;
     }
     if (entity.Where(x => x < 1 || x > 49).Any()) {
         context.DisableDefaultError();
         context.AddInvalid("should be between 1 and 49");
         return false;
     }
     return true;
 }
 private static bool ValidateChild(ChildEntityWithAttributeRules entity, IConstraintValidatorContext context)
 {
     if (entity.IsWordMonkeyAllowedInName)
     {
         return(true);
     }
     else if (entity.Name == null)
     {
         return(true);
     }
     else
     {
         return(!entity.Name.ToLowerInvariant().Contains("monkey"));
     }
 }
Esempio n. 46
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            if (value == null)
                return true;

            string regon = value.ToString();

            if (regon == string.Empty)
                return true;

            if (!HasValidFormat(regon))
                return false;

            return HasValidChecksum(regon);
        }
Esempio n. 47
0
        public override bool IsValid(object value, IConstraintValidatorContext validatorContext)
        {
            if (value is Guid)
            {
                return !Guid.Empty.Equals(value);
            }

            var ev = value as IEnumerable;
            if (ev != null)
            {
                return ev.Any();
            }

            return false;
        }
Esempio n. 48
0
        public bool IsValid(object value, IConstraintValidatorContext context)
        {
            var o = (IAuftrag)value;
            if (!Regex.IsMatch(o.Zusatzchance.Losnummer, @"^\d{7}$"))
                throw new BusinessException(String.Format(
                    "ISchein.Losnummer, '{0}', should be 7 numerals", o.Zusatzchance.Losnummer));

            if (0 == o.Tipps.Count) {
                context.DisableDefaultError();
                context.AddInvalid<IAuftrag, IList<IIndexedTipp>>(
                    String.Format("should be at least 1"), x => x.Tipps);
                return false;
            }
            return true;
        }
Esempio n. 49
0
        public override bool IsValid(object value, IConstraintValidatorContext validatorContext)
        {
            if (value is Guid)
            {
                return(!Guid.Empty.Equals(value));
            }

            var ev = value as IEnumerable;

            if (ev != null)
            {
                return(ev.Any());
            }

            return(false);
        }
Esempio n. 50
0
        public bool IsValid(object value, IConstraintValidatorContext validatorContext)
        {
            if (value == null)
            {
                return(true);
            }
            if (!(value is string))
            {
                return(false);
            }

            var @string = (string)value;
            int length  = @string.Length;

            return(length >= Min && length <= Max);
        }
Esempio n. 51
0
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null)
            {
                return(true);
            }

            if (!(value is string))
            {
                return(false);
            }

            string fileName = value.ToString();

            return(File.Exists(fileName));
        }
Esempio n. 52
0
        public bool IsValid(object value, IConstraintValidatorContext validatorContext)
        {
            if (value == null)
            {
                return true;
            }
            if (!(value is string))
            {
                return false;
            }

            var @string = (string)value;
            int length = @string.Length;

            return length >= Min && length <= Max;
        }
Esempio n. 53
0
        protected internal virtual void OptionalValidate(IConstraintValidatorContext context)
        {
            if (Coordinates.IsSpecified &&
                Site.Coordinates.IsSpecified &&
                Coordinates.CalculateDistanceInMinutesTo(Site.Coordinates) > 1f)
            {
                context.AddInvalid("(Optional) Coordinates are more than one mile from site.  You might want to double check them.", nameof(Coordinates));
            }

            if (Coordinates.IsSpecified &&
                Site.State.CoordinateBounds.Contains(Site.Coordinates) &&
                !Site.State.CoordinateBounds.Contains(Coordinates))
            {
                context.AddInvalid($"(Optional) Coordinates appear to fall outside the state's boundaries.  You might want to double check them.", nameof(Coordinates));
            }
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null)
            {
                return true;
            }

            if (!(value is string))
            {
                return false;
            }

            string fileName = value.ToString();

            return File.Exists(fileName);
        }
Esempio n. 55
0
 public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
 {
     if (value == null)
         return true;
     try
     {
         if (((DateTime)value).Kind != DateTimeKind.Utc)
             return false;
     }
     catch (InvalidCastException)
     {
         throw new InvalidOperationException(
             "The UtcDateTimeValidator may only be used against DateTime or DateTime? properties.");
     }
     return true;
 }
Esempio n. 56
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            if (value == null)
                return true;

            string pesel = value.ToString();

            if (pesel == string.Empty)
                return true;

            if (!HasValidFormat(pesel))
            {
                return false;
            }

            return HasValidChecksum(pesel);
        }
        public bool IsValid(object value, IConstraintValidatorContext validatorContext)
        {
            if (value == null)
            {
                return(true);
            }

            var creditCard = value as string;

            if (string.IsNullOrEmpty(creditCard) || creditCard.Length > 19 || !regex.IsMatch(creditCard) ||
                ulong.Parse(creditCard) == 0)
            {
                return(false);
            }

            IList <int> ints = new List <int>();

            foreach (char c in creditCard)
            {
                if (Char.IsDigit(c))
                {
                    ints.Add(c - '0');
                }
            }

            int  sum  = 0;
            bool even = false;

            for (int index = ints.Count - 1; index >= 0; index--)
            {
                int digit = ints[index];
                if (even)
                {
                    digit *= Multiplicator;
                    if (digit > 9)
                    {
                        digit = digit / 10 + digit % 10;
                    }
                }

                sum += digit;
                even = !even;
            }

            return(sum % 10 == 0);
        }
Esempio n. 58
0
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null)
            {
                return(true);
            }
            var mail = value as string;

            if (mail == null)
            {
                return(false);
            }
            if (mail.Length == 0)
            {
                return(true);
            }
            return(regex.IsMatch(mail));
        }
Esempio n. 59
0
        public bool IsValid(object value, IConstraintValidatorContext constraintContext)
        {
            if (value == null)
            {
                return(true);
            }
            if (value is string)
            {
                IPAddress ipAddress;
                string    ip = value.ToString();
                if (IPAddress.TryParse(ip, out ipAddress))
                {
                    return(subnetPrefix.Equals(ip.Substring(0, subnetPrefix.Length)));
                }
            }

            return(false);
        }
Esempio n. 60
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var check = new Regex(@"^\d{2}-\d{3}$", RegexOptions.Compiled);

            if (value == null)
            {
                return(true);
            }

            string postalCode = value.ToString();

            if (postalCode == string.Empty)
            {
                return(true);
            }

            return(check.IsMatch(postalCode));
        }