예제 #1
0
        public static ValidationNotification CompareLessDateTimeIsValid(
            this ValidationNotification source,
            IStructureToValidate data,
            IStructureToValidate dataCompare,
            CultureInfo cultureInfo = null)
        {
            string reference = data.Reference;

            object value   = data.Value;
            string display = data.Display;

            object valueCompare   = dataCompare.Value;
            string displayCompare = dataCompare.Display;

            cultureInfo = cultureInfo ?? CultureInfo.CurrentCulture;
            source.CleanLastMessage();

            if (!(value is null) && !(valueCompare is null))
            {
                if (DateTime.TryParse(Convert.ToString(value), cultureInfo, DateTimeStyles.None, out DateTime newValue) &&
                    DateTime.TryParse(Convert.ToString(valueCompare), cultureInfo, DateTimeStyles.None, out DateTime newCompare) &&
                    newValue >= newCompare)
                {
                    string text = string.Format(
                        Resource.XCompareLessInvalid,
                        display, displayCompare);

                    ValidationMessage message = new ValidationMessage(text, reference);
                    source.SetLastMessage(message, data.Display);
                    source.Add(message);
                }
            }

            return(source);
        }
예제 #2
0
        public static ValidationNotification CompareDifferentIsValid(
            this ValidationNotification source,
            IStructureToValidate data,
            IStructureToValidate dataCompare)
        {
            string reference = data.Reference;

            object value   = data.Value;
            string display = data.Display;

            object valueCompare   = dataCompare.Value;
            string displayCompare = dataCompare.Display;

            source.CleanLastMessage();

            if (!(value is null))
            {
                if (value.ToString() == valueCompare?.ToString())
                {
                    string text = string.Format(
                        Resource.XCompareDifferentInvalid,
                        display, displayCompare);

                    var message = new ValidationMessage(text, reference);
                    source.SetLastMessage(message, data.Display);
                    source.Add(message);
                }
            }

            return(source);
        }
예제 #3
0
        public static ValidationNotification CompareLessNumberIsValid(
            this ValidationNotification source,
            IStructureToValidate data,
            IStructureToValidate dataCompare)
        {
            string reference = data.Reference;

            object value   = data.Value;
            string display = data.Display;

            object valueCompare   = dataCompare.Value;
            string displayCompare = dataCompare.Display;

            source.CleanLastMessage();

            if (!(value is null) && !(valueCompare is null))
            {
                if (decimal.TryParse(Convert.ToString(value), out decimal newValue) &&
                    decimal.TryParse(Convert.ToString(valueCompare), out decimal newCompare) &&
                    newValue >= newCompare)
                {
                    string text = string.Format(
                        Resource.XCompareLessInvalid,
                        display, displayCompare);

                    var message = new ValidationMessage(text, reference);
                    source.SetLastMessage(message, data.Display);
                    source.Add(message);
                }
            }

            return(source);
        }
예제 #4
0
        private static ValidationNotification EqualItemsIsValid(
            this ValidationNotification source, IEnumerable <IEnumerable> value)
        {
            bool result = true;
            int? total  = null;
            bool isNull = false;

            foreach (IList item in value)
            {
                if (item != null)
                {
                    if (isNull)
                    {
                        result = false;
                        break;
                    }

                    int current = item.Count;
                    if (total == null)
                    {
                        total = current;
                    }
                    else if (current != total)
                    {
                        result = false;
                        break;
                    }
                }
                else
                {
                    isNull = true;
                    if (total != null)
                    {
                        result = false;
                        break;
                    }
                }
            }

            source.CleanLastMessage();
            if (!result)
            {
                string            text    = Resource.EqualNumberItemsInvalid;
                ValidationMessage message = new ValidationMessage(text, null);
                source.SetLastMessage(message, Resource.DisplayValue);
                source.Add(message);
            }
            return(source);
        }
예제 #5
0
        public static ValidationNotification RangeNumberIsValid(
            this ValidationNotification source, IStructureToValidate data, decimal minimum, decimal maximum)
        {
            source.CleanLastMessage();
            RangeNumberIsValidAttribute validation = new RangeNumberIsValidAttribute(minimum, maximum);

            if (!validation.IsValid(data.Value))
            {
                string text    = validation.FormatErrorMessage(data.Display);
                var    message = new ValidationMessage(text, data.Reference);
                source.SetLastMessage(message, data.Display);
                source.Add(message);
            }
            return(source);
        }
예제 #6
0
        public static ValidationNotification ExactCharactersIsValid(
            this ValidationNotification source, IStructureToValidate data, int exact)
        {
            source.CleanLastMessage();
            ExactCharactersIsValidAttribute validation = new ExactCharactersIsValidAttribute(exact);

            if (!validation.IsValid(data.Value))
            {
                string text    = validation.FormatErrorMessage(data.Display);
                var    message = new ValidationMessage(text, data.Reference);
                source.SetLastMessage(message, data.Display);
                source.Add(message);
            }
            return(source);
        }
