diff --git a/Kyoo.Common/Models/Episode.cs b/Kyoo.Common/Models/Episode.cs index f76d5078..0fd1efa3 100644 --- a/Kyoo.Common/Models/Episode.cs +++ b/Kyoo.Common/Models/Episode.cs @@ -25,7 +25,7 @@ namespace Kyoo.Models [JsonIgnore] public string ImgPrimary { get; set; } public string ExternalIDs { get; set; } - public IEnumerable Tracks { get; set; } + public virtual IEnumerable Tracks { get; set; } public string ShowTitle; //Used in the API response only public string Link; //Used in the API response only @@ -73,6 +73,13 @@ namespace Kyoo.Models return showSlug + "-s" + seasonNumber + "e" + episodeNumber; } + public Episode SetLink(string showSlug) + { + Link = GetSlug(showSlug, SeasonNumber, EpisodeNumber); + Thumb = "thumb/" + Link; + return this; + } + public Episode Merge(Episode other) { if (other == null) diff --git a/Kyoo.Common/Models/GenreLink.cs b/Kyoo.Common/Models/GenreLink.cs new file mode 100644 index 00000000..405a3847 --- /dev/null +++ b/Kyoo.Common/Models/GenreLink.cs @@ -0,0 +1,13 @@ +namespace Kyoo.Models +{ + public class GenreLink + { + // TODO Make json serializer ignore this class and only serialize the Genre child. + // TODO include this class in the EF workflows. + + public long ShowID { get; set; } + public virtual Show Show { get; set; } + public long GenreID { get; set; } + public virtual Genre Genre { get; set; } + } +} \ No newline at end of file diff --git a/Kyoo.Common/Models/PeopleLink.cs b/Kyoo.Common/Models/PeopleLink.cs index 54e5db4c..d766cac6 100644 --- a/Kyoo.Common/Models/PeopleLink.cs +++ b/Kyoo.Common/Models/PeopleLink.cs @@ -6,9 +6,9 @@ namespace Kyoo.Models { [JsonIgnore] public long ID { get; set; } [JsonIgnore] public long PeopleID { get; set; } - public People People { get; set; } + public virtual People People { get; set; } [JsonIgnore] public long ShowID { get; set; } - [JsonIgnore] public Show Show { get; set; } + [JsonIgnore] public virtual Show Show { get; set; } public string Role { get; set; } public string Type { get; set; } diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo/Controllers/LibraryManager.cs index 431d5936..4f9a8077 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo/Controllers/LibraryManager.cs @@ -77,12 +77,12 @@ namespace Kyoo.Controllers public Show GetShowBySlug(string slug) { Show ret = (from show in _database.Shows where show.Slug == slug select show).FirstOrDefault(); - if (ret == null) - return null; + // if (ret == null) + // return null; //_database.Entry(ret).Collection(x => x.Genres).Load(); - _database.Entry(ret).Reference(x => x.Studio).Load(); - _database.Entry(ret).Collection(x => x.People).Load(); - _database.Entry(ret).Collection(x => x.Seasons).Load(); + // _database.Entry(ret).Reference(x => x.Studio).Load(); + // _database.Entry(ret).Collection(x => x.People).Load(); + // _database.Entry(ret).Collection(x => x.Seasons).Load(); return ret; } @@ -114,26 +114,26 @@ namespace Kyoo.Controllers public IEnumerable GetEpisodes(string showSlug) { - return from episode in _database.Episodes where episode.Show.Slug == showSlug select episode; + return from episode in _database.Episodes where episode.Show.Slug == showSlug select episode.SetLink(showSlug); } public IEnumerable GetEpisodes(string showSlug, long seasonNumber) { return from episode in _database.Episodes where episode.SeasonNumber == seasonNumber - && episode.Show.Slug == showSlug select episode; + && episode.Show.Slug == showSlug select episode.SetLink(showSlug); } public IEnumerable GetEpisodes(long showID, long seasonNumber) { return from episode in _database.Episodes where episode.ShowID == showID - && episode.SeasonNumber == seasonNumber select episode; + && episode.SeasonNumber == seasonNumber select episode.SetLink(episode.Show.Slug); } public Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber) { return (from episode in _database.Episodes where episode.EpisodeNumber == episodeNumber && episode.SeasonNumber == seasonNumber - && episode.Show.Slug == showSlug select episode).FirstOrDefault(); + && episode.Show.Slug == showSlug select episode.SetLink(showSlug)).FirstOrDefault(); } public WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true) diff --git a/Kyoo/Kyoo.csproj b/Kyoo/Kyoo.csproj index 09c37be3..12d127eb 100644 --- a/Kyoo/Kyoo.csproj +++ b/Kyoo/Kyoo.csproj @@ -30,6 +30,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index 1e0bdcbf..a7cc97ed 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -33,7 +33,8 @@ namespace Kyoo services.AddControllers().AddNewtonsoftJson(); services.AddHttpClient(); - services.AddDbContext(options => options.UseSqlite(Configuration.GetConnectionString("Database"))); + services.AddDbContext(options => options.UseLazyLoadingProxies() + .UseSqlite(Configuration.GetConnectionString("Database"))); // services.AddIdentity() // .AddEntityFrameworkStores()