PlotDirector/PlotLine/Data/ProjectRestorePointRepository.cs
2026-06-05 16:15:49 +01:00

51 lines
2.0 KiB
C#

using System.Data;
using Dapper;
using PlotLine.Models;
namespace PlotLine.Data;
public interface IProjectRestorePointRepository
{
Task<IReadOnlyList<ProjectRestorePoint>> ListAsync(int projectId);
Task<ProjectRestorePoint?> GetAsync(int projectRestorePointId, int projectId);
Task<ProjectRestorePoint> CreateAsync(int projectId, string restorePointName, string restorePointType, string jsonData, string? notes);
}
public sealed class ProjectRestorePointRepository(ISqlConnectionFactory connectionFactory) : IProjectRestorePointRepository
{
public async Task<IReadOnlyList<ProjectRestorePoint>> ListAsync(int projectId)
{
using var connection = connectionFactory.CreateConnection();
var rows = await connection.QueryAsync<ProjectRestorePoint>(
"dbo.ProjectRestorePoint_List",
new { ProjectID = projectId },
commandType: CommandType.StoredProcedure);
return rows.ToList();
}
public async Task<ProjectRestorePoint?> GetAsync(int projectRestorePointId, int projectId)
{
using var connection = connectionFactory.CreateConnection();
return await connection.QuerySingleOrDefaultAsync<ProjectRestorePoint>(
"dbo.ProjectRestorePoint_Get",
new { ProjectRestorePointID = projectRestorePointId, ProjectID = projectId },
commandType: CommandType.StoredProcedure);
}
public async Task<ProjectRestorePoint> CreateAsync(int projectId, string restorePointName, string restorePointType, string jsonData, string? notes)
{
using var connection = connectionFactory.CreateConnection();
return await connection.QuerySingleAsync<ProjectRestorePoint>(
"dbo.ProjectRestorePoint_Create",
new
{
ProjectID = projectId,
RestorePointName = restorePointName,
RestorePointType = restorePointType,
JsonData = jsonData,
Notes = notes
},
commandType: CommandType.StoredProcedure);
}
}