Exemplo n.º 1
0
 public void RequestPersistentLocalId(IPersistentLocalIdGenerator persistentLocalIdGenerator)
 {
     if (_persistentLocalId == null)
     {
         AssignPersistentLocalId(persistentLocalIdGenerator.GenerateNextPersistentLocalId(), new PersistentLocalIdAssignmentDate(Instant.FromDateTimeOffset(DateTimeOffset.Now)));
     }
 }
Exemplo n.º 2
0
 public void RequestPersistentLocalId(IPersistentLocalIdGenerator persistentLocalIdGenerator)
 {
     if (PersistentLocalId == null)
     {
         AssignPersistentLocalId(
             persistentLocalIdGenerator.GenerateNextPersistentLocalId(),
             new PersistentLocalIdAssignmentDate(Instant.FromDateTimeOffset(DateTimeOffset.Now))); // TODO: Refactor this to use IClock
     }
 }
        public async Task <IActionResult> Propose(
            [FromServices] IOptions <ResponseOptions> options,
            [FromServices] IdempotencyContext idempotencyContext,
            [FromServices] SyndicationContext syndicationContext,
            [FromServices] IPersistentLocalIdGenerator persistentLocalIdGenerator,
            [FromBody] StreetNameProposeRequest streetNameProposeRequest,
            CancellationToken cancellationToken = default)
        {
            try
            {
                //TODO REMOVE WHEN IMPLEMENTED
                return(new CreatedWithETagResult(new Uri(string.Format(options.Value.DetailUrl, "1")), "1"));

                //TODO real data please
                var fakeProvenanceData = new Provenance(
                    DateTime.UtcNow.ToInstant(),
                    Application.StreetNameRegistry,
                    new Reason(""),
                    new Operator(""),
                    Modification.Insert,
                    Organisation.DigitaalVlaanderen
                    );

                var identifier = streetNameProposeRequest.GemeenteId
                                 .AsIdentifier()
                                 .Map(IdentifierMappings.MunicipalityNisCode);

                var municipality = await syndicationContext.MunicipalityLatestItems
                                   .AsNoTracking()
                                   .SingleOrDefaultAsync(i =>
                                                         i.NisCode == identifier.Value, cancellationToken);

                var persistentLocalId = persistentLocalIdGenerator.GenerateNextPersistentLocalId();
                var cmd      = streetNameProposeRequest.ToCommand(new MunicipalityId(municipality.MunicipalityId), fakeProvenanceData, persistentLocalId);
                var position = await IdempotentCommandHandlerDispatch(idempotencyContext, cmd.CreateCommandId(), cmd, cancellationToken);

                return(new CreatedWithLastObservedPositionAsETagResult(new Uri(string.Format(options.Value.DetailUrl, persistentLocalId)), position.ToString(), Application.StreetNameRegistry.ToString()));
            }
            catch (IdempotencyException)
            {
                return(Accepted());
            }
        }