aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs')
-rw-r--r--Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs31
1 files changed, 14 insertions, 17 deletions
diff --git a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs
index c89e3c74d..bfae81e4c 100644
--- a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs
+++ b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs
@@ -15,15 +15,15 @@ namespace Jellyfin.Server.Implementations.Users
/// </summary>
public class DisplayPreferencesManager : IDisplayPreferencesManager
{
- private readonly JellyfinDb _dbContext;
+ private readonly JellyfinDbContext _dbContext;
/// <summary>
/// Initializes a new instance of the <see cref="DisplayPreferencesManager"/> class.
/// </summary>
- /// <param name="dbContext">The database context.</param>
- public DisplayPreferencesManager(JellyfinDb dbContext)
+ /// <param name="dbContextFactory">The database context factory.</param>
+ public DisplayPreferencesManager(IDbContextFactory<JellyfinDbContext> dbContextFactory)
{
- _dbContext = dbContext;
+ _dbContext = dbContextFactory.CreateDbContext();
}
/// <inheritdoc />
@@ -32,9 +32,9 @@ namespace Jellyfin.Server.Implementations.Users
var prefs = _dbContext.DisplayPreferences
.Include(pref => pref.HomeSections)
.FirstOrDefault(pref =>
- pref.UserId == userId && string.Equals(pref.Client, client) && pref.ItemId == itemId);
+ pref.UserId.Equals(userId) && string.Equals(pref.Client, client) && pref.ItemId.Equals(itemId));
- if (prefs == null)
+ if (prefs is null)
{
prefs = new DisplayPreferences(userId, itemId, client);
_dbContext.DisplayPreferences.Add(prefs);
@@ -47,9 +47,9 @@ namespace Jellyfin.Server.Implementations.Users
public ItemDisplayPreferences GetItemDisplayPreferences(Guid userId, Guid itemId, string client)
{
var prefs = _dbContext.ItemDisplayPreferences
- .FirstOrDefault(pref => pref.UserId == userId && pref.ItemId == itemId && string.Equals(pref.Client, client));
+ .FirstOrDefault(pref => pref.UserId.Equals(userId) && pref.ItemId.Equals(itemId) && string.Equals(pref.Client, client));
- if (prefs == null)
+ if (prefs is null)
{
prefs = new ItemDisplayPreferences(userId, Guid.Empty, client);
_dbContext.ItemDisplayPreferences.Add(prefs);
@@ -62,8 +62,7 @@ namespace Jellyfin.Server.Implementations.Users
public IList<ItemDisplayPreferences> ListItemDisplayPreferences(Guid userId, string client)
{
return _dbContext.ItemDisplayPreferences
- .AsQueryable()
- .Where(prefs => prefs.UserId == userId && prefs.ItemId != Guid.Empty && string.Equals(prefs.Client, client))
+ .Where(prefs => prefs.UserId.Equals(userId) && !prefs.ItemId.Equals(default) && string.Equals(prefs.Client, client))
.ToList();
}
@@ -71,20 +70,18 @@ namespace Jellyfin.Server.Implementations.Users
public Dictionary<string, string?> ListCustomItemDisplayPreferences(Guid userId, Guid itemId, string client)
{
return _dbContext.CustomItemDisplayPreferences
- .AsQueryable()
- .Where(prefs => prefs.UserId == userId
- && prefs.ItemId == itemId
+ .Where(prefs => prefs.UserId.Equals(userId)
+ && prefs.ItemId.Equals(itemId)
&& string.Equals(prefs.Client, client))
.ToDictionary(prefs => prefs.Key, prefs => prefs.Value);
}
/// <inheritdoc />
- public void SetCustomItemDisplayPreferences(Guid userId, Guid itemId, string client, Dictionary<string, string> customPreferences)
+ public void SetCustomItemDisplayPreferences(Guid userId, Guid itemId, string client, Dictionary<string, string?> customPreferences)
{
var existingPrefs = _dbContext.CustomItemDisplayPreferences
- .AsQueryable()
- .Where(prefs => prefs.UserId == userId
- && prefs.ItemId == itemId
+ .Where(prefs => prefs.UserId.Equals(userId)
+ && prefs.ItemId.Equals(itemId)
&& string.Equals(prefs.Client, client));
_dbContext.CustomItemDisplayPreferences.RemoveRange(existingPrefs);