Esempio n. 1
0
 /// <summary>
 /// 如果有异常则抛出
 /// </summary>
 /// <param name="dataValidationResult"></param>
 public static void ThrowIf(this DataValidationResult dataValidationResult)
 {
     if (!dataValidationResult.IsValid)
     {
         throw Oops.Oh("[Validation]" + JsonSerializer.Serialize(
                           dataValidationResult.ValidationResults
                           .Where(u => u.MemberNames.Any())
                           .OrderBy(u => u.MemberNames.First())
                           .GroupBy(u => u.MemberNames.First())
                           .ToDictionary(u => u.Key, u => u.Select(c => c.ErrorMessage)), new JsonSerializerOptions {
             WriteIndented = true
         }));
     }
 }
 /// <summary>
 /// 如果有异常则抛出
 /// </summary>
 /// <param name="dataValidationResult"></param>
 public static void AddError(this DataValidationResult dataValidationResult)
 {
     if (!dataValidationResult.IsValid)
     {
         throw Oops.Oh("[Validation]" + JsonSerializer.Serialize(
                           dataValidationResult.ValidationResults
                           .Select(u => new
         {
             MemberNames = u.MemberNames.Any() ? u.MemberNames : new[] { $"{dataValidationResult.MemberOrValue}" },
             u.ErrorMessage
         })
                           .OrderBy(u => u.MemberNames.First())
                           .GroupBy(u => u.MemberNames.First())
                           .ToDictionary(u => u.Key, u => u.Select(c => c.ErrorMessage))));
     }
 }