Fix settings add buttons and verify catalog inserts against SQL.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-29 08:58:16 +02:00
co-authored by Cursor
parent ed6777ffed
commit 09b31a4ac9
3 changed files with 340 additions and 63 deletions
@@ -1299,6 +1299,81 @@ public sealed class SonicSetupRepository
return Convert.ToInt32(result);
}
public async Task<bool> ExistsSonicConnectionAsync(
int sonicConnectionId,
CancellationToken cancellationToken = default)
{
return await ExistsAsync(
"""
SELECT 1
FROM [dbo].[SonicConnection]
WHERE [SonicConnectionId] = @Id
AND [IsActive] = 1;
""",
sonicConnectionId,
cancellationToken);
}
public async Task<bool> ExistsSonicContainerAsync(
int sonicContainerId,
CancellationToken cancellationToken = default)
{
return await ExistsAsync(
"""
SELECT 1
FROM [dbo].[SonicContainer]
WHERE [SonicContainerId] = @Id
AND [IsActive] = 1;
""",
sonicContainerId,
cancellationToken);
}
public async Task<bool> ExistsCertificateTargetAsync(
int certificateTargetId,
CancellationToken cancellationToken = default)
{
return await ExistsAsync(
"""
SELECT 1
FROM [dbo].[CertificateTarget]
WHERE [CertificateTargetId] = @Id
AND [IsActive] = 1;
""",
certificateTargetId,
cancellationToken);
}
private async Task<bool> ExistsAsync(
string sql,
int id,
CancellationToken cancellationToken)
{
if (id <= 0)
{
return false;
}
await using SqlConnection connection =
new(_connectionString);
await connection.OpenAsync(cancellationToken);
await using SqlCommand command =
new(sql, connection);
command.Parameters.Add(
new SqlParameter("@Id", SqlDbType.Int)
{
Value = id
});
object? result =
await command.ExecuteScalarAsync(cancellationToken);
return result is not null && result is not DBNull;
}
private static string RequireTrimmed(
string? value,
int maxLength,