예제 #7
0
        public static ValidationNotification DateTimeIsValid(
            this ValidationNotification source, IStructureToValidate data, CultureInfo cultureInfo = null)
        {
            source.CleanLastMessage();
            DateTimeIsValidAttribute validation = new DateTimeIsValidAttribute(cultureInfo);

            if (!validation.IsValid(data.Value))
            {
                string text    = validation.FormatErrorMessage(data.Display);
                var    message = new ValidationMessage(text, data.Reference);
                source.SetLastMessage(message, data.Display);
                source.Add(message);
            }
            return(source);
        }
예제 #8
0
        public static ValidationNotification NotNullOrEmptyIsValid(
            this ValidationNotification source, IStructureToValidate data, bool ignoreWithSpace)
        {
            source.CleanLastMessage();
            NotNullOrEmptyIsValidAttribute validation = new NotNullOrEmptyIsValidAttribute(ignoreWithSpace);

            if (!validation.IsValid(data.Value))
            {
                string text    = validation.FormatErrorMessage(data.Display);
                var    message = new ValidationMessage(text, data.Reference);
                source.SetLastMessage(message, data.Display);
                source.Add(message);
            }
            return(source);
        }
예제 #9
0
        public static ValidationNotification BetweenTimeSpanIsValid(
            this ValidationNotification source, IStructureToValidate data, IEnumerable <TimeSpan> options)
        {
            source.CleanLastMessage();
            BetweenTimeSpanIsValidAttribute validation = new BetweenTimeSpanIsValidAttribute(options);

            if (!validation.IsValid(data.Value))
            {
                string text    = validation.FormatErrorMessage(data.Display);
                var    message = new ValidationMessage(text, data.Reference);
                source.SetLastMessage(message, data.Display);
                source.Add(message);
            }
            return(source);
        }
예제 #10
0
        public static ValidationNotification MaxTimeSpanIsValid(
            this ValidationNotification source, IStructureToValidate data, TimeSpan maximum)
        {
            source.CleanLastMessage();
            MaxTimeSpanIsValidAttribute validation = new MaxTimeSpanIsValidAttribute(maximum);

            if (!validation.IsValid(data.Value))
            {
                string text    = validation.FormatErrorMessage(data.Display);
                var    message = new ValidationMessage(text, data.Reference);
                source.SetLastMessage(message, data.Display);
                source.Add(message);
            }
            return(source);
        }
예제 #11
0
        public static ValidationNotification RegexIsValid(
            this ValidationNotification source, IStructureToValidate data,
            string pattern, RegexOptions options = RegexOptions.None)
        {
            source.CleanLastMessage();
            RegexIsValidAttribute validation = new RegexIsValidAttribute(pattern, options);

            if (!validation.IsValid(data.Value))
            {
                string text    = validation.FormatErrorMessage(data.Display);
                var    message = new ValidationMessage(text, data.Reference);
                source.SetLastMessage(message, data.Display);
                source.Add(message);
            }
            return(source);
        }
예제 #12
0
 public static ValidationNotification RequiredIfOtherNotNullIsValid(
     this ValidationNotification source, IStructureToValidate data, object compare)
 {
     source.CleanLastMessage();
     if (!source.Messages.Any(x => x.IsTypeError() && x.Reference?.ToLower() == data.Reference?.ToLower()))
     {
         if (!object.Equals(compare, null) && object.Equals(data.Value, null))
         {
             string text    = string.Format(Resource.XRequired, data.Display);
             var    message = new ValidationMessage(text, data.Reference);
             source.SetLastMessage(message, data.Display);
             source.Add(message);
         }
     }
     return(source);
 }
예제 #13
0
 public static ValidationNotification EqualIsValid(
     this ValidationNotification source, IStructureToValidate data, object compare)
 {
     source.CleanLastMessage();
     if (data.Value != null && compare != null)
     {
         string valueCheck   = Convert.ToString(data.Value);
         string compareCheck = Convert.ToString(compare);
         if (valueCheck != compareCheck)
         {
             string text    = string.Format(Resource.XConfirmedInvalid, data.Display);
             var    message = new ValidationMessage(text, data.Reference);
             source.SetLastMessage(message, data.Display);
             source.Add(message);
         }
     }
     return(source);
 }
예제 #14
0
        public static ValidationNotification RequiredIsValid(
            this ValidationNotification source, IStructureToValidate data)
        {
            source.CleanLastMessage();
            RequiredIsValidAttribute validation = new RequiredIsValidAttribute();

            if (!source.Messages.Any(x => x.IsTypeError() && x.Reference?.ToLower() == data.Reference?.ToLower()))
            {
                if (!validation.IsValid(data.Value))
                {
                    string text    = validation.FormatErrorMessage(data.Display);
                    var    message = new ValidationMessage(text, data.Reference);
                    source.SetLastMessage(message, data.Display);
                    source.Add(message);
                }
            }
            return(source);
        }