41 lines
1.9 KiB
C#
41 lines
1.9 KiB
C#
using System.Data;
|
|
using Dapper;
|
|
using PlotLine.Services;
|
|
namespace PlotLine.Data;
|
|
|
|
public interface IAppearanceRepository
|
|
{
|
|
Task<ApplicationAppearance> GetAsync(int userId);
|
|
Task SaveThemeAsync(int userId, string themeKey, bool onlyIfUnset = false);
|
|
Task SaveRibbonAsync(int userId, bool collapsed);
|
|
Task SaveApplicationBarAsync(int userId, bool showProjectContextMenu, bool showBookContextMenu);
|
|
}
|
|
public sealed class AppearanceRepository(ISqlConnectionFactory connections) : IAppearanceRepository
|
|
{
|
|
public async Task<ApplicationAppearance> GetAsync(int userId)
|
|
{
|
|
using var connection = connections.CreateConnection();
|
|
return await connection.QuerySingleOrDefaultAsync<ApplicationAppearance>("dbo.UserAppearance_Get", new { UserID = userId }, commandType: CommandType.StoredProcedure) ?? new();
|
|
}
|
|
public async Task SaveThemeAsync(int userId, string themeKey, bool onlyIfUnset = false)
|
|
{
|
|
using var connection = connections.CreateConnection();
|
|
await connection.ExecuteAsync("dbo.UserAppearance_SaveTheme", new { UserID = userId, ThemeKey = themeKey, OnlyIfUnset = onlyIfUnset }, commandType: CommandType.StoredProcedure);
|
|
}
|
|
public async Task SaveRibbonAsync(int userId, bool collapsed)
|
|
{
|
|
using var connection = connections.CreateConnection();
|
|
await connection.ExecuteAsync("dbo.UserAppearance_SaveRibbon", new { UserID = userId, Collapsed = collapsed }, commandType: CommandType.StoredProcedure);
|
|
}
|
|
public async Task SaveApplicationBarAsync(int userId, bool showProjectContextMenu, bool showBookContextMenu)
|
|
{
|
|
using var connection = connections.CreateConnection();
|
|
await connection.ExecuteAsync("dbo.UserAppearance_SaveApplicationBar", new
|
|
{
|
|
UserID = userId,
|
|
ShowProjectContextMenu = showProjectContextMenu,
|
|
ShowBookContextMenu = showBookContextMenu
|
|
}, commandType: CommandType.StoredProcedure);
|
|
}
|
|
}
|