using System.Data; using Dapper; using PlotLine.Models; namespace PlotLine.Data; public interface ISubscriptionRepository { Task GetCurrentSubscriptionAsync(int userId); Task GetSubscriptionLevelAsync(int subscriptionLevelId); Task> GetActiveSubscriptionLevelsAsync(); } public sealed class SubscriptionRepository(ISqlConnectionFactory connectionFactory) : ISubscriptionRepository { public async Task GetCurrentSubscriptionAsync(int userId) { using var connection = connectionFactory.CreateConnection(); return await connection.QuerySingleOrDefaultAsync( "dbo.UserSubscription_GetCurrent", new { UserID = userId }, commandType: CommandType.StoredProcedure); } public async Task GetSubscriptionLevelAsync(int subscriptionLevelId) { using var connection = connectionFactory.CreateConnection(); return await connection.QuerySingleOrDefaultAsync( "dbo.SubscriptionLevel_Get", new { SubscriptionLevelID = subscriptionLevelId }, commandType: CommandType.StoredProcedure); } public async Task> GetActiveSubscriptionLevelsAsync() { using var connection = connectionFactory.CreateConnection(); var rows = await connection.QueryAsync( "dbo.SubscriptionLevel_ListActive", commandType: CommandType.StoredProcedure); return rows.ToList(); } }