You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.5 KiB
43 lines
1.5 KiB
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using FluentValidation;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Application.Iac.Qad.Publics;
|
|
|
|
public class QADHelper
|
|
{
|
|
public static List<ValidationResult> CheckMember<T>(T entity, IValidator<T> validator)
|
|
{
|
|
List<ValidationResult> validResultLst = new List<ValidationResult>();
|
|
var validResult = validator.Validate(entity);
|
|
if (validResult.IsValid == false)
|
|
{
|
|
foreach (var error in validResult.Errors)
|
|
{
|
|
ValidationResult validResultObj = new ValidationResult(error.ErrorMessage);
|
|
validResultLst.Add(validResultObj);
|
|
}
|
|
}
|
|
return validResultLst;
|
|
}
|
|
|
|
public static List<ValidationResult> CheckMember<T>(List<T> entityList, IValidator<T> validator)
|
|
{
|
|
List<ValidationResult> validResultLst = new List<ValidationResult>();
|
|
for (int i = 0; i < entityList.Count; i++)
|
|
{
|
|
var entity = entityList[i];
|
|
var validResult = validator.Validate(entity);
|
|
if (validResult.IsValid == false)
|
|
{
|
|
foreach (var error in validResult.Errors)
|
|
{
|
|
ValidationResult validResultObj = new ValidationResult($"Line {i + 1}:" + error.ErrorMessage);
|
|
validResultLst.Add(validResultObj);
|
|
}
|
|
}
|
|
}
|
|
return validResultLst;
|
|
}
|
|
|
|
}
|
|
|