private IEnumerable <MunicipalityLatestItem> FilterByPostalCode(
            IEnumerable <MunicipalityLatestItem> municipalities,
            AddressMatchBuilder results)
        {
            if (string.IsNullOrWhiteSpace(results?.Query.PostalCode))
            {
                return(new List <MunicipalityLatestItem>());
            }

            var postalInfo = _latestQueries
                             .GetAllPostalInfo()
                             .FirstOrDefault(x => x.PostalCode == results.Query.PostalCode);

            if (postalInfo != null)
            {
                if (results.Any() && !results.ContainsNisCode(postalInfo.NisCode))
                {
                    _warnings.AddWarning("8", "Geen overeenkomst tussen 'Postcode' en 'Gemeentenaam'/'Niscode'.");
                }

                return(string.IsNullOrEmpty(postalInfo.NisCode)
                    ? new List <MunicipalityLatestItem>()
                    : municipalities.Where(g => g.NisCode != null && g.NisCode.Contains(postalInfo.NisCode)));
            }

            _warnings.AddWarning("4", "Onbekende 'Postcode'.");
            return(new MunicipalityLatestItem[] { });
        }
예제 #2
0
 private IEnumerable <Tuple <string, MunicipalityLatestItem> > FilterByPartOfMunicipality(IEnumerable <MunicipalityLatestItem> municipalities, AddressMatchBuilder results) =>
 _latestQueries.GetAllPostalInfo()
 .Where(postalInfo => postalInfo.PostalNames.Any(
            postalName => postalName.PostalName.EqIgnoreDiacritics(results.Query.MunicipalityName)))
 .Select(postalInfo => new
 {
     PostalCode     = postalInfo.PostalCode,
     MissingNisCode = results.ContainsNisCode(postalInfo.NisCode) ? null : postalInfo.NisCode,
 })
 .SelectMany(x => municipalities
             .Where(g => g.NisCode == x.MissingNisCode)
             .Select(g => new Tuple <string, MunicipalityLatestItem>(x.PostalCode, g)));