34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using FluentValidation;
|
|
|
|
namespace Landmark.OLA.Models.Loan.Validators
|
|
{
|
|
public class BranchConfigValidator : AbstractValidator<BranchConfig>
|
|
{
|
|
public BranchConfigValidator() {
|
|
RuleFor(x => x.BranchCodesByZip).Must((x, branchCodes) => NoZipcodeDuplicates(branchCodes))
|
|
.WithMessage("You cannot have duplicate zipcodes.");
|
|
}
|
|
|
|
private static bool NoZipcodeDuplicates(List<BranchData> branchData)
|
|
{
|
|
var matchFound = false;
|
|
foreach (var eachMapping in branchData)
|
|
{
|
|
int matchCount = 0;
|
|
foreach (var otherMapping in branchData)
|
|
{
|
|
if( otherMapping.Zipcode == eachMapping.Zipcode)
|
|
{
|
|
matchCount++;
|
|
}
|
|
}
|
|
if( matchCount > 1 )
|
|
{
|
|
matchFound = true;
|
|
}
|
|
}
|
|
return !matchFound;
|
|
}
|
|
}
|
|
}
|