public async Task <IActionResult> Correct( [FromServices] AddressCrabEditClient editClient, [FromServices] LegacyContext context, [FromServices] IStreamStore streamStore, [FromRoute] string lokaleIdentificator, [FromBody] CorrectAddressRequest request, CancellationToken cancellationToken) { // TODO: Turn this into proper VBR API Validation if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var persistentLocalId = int.Parse(lokaleIdentificator); // todo: should become position from bus.Dispatch var position = await streamStore.ReadHeadPosition(cancellationToken); var addressId = context .CrabIdToPersistentLocalIds .Single(item => item.PersistentLocalId == persistentLocalId); CrabEditClientResult crabEditResult; if (addressId.HouseNumberId.HasValue) { crabEditResult = await editClient.CorrectHouseNumber(addressId.HouseNumberId.Value, request, cancellationToken); } else if (addressId.SubaddressId.HasValue) { crabEditResult = await editClient.CorrectSubaddress(addressId.SubaddressId.Value, request, cancellationToken); } else { throw new InvalidOperationException(); } return(AcceptedWithPosition( position, crabEditResult.ExecutionTime)); }
public async Task <CrabEditClientResult> CorrectSubaddress( int subaddressId, CorrectAddressRequest request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var updateResponse = await _client.Update( new EditSubaddress { SubaddressId = subaddressId, OfficiallyAssigned = request.OfficiallyAssigned, Position = MapPosition(request.Position), PostalCode = request.PostalCode.AsIdentifier().Map(IdentifierMappings.PostalCode), Status = request.Status.AsIdentifier().Map(IdentifierMappings.AddressStatus), IsCorrection = true, }, cancellationToken); return(CrabEditClientResult.From(updateResponse)); }