Esempio n. 1
0
        protected override bool ValidateSave()
        {
            base.ValidateSave();

            // Create a sandbox to do the validation in.
            var em = new EntityManager(EntityManager);
            em.CacheStateManager.RestoreCacheState(EntityManager.CacheStateManager.GetCacheState());

            // Find all entities supporting custom validation                
            var entities =
                em.FindEntities(EntityState.AllButDetached).OfType<EntityBase>().ToList();

            foreach (var e in entities)
            {
                var entityAspect = EntityAspect.Wrap(e);
                if (entityAspect.EntityState.IsDeletedOrDetached()) continue;

                var validationErrors = new VerifierResultCollection();
                e.Validate(validationErrors);

                validationErrors =
                    new VerifierResultCollection(entityAspect.ValidationErrors.Concat(validationErrors.Errors));
                validationErrors.Where(vr => !entityAspect.ValidationErrors.Contains(vr))
                    .ForEach(entityAspect.ValidationErrors.Add);

                if (validationErrors.HasErrors)
                    throw new EntityServerException(validationErrors.Select(v => v.Message).ToAggregateString("\n"),
                                                    null,
                                                    PersistenceOperation.Save, PersistenceFailure.Validation);
            }

            return true;
        }
Esempio n. 2
0
 public void OnValidationError(VerifierResultCollection validationErrors)
 {
     if (validationErrors.HasErrors)
     {
         EventFns.Publish(new ValidationErrorMessage(validationErrors));
     }
 }
Esempio n. 3
0
 public override void Validate(VerifierResultCollection validationErrors)
 {
     if (State.EntityFacts.EntityAspect.IsNullOrPendingEntity)
     {
         validationErrors.Add(new VerifierResult(VerifierResultCode.Error, "The State field is required", "State"));
     }
 }
Esempio n. 4
0
        public override void Validate(object entity, VerifierResultCollection validationErrors)
        {
            var entityBase = entity as EntityBase;

            if (entityBase != null)
            {
                entityBase.Validate(validationErrors);
            }
        }
Esempio n. 5
0
        public override void Validate(VerifierResultCollection validationErrors)
        {
            if (Addresses.Count == 0)
            {
                validationErrors.Add(new VerifierResult(false, "StaffingResource must have at least one address",
                                                        "Addresses"));
            }

            if (PhoneNumbers.Count == 0)
            {
                validationErrors.Add(new VerifierResult(false, "StaffingResource must have at least one phone number",
                                                        "PhoneNumbers"));
            }
        }
Esempio n. 6
0
        protected override bool ValidateSave()
        {
            base.ValidateSave();

            // Create a sandbox to do the validation in.
            var em = new EntityManager(EntityManager);

            em.CacheStateManager.RestoreCacheState(EntityManager.CacheStateManager.GetCacheState());

            // Find all entities supporting custom validation
            var entities =
                em.FindEntities(EntityState.AllButDetached).OfType <EntityBase>().ToList();

            foreach (var e in entities)
            {
                var entityAspect = EntityAspect.Wrap(e);
                if (entityAspect.EntityState.IsDeletedOrDetached())
                {
                    continue;
                }

                var validationErrors = new VerifierResultCollection();
                e.Validate(validationErrors);

                validationErrors =
                    new VerifierResultCollection(entityAspect.ValidationErrors.Concat(validationErrors.Errors));
                validationErrors.Where(vr => !entityAspect.ValidationErrors.Contains(vr))
                .ForEach(entityAspect.ValidationErrors.Add);

                if (validationErrors.HasErrors)
                {
                    throw new EntityServerException(validationErrors.Select(v => v.Message).ToAggregateString("\n"),
                                                    null,
                                                    PersistenceOperation.Save, PersistenceFailure.Validation);
                }
            }

            return(true);
        }
Esempio n. 7
0
        private void Validate(EntitySavingEventArgs args)
        {
            var allValidationErrors = new VerifierResultCollection();

            foreach (var entity in args.Entities)
            {
                var entityAspect = EntityAspect.Wrap(entity);
                if (entityAspect.EntityState.IsDeletedOrDetached())
                {
                    continue;
                }

                var validationErrors = Manager.VerifierEngine.Execute(entity);
                foreach (var d in _configuration.Delegates ?? new EntityManagerDelegate <T> [0])
                {
                    d.Validate(entity, validationErrors);
                }
                // Extract only validation errors
                validationErrors = validationErrors.Errors;

                validationErrors.Where(vr => !entityAspect.ValidationErrors.Contains(vr))
                .ForEach(entityAspect.ValidationErrors.Add);

                validationErrors.ForEach(allValidationErrors.Add);
            }

            if (allValidationErrors.HasErrors)
            {
                if (!ValidationErrorNotifiers.Any())
                {
                    throw new ValidationException(allValidationErrors.Select(v => v.Message).ToAggregateString("\n"));
                }

                ValidationErrorNotifiers.ForEach(s => s.OnValidationError(allValidationErrors));
                args.Cancel = true;
            }
        }
Esempio n. 8
0
 public virtual void Validate(VerifierResultCollection validationErrors)
 {
 }
Esempio n. 9
0
 public ValidationErrorMessage(VerifierResultCollection verifierResults)
 {
     VerifierResults = verifierResults;
 }
 public void OnValidationError(VerifierResultCollection validationErrors)
 {
     if (validationErrors.HasErrors)
         EventFns.Publish(new ValidationErrorMessage(validationErrors));
 }
 public ValidationErrorMessage(VerifierResultCollection verifierResults)
 {
     VerifierResults = verifierResults;
 }
Esempio n. 12
0
 public virtual void Validate(VerifierResultCollection validationErrors)
 {
 }
Esempio n. 13
0
 public ValidationErrorsViewModel Start(VerifierResultCollection verifierResults)
 {
     VerifierResults = verifierResults;
     return(this);
 }
Esempio n. 14
0
 public override void Validate(VerifierResultCollection validationErrors)
 {
     if (State.EntityFacts.EntityAspect.IsNullOrPendingEntity)
         validationErrors.Add(new VerifierResult(VerifierResultCode.Error, "The State field is required", "State"));
 }
        public override void Validate(VerifierResultCollection validationErrors)
        {
            if (Addresses.Count == 0)
                validationErrors.Add(new VerifierResult(false, "StaffingResource must have at least one address",
                                                                "Addresses"));

            if (PhoneNumbers.Count == 0)
                validationErrors.Add(new VerifierResult(false, "StaffingResource must have at least one phone number",
                                                                "PhoneNumbers"));
        }
 public ValidationErrorsViewModel Start(VerifierResultCollection verifierResults)
 {
     VerifierResults = verifierResults;
     return this;
 }