Exemple #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));
        }
Exemple #2
0
        public async Task <IActionResult> Get(
            [FromServices] LegacyContext context,
            [FromServices] SyndicationContext syndicationContext,
            [FromServices] IOptions <ResponseOptions> responseOptions,
            [FromRoute] int persistentLocalId,
            [FromRoute] Taal?taal,
            CancellationToken cancellationToken = default)
        {
            var address = await context
                          .AddressDetail
                          .AsNoTracking()
                          .SingleOrDefaultAsync(item => item.PersistentLocalId == persistentLocalId, cancellationToken);

            if (address != null && address.Removed)
            {
                throw new ApiException("Adres werd verwijderd.", StatusCodes.Status410Gone);
            }

            if (address == null || !address.Complete)
            {
                throw new ApiException("Onbestaand adres.", StatusCodes.Status404NotFound);
            }

            var streetName = await syndicationContext.StreetNameLatestItems.FindAsync(new object[] { address.StreetNameId }, cancellationToken);

            var municipality = await syndicationContext.MunicipalityLatestItems.FirstAsync(m => m.NisCode == streetName.NisCode, cancellationToken);

            var defaultMunicipalityName = AddressMapper.GetDefaultMunicipalityName(municipality);
            var defaultStreetName       = AddressMapper.GetDefaultStreetNameName(streetName, municipality.PrimaryLanguage);
            var defaultHomonymAddition  = AddressMapper.GetDefaultHomonymAddition(streetName, municipality.PrimaryLanguage);

            var gemeente = new AdresDetailGemeente(
                municipality.NisCode,
                string.Format(responseOptions.Value.GemeenteDetailUrl, municipality.NisCode),
                new GeografischeNaam(defaultMunicipalityName.Value, defaultMunicipalityName.Key));

            var straat = new AdresDetailStraatnaam(
                streetName.PersistentLocalId,
                string.Format(responseOptions.Value.StraatnaamDetailUrl, streetName.PersistentLocalId),
                new GeografischeNaam(defaultStreetName.Value, defaultStreetName.Key));

            var postInfo = string.IsNullOrEmpty(address.PostalCode)
                ? null
                : new AdresDetailPostinfo(
                address.PostalCode,
                string.Format(responseOptions.Value.PostInfoDetailUrl, address.PostalCode));

            var homoniemToevoeging = defaultHomonymAddition == null
                ? null
                : new HomoniemToevoeging(new GeografischeNaam(defaultHomonymAddition.Value.Value, defaultHomonymAddition.Value.Key));

            return(Ok(
                       new AddressResponse(
                           responseOptions.Value.Naamruimte,
                           address.PersistentLocalId.ToString(),
                           address.HouseNumber,
                           address.BoxNumber,
                           gemeente,
                           straat,
                           homoniemToevoeging,
                           postInfo,
                           AddressMapper.GetAddressPoint(address.Position),
                           AddressMapper.ConvertFromGeometryMethod(address.PositionMethod),
                           AddressMapper.ConvertFromGeometrySpecification(address.PositionSpecification),
                           AddressMapper.ConvertFromAddressStatus(address.Status),
                           defaultStreetName.Key,
                           address.OfficiallyAssigned,
                           address.VersionTimestamp.ToBelgianDateTimeOffset())));
        }