public class ModelToValidate
{
public int CustomerId { get; set; }
public int CarId { get; set; }
public int CustomerPartnerId { get; set; }
...
}
public class ModelToValidateValidator: AbstractValidator<ModelToValidate>
{
...
RuleFor(v => v.CustomerId).MustAsync(
async (model) =>
{
return await CustomerFound(model.CustomerId, model.CarId);
}
).WithMessage("{PropertyName} message.");
RuleFor(v => v.CustomerPartnerId).MustAsync(
async (model) =>
{
return await CustomerFound(model.CustomerPartnerId, model.CarId);
}
).WithMessage("{PropertyName} message.");
private async Task<bool> CustomerFound(int custId, int carId)
{
return await _repository.Customers(custId, carId);
}
}
I want to validate model with same method (CustomerFound) for multiple properties in my model (first I want to check combination of CustomerId + CarID and secondly CustomerPartnerId + CarId). This code above doesn't compile