Пример #1
0
        /// <summary>
        /// Gets a list of validation errors for a property.
        /// </summary>
        /// <param name="propertyName">The property to check. There are constants for the properties at Foresight.DataAccess.[EntityName].[EntityName]Properties</param>
        /// <param name="validationGroup">The validation group to validate. There are constants for this value in Foresight.DataAccess.Framework.ValidationGroup</param>
        /// <returns>the list of errors</returns>
        public virtual List <ValidationError> GetValidationErrorsByProperty(string propertyName, SqlHelper helper, string validationGroup)
        {
            List <ValidationError> validationErrors = new List <ValidationError>();

            EntityValidationCancelEventArgs e = new EntityValidationCancelEventArgs(this, helper, propertyName, validationGroup);

            OnPropertyValidating(this, e);

            if (!e.Cancel)
            {
                System.Type type = this.GetType();
                Dictionary <string, ColumnInfo> columns = ColumnInfo.GetColumnInfoLookup(type);

                ColumnInfo column;
                if (columns.TryGetValue(propertyName, out column))
                {
                    validationErrors.AddRange(GetValidationErrors(type, column, validationGroup));
                }
                OnPropertyValidated(this, new EntityValidationEventArgs(this, helper, propertyName, validationGroup));
            }

            return(validationErrors);
        }
Пример #2
0
        /// <summary>
        /// Gets a list of validation errors
        /// </summary>
        /// <param name="helper">The current SqlHelper</param>
        /// <param name="validationGroup">The validation group to validate. There are constants for this value in Foresight.DataAccess.Framework.ValidationGroup</param>
        /// <returns>the list of errors</returns>
        public virtual List <ValidationError> GetValidationErrors(SqlHelper helper, string validationGroup)
        {
            List <ValidationError> validationErrors = new List <ValidationError>();

            EntityValidationCancelEventArgs e = new EntityValidationCancelEventArgs(this, helper, String.Empty, validationGroup);

            OnEntityValidating(this, e);

            if (!e.Cancel)
            {
                Dictionary <string, PropertyInfo> propertyList = GetPropertyList(ColumnType.DatabaseColumn);

                foreach (string propertyName in propertyList.Keys)
                {
                    validationErrors.AddRange(GetValidationErrorsByProperty(propertyName, helper, validationGroup));
                }

                validationErrors.AddRange(GetChildrenValidationErrors());

                OnEntityValidated(this, new EntityValidationEventArgs(this, helper, String.Empty, validationGroup));
            }

            return(validationErrors);
        }