Fixing a bug with the registration of shows

This commit is contained in:
Zoe Roux 2020-09-21 00:04:59 +02:00
parent 6575cb5ea6
commit 522d253e9c
6 changed files with 25 additions and 17 deletions

View File

@ -71,7 +71,7 @@ namespace Kyoo
if (isEqual == null) if (isEqual == null)
return first.Concat(second).ToList(); return first.Concat(second).ToList();
List<T> list = first.ToList(); List<T> 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>(T first, T second) public static T Assign<T>(T first, T second)

View File

@ -84,9 +84,17 @@ namespace Kyoo.Controllers
{ {
await base.Create(obj); await base.Create(obj);
_database.Entry(obj).State = EntityState.Added; _database.Entry(obj).State = EntityState.Added;
if (obj.GenreLinks != null) if (obj.GenreLinks != null)
{
foreach (GenreLink entry in obj.GenreLinks) foreach (GenreLink entry in obj.GenreLinks)
{
if (!(entry.Genre is GenreDE))
entry.Genre = new GenreDE(entry.Genre);
_database.Entry(entry).State = EntityState.Added; _database.Entry(entry).State = EntityState.Added;
}
}
if (obj.People != null) if (obj.People != null)
foreach (PeopleRole entry in obj.People) foreach (PeopleRole entry in obj.People)
_database.Entry(entry).State = EntityState.Added; _database.Entry(entry).State = EntityState.Added;

View File

@ -7,21 +7,21 @@ namespace Kyoo.Models
{ {
public class CollectionDE : Collection public class CollectionDE : Collection
{ {
[JsonIgnore] [NotMergable] public virtual IEnumerable<CollectionLink> Links { get; set; } [JsonIgnore] [NotMergable] public virtual ICollection<CollectionLink> Links { get; set; }
[ExpressionRewrite(nameof(Links), nameof(CollectionLink.Show))] [ExpressionRewrite(nameof(Links), nameof(CollectionLink.Show))]
public override IEnumerable<Show> Shows public override IEnumerable<Show> Shows
{ {
get => Links?.Select(x => x.Show); 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<LibraryLink> LibraryLinks { get; set; } [JsonIgnore] [NotMergable] public virtual ICollection<LibraryLink> LibraryLinks { get; set; }
[ExpressionRewrite(nameof(LibraryLinks), nameof(GenreLink.Genre))] [ExpressionRewrite(nameof(LibraryLinks), nameof(GenreLink.Genre))]
public override IEnumerable<Library> Libraries public override IEnumerable<Library> Libraries
{ {
get => LibraryLinks?.Select(x => x.Library); 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() {} public CollectionDE() {}

View File

@ -7,13 +7,13 @@ namespace Kyoo.Models
{ {
public class GenreDE : Genre public class GenreDE : Genre
{ {
[JsonIgnore] [NotMergable] public virtual IEnumerable<GenreLink> Links { get; set; } [JsonIgnore] [NotMergable] public virtual ICollection<GenreLink> Links { get; set; }
[ExpressionRewrite(nameof(Links), nameof(GenreLink.Genre))] [ExpressionRewrite(nameof(Links), nameof(GenreLink.Genre))]
[JsonIgnore] [NotMergable] public override IEnumerable<Show> Shows [JsonIgnore] [NotMergable] public override IEnumerable<Show> Shows
{ {
get => Links?.Select(x => x.Show); 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() {} public GenreDE() {}

View File

@ -7,7 +7,7 @@ namespace Kyoo.Models
{ {
public class LibraryDE : Library public class LibraryDE : Library
{ {
[JsonIgnore] [NotMergable] public virtual IEnumerable<ProviderLink> ProviderLinks { get; set; } [JsonIgnore] [NotMergable] public virtual ICollection<ProviderLink> ProviderLinks { get; set; }
[ExpressionRewrite(nameof(ProviderLinks), nameof(ProviderLink.Provider))] [ExpressionRewrite(nameof(ProviderLinks), nameof(ProviderLink.Provider))]
public override IEnumerable<ProviderID> Providers public override IEnumerable<ProviderID> Providers
{ {
@ -15,14 +15,14 @@ namespace Kyoo.Models
set => ProviderLinks = value?.Select(x => new ProviderLink(x, this)).ToList(); set => ProviderLinks = value?.Select(x => new ProviderLink(x, this)).ToList();
} }
[JsonIgnore] [NotMergable] public virtual IEnumerable<LibraryLink> Links { get; set; } [JsonIgnore] [NotMergable] public virtual ICollection<LibraryLink> Links { get; set; }
[ExpressionRewrite(nameof(Links), nameof(LibraryLink.Show))] [ExpressionRewrite(nameof(Links), nameof(LibraryLink.Show))]
public override IEnumerable<Show> Shows public override IEnumerable<Show> Shows
{ {
get => Links?.Where(x => x.Show != null).Select(x => x.Show); get => Links?.Where(x => x.Show != null).Select(x => x.Show);
set => Links = Utility.MergeLists( set => Links = Utility.MergeLists(
value?.Select(x => new LibraryLink(this, x)), 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))] [ExpressionRewrite(nameof(Links), nameof(LibraryLink.Collection))]
public override IEnumerable<Collection> Collections public override IEnumerable<Collection> Collections
@ -30,7 +30,7 @@ namespace Kyoo.Models
get => Links?.Where(x => x.Collection != null).Select(x => x.Collection); get => Links?.Where(x => x.Collection != null).Select(x => x.Collection);
set => Links = Utility.MergeLists( set => Links = Utility.MergeLists(
value?.Select(x => new LibraryLink(this, x)), value?.Select(x => new LibraryLink(this, x)),
Links?.Where(x => x.Collection == null)); Links?.Where(x => x.Collection == null))?.ToList();
} }
public LibraryDE() {} public LibraryDE() {}

View File

@ -10,28 +10,28 @@ namespace Kyoo.Models
{ {
public class ShowDE : Show public class ShowDE : Show
{ {
[JsonIgnore] [NotMergable] public virtual IEnumerable<GenreLink> GenreLinks { get; set; } [JsonIgnore] [NotMergable] public virtual ICollection<GenreLink> GenreLinks { get; set; }
[ExpressionRewrite(nameof(GenreLinks), nameof(GenreLink.Genre))] [ExpressionRewrite(nameof(GenreLinks), nameof(GenreLink.Genre))]
public override IEnumerable<Genre> Genres public override IEnumerable<Genre> Genres
{ {
get => GenreLinks?.Select(x => x.Genre); 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<LibraryLink> LibraryLinks { get; set; } [JsonIgnore] [NotMergable] public virtual ICollection<LibraryLink> LibraryLinks { get; set; }
[ExpressionRewrite(nameof(LibraryLinks), nameof(LibraryLink.Library))] [ExpressionRewrite(nameof(LibraryLinks), nameof(LibraryLink.Library))]
public override IEnumerable<Library> Libraries public override IEnumerable<Library> Libraries
{ {
get => LibraryLinks?.Select(x => x.Library); 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<CollectionLink> CollectionLinks { get; set; } [JsonIgnore] [NotMergable] public virtual ICollection<CollectionLink> CollectionLinks { get; set; }
[ExpressionRewrite(nameof(CollectionLinks), nameof(CollectionLink.Collection))] [ExpressionRewrite(nameof(CollectionLinks), nameof(CollectionLink.Collection))]
public override IEnumerable<Collection> Collections public override IEnumerable<Collection> Collections
{ {
get => CollectionLinks?.Select(x => x.Collection); 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() {} public ShowDE() {}