PlotDirector/PlotLine/Data/WriterObjectiveRepository.cs

19 lines
975 B
C#

using System.Data;
using Dapper;
using PlotLine.Models;
namespace PlotLine.Data;
public sealed class WriterObjectiveRepository(ISqlConnectionFactory factory)
{
public async Task<(WriterObjective? Objective, IReadOnlyList<WriterObjectiveChoice> Choices)> Read(int user, int book)
{
using var db = factory.CreateConnection();
using var rows = await db.QueryMultipleAsync("dbo.WriterObjective", new { UserID = user, BookID = book, Action = "read" }, commandType: CommandType.StoredProcedure);
return (await rows.ReadSingleOrDefaultAsync<WriterObjective>(), (await rows.ReadAsync<WriterObjectiveChoice>()).ToArray());
}
public async Task Save(int user, WriterObjective value)
{
using var db = factory.CreateConnection();
await db.ExecuteAsync("dbo.WriterObjective", new { UserID = user, value.BookID, value.ChapterID, value.SceneID, value.Activity, Action = "save" }, commandType: CommandType.StoredProcedure);
}
}