diff --git a/Kyoo.Common/Models/Collection.cs b/Kyoo.Common/Models/Collection.cs index 98881da2..5336c52c 100644 --- a/Kyoo.Common/Models/Collection.cs +++ b/Kyoo.Common/Models/Collection.cs @@ -19,6 +19,14 @@ namespace Kyoo.Models get => Links.Select(x => x.Show); set => Links = value.Select(x => new CollectionLink(this, x)); } + + [NotMergable] [JsonIgnore] public virtual IEnumerable LibraryLinks { get; set; } + + [NotMergable] [JsonIgnore] public IEnumerable Libraries + { + get => LibraryLinks?.Select(x => x.Library); + set => LibraryLinks = value?.Select(x => new LibraryLink(x, this)); + } public Collection() { } diff --git a/Kyoo/Controllers/Repositories/CollectionRepository.cs b/Kyoo/Controllers/Repositories/CollectionRepository.cs index 4b2f4786..5e3fcd43 100644 --- a/Kyoo/Controllers/Repositories/CollectionRepository.cs +++ b/Kyoo/Controllers/Repositories/CollectionRepository.cs @@ -115,7 +115,14 @@ namespace Kyoo.Controllers { if (obj == null) throw new ArgumentNullException(nameof(obj)); - _database.Collections.Remove(obj); + + _database.Entry(obj).State = EntityState.Deleted; + if (obj.Links != null) + foreach (CollectionLink link in obj.Links) + _database.Entry(link).State = EntityState.Deleted; + if (obj.LibraryLinks != null) + foreach (LibraryLink link in obj.LibraryLinks) + _database.Entry(link).State = EntityState.Deleted; await _database.SaveChangesAsync(); } }