public RulesExceptionListContainer(RulesException rulesException) { IsRoot = true; PropertyName = rulesException.PropertyName; if (!string.IsNullOrEmpty(PropertyName)) { PropertyNameCamelCase = PropertyName.ToCamelCase(); } Index = rulesException.Index; }
public RulesExceptionDto(RulesException rulesException) : this() { Data = rulesException.Data; Errors = rulesException.GetErrorDictionary(); if (!string.IsNullOrEmpty(rulesException.ErrorMessage)) { ErrorMessages.Add(rulesException.ErrorMessage); } ErrorMessages.AddRange(rulesException.ErrorMessages); }
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; }
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}"); } } }
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)); } }
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)); } }
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); }
public RulesBase() { RulesException = new RulesException <TModel>(); }
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); }
public static bool ContainsErrorForProperty(this RulesException ex, string propertyName) { return(ex.Errors.Any(x => x.Key.Contains(propertyName))); }