using System.Data; using Dapper; using PlotLine.Models; namespace PlotLine.Data; public sealed class WriterObjectiveRepository(ISqlConnectionFactory factory) { public async Task<(WriterObjective? Objective, IReadOnlyList 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(), (await rows.ReadAsync()).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); } }