Ejemplo n.º 1
0
        public async Task <IActionResult> PostBosaAddressRepresentations(
            [FromServices] LegacyContext context,
            [FromServices] SyndicationContext syndicationContext,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            [FromBody] BosaAddressRepresentationRequest request,
            CancellationToken cancellationToken = default)
        {
            if (Request.ContentLength.HasValue && Request.ContentLength > 0 && request == null)
            {
                return(Ok(new AddressRepresentationBosaResponse()));
            }

            if (string.IsNullOrEmpty(request?.AdresCode?.ObjectId) || !int.TryParse(request.AdresCode.ObjectId, out var addressId))
            {
                return(BadRequest("Valid objectId is required"));
            }

            var address = await context.AddressDetail.FirstOrDefaultAsync(x => x.PersistentLocalId == addressId, cancellationToken);

            if (address == null)
            {
                return(NotFound());
            }

            var streetName = await syndicationContext
                             .StreetNameBosaItems
                             .FirstOrDefaultAsync(x => x.StreetNameId == address.StreetNameId, cancellationToken);

            var municipality = await syndicationContext
                               .MunicipalityBosaItems
                               .FirstOrDefaultAsync(x => x.NisCode == streetName.NisCode, cancellationToken);

            var response = new AddressRepresentationBosaResponse
            {
                Identificator = new AdresIdentificator(responseOptions.Value.Naamruimte, address.PersistentLocalId.ToString(), address.VersionTimestamp.ToBelgianDateTimeOffset())
            };

            if (!request.Taal.HasValue || request.Taal.Value == municipality.PrimaryLanguage)
            {
                response.AdresVoorstellingen = new List <BosaAddressRepresentation>
                {
                    new BosaAddressRepresentation(
                        municipality.PrimaryLanguage.Value,
                        address.HouseNumber,
                        address.BoxNumber,
                        AddressMapper.GetVolledigAdres(address.HouseNumber, address.BoxNumber, address.PostalCode, streetName, municipality).GeografischeNaam.Spelling,
                        AddressMapper.GetDefaultMunicipalityName(municipality).Value,
                        AddressMapper.GetDefaultStreetNameName(streetName, municipality.PrimaryLanguage).Value,
                        address.PostalCode)
                };
            }

            return(Ok(response));
        }
 public async Task <IActionResult> SearchBestAddAddressRepresentation(
     [FromServices] IActionContextAccessor actionContextAccessor,
     [FromServices] IOptions <MunicipalityOptions> responseOptions,
     [FromHeader(Name = HeaderNames.IfNoneMatch)] string ifNoneMatch,
     [FromBody] BosaAddressRepresentationRequest searchBody,
     CancellationToken cancellationToken = default)
 => await SearchBestAddAddressRepresentationWithFormat(
     null,
     actionContextAccessor,
     responseOptions,
     ifNoneMatch,
     searchBody,
     cancellationToken);
Ejemplo n.º 3
0
        public async Task <IActionResult> SearchBestAddAddressRepresentation(
            [FromServices] IActionContextAccessor actionContextAccessor,
            [FromServices] IOptions <MunicipalityOptions> responseOptions,
            [FromHeader(Name = HeaderNames.IfNoneMatch)] string ifNoneMatch,
            [FromBody] BosaAddressRepresentationRequest 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));
        }
Ejemplo n.º 4
0
 private static IRestRequest CreateBackendSearchBestAddRequest(BosaAddressRepresentationRequest searchBody)
 => new RestRequest("adressen/bosa/adresvoorstellingen", Method.POST).AddJsonBodyOrEmpty(searchBody);