PlotDirector/PlotLine/Data/CharacterIntelligenceRepository.cs

41 lines
1.7 KiB
C#

using Dapper;
using PlotLine.Models;
namespace PlotLine.Data;
public interface ICharacterIntelligenceRepository
{
Task<IReadOnlyList<CharacterIntelligenceProfile>> ListProfilesAsync(int importSessionId);
Task<CharacterIntelligenceProfile> UpsertProfileAsync(CharacterIntelligenceProfileSave request);
Task AddEvidenceAsync(CharacterIntelligenceEvidenceSave request);
}
public sealed class CharacterIntelligenceRepository(ISqlConnectionFactory connectionFactory) : ICharacterIntelligenceRepository
{
public async Task<IReadOnlyList<CharacterIntelligenceProfile>> ListProfilesAsync(int importSessionId)
{
using var connection = connectionFactory.CreateConnection();
var rows = await connection.QueryAsync<CharacterIntelligenceProfile>(
"dbo.CharacterIntelligence_ListProfiles",
new { ImportSessionID = importSessionId }, commandType: System.Data.CommandType.StoredProcedure);
return rows.ToList();
}
public async Task<CharacterIntelligenceProfile> UpsertProfileAsync(CharacterIntelligenceProfileSave request)
{
using var connection = connectionFactory.CreateConnection();
return await connection.QuerySingleAsync<CharacterIntelligenceProfile>(
"dbo.CharacterIntelligence_UpsertProfile",
request,commandType:System.Data.CommandType.StoredProcedure);
}
public async Task AddEvidenceAsync(CharacterIntelligenceEvidenceSave request)
{
using var connection = connectionFactory.CreateConnection();
await connection.ExecuteAsync(
"dbo.CharacterIntelligence_AddEvidence",
request, commandType: System.Data.CommandType.StoredProcedure);
}
}