using FluentValidation; namespace Landmark.OLA.Models.Loan.Validators { public class BranchConfigValidator : AbstractValidator { public BranchConfigValidator() { RuleFor(x => x.BranchCodesByZip).Must((x, branchCodes) => NoZipcodeDuplicates(branchCodes)) .WithMessage("You cannot have duplicate zipcodes."); } private static bool NoZipcodeDuplicates(List 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; } } }