/// ======================================================================

        public static bool IsValid(IValidable obj)
        {
            if (obj == null)
            {
                return(false);
            }

            return(obj.IsValid());
        }
Exemple #2
0
        /// <summary>
        /// Extension method to assign css class for a asp.net control based on a condition
        /// </summary>
        /// <param name="container"></param>
        /// <param name="condition"></param>
        /// <param name="className"></param>
        /// <returns></returns>
        public static string CssClassIfInvalid(this Control container, IValidable item, string propertyName, string errorStyle)
        {
            if (!item.IsValid())
            {
                // find the matching property
                ValidationError valError = item.ValidationErrors().Find(vError => vError.PropertyName.EqualsIgnoreCase(propertyName));
                if (valError != null)
                {
                    return(errorStyle);
                }
            }

            return(string.Empty);
        }
Exemple #3
0
        /// <summary>
        ///     Checks if all the IValidable children are Valid (elem.IsValid())
        /// </summary>
        /// <param name="root"></param>
        /// <returns></returns>
        public static bool AreAllChildrenValid(this FrameworkElement root)
        {
            if (root == null)
                return true;

            foreach (Control ctrl in root.FindAllChildren<IValidable>())
            {
                IValidable test = ctrl as IValidable;
                if (test != null)
                    if (test.IsValid() == false)
                    {
                        return false;
                    }
            }
            return true;
        }