Beispiel #1
0
 public RulesExceptionListContainer(RulesException rulesException)
 {
     IsRoot       = true;
     PropertyName = rulesException.PropertyName;
     if (!string.IsNullOrEmpty(PropertyName))
     {
         PropertyNameCamelCase = PropertyName.ToCamelCase();
     }
     Index = rulesException.Index;
 }
Beispiel #2
0
 public RulesExceptionDto(RulesException rulesException) : this()
 {
     Data   = rulesException.Data;
     Errors = rulesException.GetErrorDictionary();
     if (!string.IsNullOrEmpty(rulesException.ErrorMessage))
     {
         ErrorMessages.Add(rulesException.ErrorMessage);
     }
     ErrorMessages.AddRange(rulesException.ErrorMessages);
 }
Beispiel #3
0
 protected RulesException(string message, RulesException rulesException) : base(message)
 {
     Errors        = rulesException.Errors;
     ErrorMessages = rulesException.ErrorMessages;
     Prefix        = rulesException.Prefix;
     IsEnumerable  = rulesException.IsEnumerable;
     PropertyName  = rulesException.PropertyName;
     Index         = rulesException.Index;
     ErrorMessage  = rulesException.ErrorMessage;
 }
Beispiel #4
0
 protected void Add(RulesException errors)
 {
     foreach (var error in errors.Errors)
     {
         Errors.Add(error);
         if (string.IsNullOrEmpty(error.Prefix))
         {
             ErrorMessages.Add($"{error.Key} - {error.Message}");
         }
         else
         {
             ErrorMessages.Add($"{error.Prefix} - {error.Key} - {error.Message}");
         }
     }
 }
Beispiel #5
0
        private void ProcessEnumerableRulesException(string key, KeyValuePair <string, List <object> > error, RulesException rulesException)
        {
            var keySplit = key.Split('.');

            if (!rulesException.IsEnumerable && !keySplit.Any(x => x.EndsWith("]")))
            {
                Errors.Add(key, error.Value);
            }
            else if (rulesException.IsEnumerable && keySplit.Count(x => x.EndsWith("]")) == 1)
            {
                FindAndAddRulesExceptionListContainer(key, keySplit, error, rulesException);
            }
            else if ((!rulesException.IsEnumerable && keySplit.Any(x => x.EndsWith("]"))) ||
                     keySplit.Count(x => x.EndsWith("]")) > 1)
            {
                FindAndAddRulesExceptionListContainer(key, keySplit, error, rulesException);
            }
            else
            {
                RulesExceptionListContainers.Add(new RulesExceptionListContainer(key, error, rulesException));
            }
        }
Beispiel #6
0
        private void FindAndAddRulesExceptionListContainer(string key, string[] keySplit, KeyValuePair <string, List <object> > error, RulesException rulesException)
        {
            var rulesExceptionListContainer = FindRulesExceptionListContainer(keySplit, 0, error, rulesException, RulesExceptionListContainers);

            if (rulesExceptionListContainer == null)
            {
                var newRulesExceptionListContainers = new RulesExceptionListContainer(rulesException);
                newRulesExceptionListContainers.AddError(error);
                RulesExceptionListContainers.Add(newRulesExceptionListContainers);
            }
            else
            {
                rulesExceptionListContainer.AddError(new KeyValuePair <string, List <object> >(key.Replace(rulesExceptionListContainer.KeyIndex + ".", ""), error.Value));
            }
        }
Beispiel #7
0
        private RulesExceptionListContainer FindRulesExceptionListContainer(string[] keySplit, int index, KeyValuePair <string, List <object> > error, RulesException rulesException, List <RulesExceptionListContainer> rulesExceptionListContainers)
        {
            var rulesExceptionListContainer = rulesExceptionListContainers.SingleOrDefault(x => x.KeyIndex == keySplit[index] || (x.Key == "" && x.KeyIndex == keySplit[index]));

            if (rulesExceptionListContainer != null && rulesExceptionListContainer.Index.HasValue)
            {
                var nextIndex = index + 1;
                var findRulesExceptionListContainer = FindRulesExceptionListContainer(keySplit, nextIndex, error, rulesException, rulesExceptionListContainer.RulesExceptionListContainers);
                if (findRulesExceptionListContainer != null)
                {
                    return(findRulesExceptionListContainer);
                }
                else if (keySplit[nextIndex].EndsWith("]"))
                {
                    var newRulesExceptionListContainers = new RulesExceptionListContainer(rulesException);
                    rulesExceptionListContainer.RulesExceptionListContainers.Add(newRulesExceptionListContainers);
                    findRulesExceptionListContainer = FindRulesExceptionListContainer(keySplit, nextIndex, error, rulesException, rulesExceptionListContainer.RulesExceptionListContainers);
                    if (findRulesExceptionListContainer != null)
                    {
                        return(findRulesExceptionListContainer);
                    }
                }
            }
            return(rulesExceptionListContainer);
        }
Beispiel #8
0
 public RulesBase()
 {
     RulesException = new RulesException <TModel>();
 }
Beispiel #9
0
        public RulesExceptionListContainer(string key, KeyValuePair <string, List <object> > error, RulesException rulesException)
        {
            IsRoot       = false;
            Key          = key;
            PropertyName = rulesException.PropertyName;
            if (!string.IsNullOrEmpty(PropertyName))
            {
                PropertyNameCamelCase = PropertyName.ToCamelCase();
            }
            Index = rulesException.Index;

            Errors.Add(error.Key.ToCamelCase(), error.Value);
        }
Beispiel #10
0
 public static bool ContainsErrorForProperty(this RulesException ex, string propertyName)
 {
     return(ex.Errors.Any(x => x.Key.Contains(propertyName)));
 }