diff options
| author | Patrick Barron <barronpm@gmail.com> | 2020-07-27 20:40:21 -0400 |
|---|---|---|
| committer | Patrick Barron <barronpm@gmail.com> | 2020-07-27 20:40:21 -0400 |
| commit | 68a185fd02844698ac5ecd5618d590ae254d95cf (patch) | |
| tree | c4efd898494ba80674d75c9c834ffe848927eb11 /Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs | |
| parent | 592d2480ca9c424c7b8b8f4be2bdfa81b4476f0c (diff) | |
Serialize/deserialize new entities properly.
Diffstat (limited to 'Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs')
| -rw-r--r-- | Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs index b7c65fc2c..7c5c5a3ec 100644 --- a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs +++ b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs @@ -1,6 +1,7 @@ #pragma warning disable CA1307 using System; +using System.Collections.Generic; using System.Linq; using Jellyfin.Data.Entities; using MediaBrowser.Controller; @@ -31,11 +32,11 @@ namespace Jellyfin.Server.Implementations.Users var prefs = dbContext.DisplayPreferences .Include(pref => pref.HomeSections) .FirstOrDefault(pref => - pref.UserId == userId && pref.ItemId == null && string.Equals(pref.Client, client)); + pref.UserId == userId && string.Equals(pref.Client, client)); if (prefs == null) { - prefs = new DisplayPreferences(client, userId); + prefs = new DisplayPreferences(userId, client); dbContext.DisplayPreferences.Add(prefs); } @@ -43,11 +44,45 @@ namespace Jellyfin.Server.Implementations.Users } /// <inheritdoc /> + public ItemDisplayPreferences GetItemDisplayPreferences(Guid userId, Guid itemId, string client) + { + using var dbContext = _dbProvider.CreateContext(); + var prefs = dbContext.ItemDisplayPreferences + .FirstOrDefault(pref => pref.UserId == userId && pref.ItemId == itemId && string.Equals(pref.Client, client)); + + if (prefs == null) + { + prefs = new ItemDisplayPreferences(userId, Guid.Empty, client); + dbContext.ItemDisplayPreferences.Add(prefs); + } + + return prefs; + } + + /// <inheritdoc /> + public IList<ItemDisplayPreferences> ListItemDisplayPreferences(Guid userId, string client) + { + using var dbContext = _dbProvider.CreateContext(); + + return dbContext.ItemDisplayPreferences + .Where(prefs => prefs.UserId == userId && prefs.ItemId != Guid.Empty && string.Equals(prefs.Client, client)) + .ToList(); + } + + /// <inheritdoc /> public void SaveChanges(DisplayPreferences preferences) { using var dbContext = _dbProvider.CreateContext(); dbContext.Update(preferences); dbContext.SaveChanges(); } + + /// <inheritdoc /> + public void SaveChanges(ItemDisplayPreferences preferences) + { + using var dbContext = _dbProvider.CreateContext(); + dbContext.Update(preferences); + dbContext.SaveChanges(); + } } } |
