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;
        }
 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;
 }
        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;
        }
Beispiel #4
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;
        }
 //- 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;
 }
        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);
        }
Beispiel #7
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);
        }
 //- SID range
 //- Tippzahlen-SID match
 public bool IsValid(object value, IConstraintValidatorContext context)
 {
     var entity = (ITippfeld)value;
     if (entity is Normalfeld && 6 != entity.SID)
         throw new BusinessException("SID is not 6");
     if (entity is Systemfeld && (entity.SID < 7 || entity.SID > 13)){
         context.DisableDefaultError();
         context.AddInvalid<ITippfeld, int>(String.Format(
             "'{0}' should be between 7 and 13", entity.SID), x => entity.SID);
         return false;
     }
     if (entity.SID != entity.Tippzahlen.Count) {
         context.DisableDefaultError();
         context.AddInvalid<ITippfeld, Tippzahlen>(String.Format(
             "number '{0}' should match SID '{1}'", entity.Tippzahlen.Count, entity.SID), x => entity.Tippzahlen);
         return false;
     }
     return true;
 }
 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 context)
        {
            var entity = (ISchein)value;
            if (!Regex.IsMatch(entity.Losnummer, @"^\d{7}$"))
                throw new BusinessException(String.Format(
                    "ISchein.Losnummer, '{0}', should be 7 numerals", entity.Losnummer));

            if (entity.Tippfelder.All(x => x.IsEmpty())) {
                context.DisableDefaultError();
                context.AddInvalid<ISchein, IList<ITippfeld>>(
                    String.Format("should be populated"), x => x.Tippfelder);
                return false;
            }
            if (entity.Tippfelder.Where(x => !x.IsEmpty()).Any(x => !x.IsValid())) {
                context.DisableDefaultError();
                context.AddInvalid<ISchein, IList<ITippfeld>>(
                    String.Format("should be valid"), x => x.Tippfelder);
                return false;
            }
            return true;
        }
Beispiel #11
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;
        }
Beispiel #12
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 constraintValidatorContext)
        {
            var isValid = true;
            var sniInvestigador = value as SNIInvestigador;
            if (sniInvestigador != null && sniInvestigador.SNI != null && sniInvestigador.SNI.Nombre != "No Pertenece")
            {
                if (sniInvestigador.FechaInicial <= DateTime.Parse("1910-01-01"))
                {
                    constraintValidatorContext.DisableDefaultError();
                    constraintValidatorContext.AddInvalid<SNIInvestigador, DateTime>(
                        "fecha inicial inválida o nula|FechaInicial", x => x.FechaInicial);
                    isValid = false;
                }

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

            return isValid;
        }
        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;
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var isValid = true;
            var estadoInvestigador = value as EstadoInvestigador;
            if (estadoInvestigador != null)
            {
                if(estadoInvestigador.FechaInicial <= DateTime.Parse("1910-01-01"))
                {
                    constraintValidatorContext.DisableDefaultError();
                    constraintValidatorContext.AddInvalid<EstadoInvestigador, DateTime>("fecha inicial inválida o nula|FechaInicial", x => x.FechaInicial);
                    isValid = false;
                }

                if (estadoInvestigador.Estado != null && (estadoInvestigador.Estado.Nombre != "Activo" && estadoInvestigador.Estado.Nombre != "Baja"))
                {
                    if (estadoInvestigador.FechaFinal <= DateTime.Parse("1910-01-01"))
                    {
                        constraintValidatorContext.DisableDefaultError();
                        constraintValidatorContext.AddInvalid<EstadoInvestigador, DateTime>(
                            "fecha final inválida o nula|FechaFinal", x => x.FechaFinal);
                        isValid = false;
                    }
                    else if (estadoInvestigador.FechaInicial >= estadoInvestigador.FechaFinal)
                    {
                        constraintValidatorContext.DisableDefaultError();
                        constraintValidatorContext.AddInvalid<EstadoInvestigador, DateTime>(
                            "fecha inicial debe ser menor a fecha final|FechaInicial", x => x.FechaInicial);
                        constraintValidatorContext.AddInvalid<EstadoInvestigador, DateTime>(
                            "fecha final debe ser mayor a fecha inicial|FechaFinal", x => x.FechaFinal);
                        isValid = false;
                    }
                }
            }

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

            return isValid;
        }
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var isValid = true;
            var autorExternoProducto = value as AutorExternoProducto;
            if (autorExternoProducto != null)
            {
                if (!autorExternoProducto.AutorSeOrdenaAlfabeticamente)
                {
                    if (autorExternoProducto.Posicion <= 0)
                    {
                        constraintValidatorContext.DisableDefaultError();
                        constraintValidatorContext.AddInvalid<AutorExternoProducto, int>(
                            "no debe ser menor o igual a cero|Posicion", x => x.Posicion);
                        isValid = false;
                    }
                }
            }

            return isValid;
        }
Beispiel #18
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            constraintValidatorContext.DisableDefaultError();
            bool isValid = true;
            string password = (string)value;

            if(password.Length < 5)
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordLength);
                isValid = false;
            }

            if(password.Contains("123"))
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordContent);
                isValid = false;
            }

            return isValid;
        }
Beispiel #19
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            constraintValidatorContext.DisableDefaultError();
            bool   isValid  = true;
            string password = (string)value;

            if (password.Length < 5)
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordLength);
                isValid = false;
            }

            if (password.Contains("123"))
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordContent);
                isValid = false;
            }

            return(isValid);
        }
        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;
        }
Beispiel #21
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var info = value as IMembershipInfo;

            if (info == null)
            {
                throw new InvalidOperationException("The Validator Password can only be applied to implementations of " +
                                                    typeof(IMembershipInfo).FullName);
            }

            constraintValidatorContext.DisableDefaultError();

            bool isValid = true;

            if (string.IsNullOrEmpty(info.Username))
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordLength);
                isValid = false;
            }

            if (info.Username != null && info.Password.Contains(info.Username))
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordContentUsername);
                isValid = false;
            }

            if (info.Password.Length < 5)
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordLength);
                isValid = false;
            }

            if (info.Password.Contains("123"))
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordContent);
                isValid = false;
            }

            return(isValid);
        }
Beispiel #22
0
        public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext)
        {
            var info = value as IMembershipInfo;
            if (info == null) throw new InvalidOperationException("The Validator Password can only be applied to implementations of " +
                                                    typeof (IMembershipInfo).FullName);

            constraintValidatorContext.DisableDefaultError();

            bool isValid = true;

            if (string.IsNullOrEmpty(info.Username))
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordLength);
                isValid = false;
            }

            if (info.Username != null && info.Password.Contains(info.Username))
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordContentUsername);
                isValid = false;
            }

            if (info.Password.Length < 5)
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordLength);
                isValid = false;
            }

            if (info.Password.Contains("123"))
            {
                constraintValidatorContext.AddInvalid(Messages.PasswordContent);
                isValid = false;
            }

            return isValid;
        }