Пример #1
0
 /// <inheritdoc />
 public void AddValidation(AbstractValidation <T> validation)
 {
     if (!Validations.Any(a => a.Name == validation.Name))
     {
         _validations.Add(item: validation);
     }
 }
Пример #2
0
 public void CreateResponseOk()
 {
     if (Validations == null || !Validations.Any())
     {
         Message        = "Success.";
         HttpStatusCode = (HttpStatusCode)200;
     }
 }
Пример #3
0
        public bool IsHttpStatusCodeError()
        {
            if (Validations != null && Validations.Any() && (int)HttpStatusCode < 400)
            {
                CreateResponseBadRequest();
            }

            return((int)HttpStatusCode >= 400);
        }
Пример #4
0
 private bool ExecuteValidations(IPublishedContent content, IEnumerable <FieldWithValue> valueFields)
 {
     if (Validations != null &&
         Validations.Any()
         // if any validation fails, the entire form validation fails
         // - instead of calling Validations.All() here, this actually forces all validations to execute
         && Validations.Count(v => v.IsValidFor(valueFields, content) == false) != 0)
     {
         return(false);
     }
     return(true);
 }
Пример #5
0
        public void AddValidation(IEnumerable <ValidationMessage> validations)
        {
            var consolidateValidations = new List <ValidationMessage>();

            if (Validations != null && Validations.Any())
            {
                foreach (var validation in Validations)
                {
                    consolidateValidations.Add(validation);
                }
            }

            consolidateValidations.AddRange(validations);

            Validations = consolidateValidations;
        }
Пример #6
0
        public void AddValidation(string attribute, string message)
        {
            var validations = new List <ValidationMessage>();

            if (Validations != null && Validations.Any())
            {
                foreach (var validation in Validations)
                {
                    validations.Add(validation);
                }
            }

            validations.Add(new ValidationMessage {
                Attribute = attribute, Message = message
            });

            Validations = validations;
        }
Пример #7
0
        /// <summary>
        /// Retorna a mensagem e possíveis validações do result.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.Append(Message);

            if (!Valid && Validations != null && Validations.Any())
            {
                sb.AppendLine("");
                Validations.ForEach(val => sb.AppendLine($"- {val.Attribute}: {val.Message}"));
            }

            string toString = sb.ToString();

            if (toString.EndsWith("\r\n"))
            {
                toString = toString.Substring(0, toString.Length - 2);
            }

            return(toString);
        }
Пример #8
0
        public void ValidateAndThrow()
        {
            AddValidattions();

            if (dations.Count > 0)
            {
                message = dations.Message;
            }

            if (!String.IsNullOrEmpty(message))
            {
                if (dations.Any(a => a.CustomException != null && !a.Ok))
                {
                    var err = dations.First(a => a.CustomException != null && !a.Ok);
                    throw err.CustomException;
                }
                else
                {
                    throw new ValidationException(message);
                }
            }
        }
Пример #9
0
        public string SimpleMessage()
        {
            string mensaje = string.Empty;

            if (Validations.Any())
            {
                foreach (Validation validation in Validations)
                {
                    mensaje += validation.Message;
                    mensaje += "\n";
                }
            }

            if (Errors.Any())
            {
                foreach (string error in Errors)
                {
                    mensaje += error;
                    mensaje += "\n";
                }
            }

            return(mensaje);
        }
Пример #10
0
 public bool HasValidatedTheme(int roundNumber, string theme) =>
 Validations.Any(v => v.RoundNumber == roundNumber && v.Theme.Equals(theme));
Пример #11
0
 public override bool IsValid() => !Validations.Any();