diff --git a/Kyoo.Common/Utility.cs b/Kyoo.Common/Utility.cs index 2922acec..19b23564 100644 --- a/Kyoo.Common/Utility.cs +++ b/Kyoo.Common/Utility.cs @@ -71,7 +71,7 @@ namespace Kyoo if (isEqual == null) return first.Concat(second).ToList(); List list = first.ToList(); - return list.Concat(second.Where(x => !list.Any(y => isEqual(x, y)))).ToList(); + return list.Concat(second.Where(x => !list.Any(y => isEqual(x, y)))); } public static T Assign(T first, T second) diff --git a/Kyoo/Controllers/Repositories/ShowRepository.cs b/Kyoo/Controllers/Repositories/ShowRepository.cs index 03505365..0991eda7 100644 --- a/Kyoo/Controllers/Repositories/ShowRepository.cs +++ b/Kyoo/Controllers/Repositories/ShowRepository.cs @@ -84,9 +84,17 @@ namespace Kyoo.Controllers { await base.Create(obj); _database.Entry(obj).State = EntityState.Added; + if (obj.GenreLinks != null) + { foreach (GenreLink entry in obj.GenreLinks) + { + if (!(entry.Genre is GenreDE)) + entry.Genre = new GenreDE(entry.Genre); _database.Entry(entry).State = EntityState.Added; + } + } + if (obj.People != null) foreach (PeopleRole entry in obj.People) _database.Entry(entry).State = EntityState.Added; diff --git a/Kyoo/Models/Resources/CollectionDE.cs b/Kyoo/Models/Resources/CollectionDE.cs index 3f23faf8..8cafc83f 100644 --- a/Kyoo/Models/Resources/CollectionDE.cs +++ b/Kyoo/Models/Resources/CollectionDE.cs @@ -7,21 +7,21 @@ namespace Kyoo.Models { public class CollectionDE : Collection { - [JsonIgnore] [NotMergable] public virtual IEnumerable Links { get; set; } + [JsonIgnore] [NotMergable] public virtual ICollection Links { get; set; } [ExpressionRewrite(nameof(Links), nameof(CollectionLink.Show))] public override IEnumerable Shows { get => Links?.Select(x => x.Show); - set => Links = value?.Select(x => new CollectionLink(this, x)); + set => Links = value?.Select(x => new CollectionLink(this, x)).ToList(); } - [JsonIgnore] [NotMergable] public virtual IEnumerable LibraryLinks { get; set; } + [JsonIgnore] [NotMergable] public virtual ICollection LibraryLinks { get; set; } [ExpressionRewrite(nameof(LibraryLinks), nameof(GenreLink.Genre))] public override IEnumerable Libraries { get => LibraryLinks?.Select(x => x.Library); - set => LibraryLinks = value?.Select(x => new LibraryLink(x, this)); + set => LibraryLinks = value?.Select(x => new LibraryLink(x, this)).ToList(); } public CollectionDE() {} diff --git a/Kyoo/Models/Resources/GenreDE.cs b/Kyoo/Models/Resources/GenreDE.cs index 3d5172ab..03443d66 100644 --- a/Kyoo/Models/Resources/GenreDE.cs +++ b/Kyoo/Models/Resources/GenreDE.cs @@ -7,13 +7,13 @@ namespace Kyoo.Models { public class GenreDE : Genre { - [JsonIgnore] [NotMergable] public virtual IEnumerable Links { get; set; } + [JsonIgnore] [NotMergable] public virtual ICollection Links { get; set; } [ExpressionRewrite(nameof(Links), nameof(GenreLink.Genre))] [JsonIgnore] [NotMergable] public override IEnumerable Shows { get => Links?.Select(x => x.Show); - set => Links = value?.Select(x => new GenreLink(x, this)); + set => Links = value?.Select(x => new GenreLink(x, this)).ToList(); } public GenreDE() {} diff --git a/Kyoo/Models/Resources/LibraryDE.cs b/Kyoo/Models/Resources/LibraryDE.cs index 652eaa88..3ddc6cd6 100644 --- a/Kyoo/Models/Resources/LibraryDE.cs +++ b/Kyoo/Models/Resources/LibraryDE.cs @@ -7,7 +7,7 @@ namespace Kyoo.Models { public class LibraryDE : Library { - [JsonIgnore] [NotMergable] public virtual IEnumerable ProviderLinks { get; set; } + [JsonIgnore] [NotMergable] public virtual ICollection ProviderLinks { get; set; } [ExpressionRewrite(nameof(ProviderLinks), nameof(ProviderLink.Provider))] public override IEnumerable Providers { @@ -15,14 +15,14 @@ namespace Kyoo.Models set => ProviderLinks = value?.Select(x => new ProviderLink(x, this)).ToList(); } - [JsonIgnore] [NotMergable] public virtual IEnumerable Links { get; set; } + [JsonIgnore] [NotMergable] public virtual ICollection Links { get; set; } [ExpressionRewrite(nameof(Links), nameof(LibraryLink.Show))] public override IEnumerable Shows { get => Links?.Where(x => x.Show != null).Select(x => x.Show); set => Links = Utility.MergeLists( value?.Select(x => new LibraryLink(this, x)), - Links?.Where(x => x.Show == null)); + Links?.Where(x => x.Show == null))?.ToList(); } [ExpressionRewrite(nameof(Links), nameof(LibraryLink.Collection))] public override IEnumerable Collections @@ -30,7 +30,7 @@ namespace Kyoo.Models get => Links?.Where(x => x.Collection != null).Select(x => x.Collection); set => Links = Utility.MergeLists( value?.Select(x => new LibraryLink(this, x)), - Links?.Where(x => x.Collection == null)); + Links?.Where(x => x.Collection == null))?.ToList(); } public LibraryDE() {} diff --git a/Kyoo/Models/Resources/ShowDE.cs b/Kyoo/Models/Resources/ShowDE.cs index c7c3b170..31d68100 100644 --- a/Kyoo/Models/Resources/ShowDE.cs +++ b/Kyoo/Models/Resources/ShowDE.cs @@ -10,28 +10,28 @@ namespace Kyoo.Models { public class ShowDE : Show { - [JsonIgnore] [NotMergable] public virtual IEnumerable GenreLinks { get; set; } + [JsonIgnore] [NotMergable] public virtual ICollection GenreLinks { get; set; } [ExpressionRewrite(nameof(GenreLinks), nameof(GenreLink.Genre))] public override IEnumerable Genres { get => GenreLinks?.Select(x => x.Genre); - set => GenreLinks = value?.Select(x => new GenreLink(this, x)); + set => GenreLinks = value?.Select(x => new GenreLink(this, x)).ToList(); } - [JsonIgnore] [NotMergable] public virtual IEnumerable LibraryLinks { get; set; } + [JsonIgnore] [NotMergable] public virtual ICollection LibraryLinks { get; set; } [ExpressionRewrite(nameof(LibraryLinks), nameof(LibraryLink.Library))] public override IEnumerable Libraries { get => LibraryLinks?.Select(x => x.Library); - set => LibraryLinks = value?.Select(x => new LibraryLink(x, this)); + set => LibraryLinks = value?.Select(x => new LibraryLink(x, this)).ToList(); } - [JsonIgnore] [NotMergable] public virtual IEnumerable CollectionLinks { get; set; } + [JsonIgnore] [NotMergable] public virtual ICollection CollectionLinks { get; set; } [ExpressionRewrite(nameof(CollectionLinks), nameof(CollectionLink.Collection))] public override IEnumerable Collections { get => CollectionLinks?.Select(x => x.Collection); - set => CollectionLinks = value?.Select(x => new CollectionLink(x, this)); + set => CollectionLinks = value?.Select(x => new CollectionLink(x, this)).ToList(); } public ShowDE() {}