public async Task UpsertStatuses(IReadOnlyCollection <ResourceSearchParameterStatus> statuses, CancellationToken cancellationToken) { EnsureArg.IsNotNull(statuses, nameof(statuses)); if (!statuses.Any()) { return; } if (_schemaInformation.Current < SchemaVersionConstants.SearchParameterStatusSchemaVersion) { throw new BadRequestException(Resources.SchemaVersionNeedsToBeUpgraded); } using (IScoped <SqlConnectionWrapperFactory> scopedSqlConnectionWrapperFactory = _scopedSqlConnectionWrapperFactory()) using (SqlConnectionWrapper sqlConnectionWrapper = await scopedSqlConnectionWrapperFactory.Value.ObtainSqlConnectionWrapperAsync(cancellationToken, true)) using (SqlCommandWrapper sqlCommandWrapper = sqlConnectionWrapper.CreateSqlCommand()) { VLatest.UpsertSearchParams.PopulateCommand(sqlCommandWrapper, _updateSearchParamsTvpGenerator.Generate(statuses.ToList())); using (SqlDataReader sqlDataReader = await sqlCommandWrapper.ExecuteReaderAsync(CommandBehavior.SequentialAccess, cancellationToken)) { while (await sqlDataReader.ReadAsync(cancellationToken)) { // The upsert procedure returns the search parameters that were new. (short searchParamId, string searchParamUri) = sqlDataReader.ReadRow(VLatest.SearchParam.SearchParamId, VLatest.SearchParam.Uri); // Add the new search parameters to the FHIR model dictionary. _fhirModel.TryAddSearchParamIdToUriMapping(searchParamUri, searchParamId); } } } }
// TODO: Make cancellation token an input. public async Task UpsertStatuses(List <ResourceSearchParameterStatus> statuses) { EnsureArg.IsNotNull(statuses, nameof(statuses)); if (!statuses.Any()) { return; } if (_schemaInformation.Current < SchemaVersionConstants.SearchParameterStatusSchemaVersion) { throw new BadRequestException(Resources.SchemaVersionNeedsToBeUpgraded); } using (IScoped <SqlConnectionWrapperFactory> scopedSqlConnectionWrapperFactory = _scopedSqlConnectionWrapperFactory()) using (SqlConnectionWrapper sqlConnectionWrapper = await scopedSqlConnectionWrapperFactory.Value.ObtainSqlConnectionWrapperAsync(CancellationToken.None, true)) using (SqlCommandWrapper sqlCommandWrapper = sqlConnectionWrapper.CreateSqlCommand()) { VLatest.UpsertSearchParams.PopulateCommand(sqlCommandWrapper, _updateSearchParamsTvpGenerator.Generate(statuses)); await sqlCommandWrapper.ExecuteNonQueryAsync(CancellationToken.None); } }