示例#1
0
 public async Task <IActionResult> SearchBestAddAddress(
     [FromServices] IActionContextAccessor actionContextAccessor,
     [FromServices] IOptions <MunicipalityOptions> responseOptions,
     [FromHeader(Name = HeaderNames.IfNoneMatch)] string ifNoneMatch,
     [FromBody] BosaAddressRequest searchBody,
     CancellationToken cancellationToken = default)
 => await SearchBestAddAddressWithFormat(
     null,
     actionContextAccessor,
     responseOptions,
     ifNoneMatch,
     searchBody,
     cancellationToken);
示例#2
0
        public async Task <IActionResult> Post(
            [FromServices] AddressBosaContext context,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            [FromBody] BosaAddressRequest addressRequest,
            CancellationToken cancellationToken = default)
        {
            if (Request.ContentLength.HasValue && Request.ContentLength > 0 && addressRequest == null)
            {
                return(Ok(new AddressBosaResponse()));
            }

            var query = new AddressBosaQuery(context, responseOptions.Value);

            return(Ok(await query.Filter(addressRequest)));
        }
        public async Task <IActionResult> SearchBestAddAddress(
            [FromServices] IActionContextAccessor actionContextAccessor,
            [FromServices] IOptions <MunicipalityOptions> responseOptions,
            [FromHeader(Name = HeaderNames.IfNoneMatch)] string ifNoneMatch,
            [FromBody] BosaAddressRequest searchBody,
            CancellationToken cancellationToken = default)
        {
            var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

            IRestRequest BackendRequest() => CreateBackendSearchBestAddRequest(searchBody);

            var value = await GetFromBackendAsync(
                contentFormat.ContentType,
                BackendRequest,
                CreateDefaultHandleBadRequest(),
                cancellationToken);

            return(BackendListResponseResult.Create(value, Request.Query, responseOptions.Value.VolgendeUrl));
        }
        public async Task <AddressBosaResponse> Filter(BosaAddressRequest filter)
        {
            var addressesQuery      = _context.AddressDetail.AsNoTracking().OrderBy(x => x.PersistentLocalId).Where(x => x.Complete && !x.Removed);
            var streetNamesQuery    = _context.StreetNameBosaItems.AsNoTracking().Where(x => x.IsComplete);
            var municipalitiesQuery = _context.MunicipalityBosaItems.AsNoTracking();

            if (filter?.IsOnlyAdresIdRequested == true && int.TryParse(filter.AdresCode?.ObjectId, out var adresId))
            {
                addressesQuery = addressesQuery
                                 .Where(a => a.PersistentLocalId == adresId)
                                 .ToList()
                                 .AsQueryable();

                var address = addressesQuery.FirstOrDefault();
                if (address == null)
                {
                    return new AddressBosaResponse {
                               Adressen = new List <AddressBosaResponseItem>()
                    }
                }
                ;

                streetNamesQuery = (await streetNamesQuery
                                    .Where(x => x.StreetNameId == address.StreetNameId)
                                    .ToListAsync())
                                   .AsQueryable();

                var streetName = streetNamesQuery.FirstOrDefault();

                municipalitiesQuery = (await municipalitiesQuery
                                       .Where(x => x.NisCode == streetName.NisCode)
                                       .ToListAsync())
                                      .AsQueryable();
            }

            var gemeenteCodeVersieId = filter?.GemeenteCode?.VersieId == null ? null : new Rfc3339SerializableDateTimeOffset(filter.GemeenteCode.VersieId.Value).ToString();

            var filteredMunicipalities = FilterMunicipalities(
                filter?.GemeenteCode?.ObjectId,
                gemeenteCodeVersieId,
                filter?.Gemeentenaam?.Spelling,
                filter?.Gemeentenaam?.Taal,
                filter?.Gemeentenaam?.SearchType ?? BosaSearchType.Bevat,
                municipalitiesQuery);

            var straatnaamCodeVersieId = filter?.StraatnaamCode?.VersieId == null ? null : new Rfc3339SerializableDateTimeOffset(filter.StraatnaamCode.VersieId.Value).ToString();
            var filteredStreetNames    = FilterStreetNames(
                filter?.StraatnaamCode?.ObjectId,
                straatnaamCodeVersieId,
                filter?.Straatnaam?.Spelling,
                filter?.Straatnaam?.Taal,
                filter?.Straatnaam?.SearchType ?? BosaSearchType.Bevat,
                streetNamesQuery,
                filteredMunicipalities);

            var filteredAddresses =
                FilterAddresses(
                    filter?.AdresCode?.ObjectId,
                    filter?.AdresCode?.VersieId,
                    filter?.Huisnummer,
                    filter?.Busnummer,
                    filter?.AdresStatus,
                    filter?.PostCode?.ObjectId,
                    addressesQuery,
                    filteredStreetNames)
                .OrderBy(x => x.PersistentLocalId);

            var municipalities = filteredMunicipalities.Select(x => new { x.NisCode, x.Version }).ToList();
            var streetNames    = filteredStreetNames.Select(x => new { x.StreetNameId, x.PersistentLocalId, x.Version, x.NisCode }).ToList();

            var addresses = filteredAddresses
                            .Take(1001)
                            .ToList()
                            .Select(x =>
            {
                var streetName = streetNames.First(y => y.StreetNameId == x.StreetNameId);

                var municipality = municipalities.First(y => y.NisCode == streetName.NisCode);
                var postalCode   = _context
                                   .PostalInfoLatestItems
                                   .AsNoTracking()
                                   .First(y => y.PostalCode == x.PostalCode);

                return(new AddressBosaResponseItem(
                           _responseOptions.PostInfoNaamruimte,
                           _responseOptions.GemeenteNaamruimte,
                           _responseOptions.StraatNaamNaamruimte,
                           _responseOptions.Naamruimte,
                           x.PersistentLocalId.Value,
                           AddressMapper.ConvertFromAddressStatus(x.Status),
                           x.HouseNumber,
                           x.BoxNumber,
                           x.OfficiallyAssigned,
                           AddressMapper.GetAddressPoint(x.Position),
                           AddressMapper.ConvertFromGeometryMethod(x.PositionMethod),
                           AddressMapper.ConvertFromGeometrySpecification(x.PositionSpecification),
                           x.VersionTimestamp.ToBelgianDateTimeOffset(),
                           streetName.PersistentLocalId,
                           streetName.Version,
                           municipality.NisCode,
                           municipality.Version,
                           x.PostalCode,
                           postalCode.Version));
            })
                            .ToList();

            return(new AddressBosaResponse
            {
                Adressen = addresses
            });
        }
示例#5
0
 private static IRestRequest CreateBackendSearchBestAddRequest(BosaAddressRequest searchBody)
 => new RestRequest("adressen/bosa", Method.POST).AddJsonBodyOrEmpty(searchBody);