Beispiel #1
0
        public bool Validate(EntityRecord entityRecord)
        {
            var instance = entityRecord.CreateInstance();
            var context = new ValidationContext(instance);
            var isValid = true;
            foreach (var propertyValue in entityRecord.Values.WhereIsNotSkipped())
            {
                if (propertyValue.Property.TypeInfo.IsFile)
                {
                    var result = _fileValidator.Validate(propertyValue);
                    if (result == false)
                        isValid = false;
                }

                context.DisplayName = propertyValue.Property.Display;
                foreach (var validator in propertyValue.Property.Validators)
                {
                    try
                    {
                        validator.Validate(propertyValue.Raw, context);
                    }
                    catch (ValidationException ex)
                    {
                        isValid = false;
                        _notificator.AddModelError(propertyValue.Property.Name, ex.Message);
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex);
                    }
                }
            }
            return isValid;
        }
Beispiel #2
0
        public bool Validate(EntityRecord entityRecord)
        {
            var instance = entityRecord.CreateInstance();
            var context  = new ValidationContext(instance);
            var isValid  = true;

            foreach (var propertyValue in entityRecord.Values.WhereIsNotSkipped())
            {
                if (propertyValue.Property.TypeInfo.IsFile)
                {
                    var result = _fileValidator.Validate(propertyValue);
                    if (result == false)
                    {
                        isValid = false;
                    }
                }

                context.DisplayName = propertyValue.Property.Display;
                foreach (var validator in propertyValue.Property.Validators)
                {
                    try
                    {
                        validator.Validate(propertyValue.Raw, context);
                    }
                    catch (ValidationException ex)
                    {
                        isValid = false;
                        _notificator.AddModelError(propertyValue.Property.Name, ex.Message);
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex);
                    }
                }
            }
            return(isValid);
        }