mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Handling related data in the collection delete
This commit is contained in:
parent
15d8173433
commit
2aa87378fc
@ -20,6 +20,14 @@ namespace Kyoo.Models
|
||||
set => Links = value.Select(x => new CollectionLink(this, x));
|
||||
}
|
||||
|
||||
[NotMergable] [JsonIgnore] public virtual IEnumerable<LibraryLink> LibraryLinks { get; set; }
|
||||
|
||||
[NotMergable] [JsonIgnore] public IEnumerable<Library> Libraries
|
||||
{
|
||||
get => LibraryLinks?.Select(x => x.Library);
|
||||
set => LibraryLinks = value?.Select(x => new LibraryLink(x, this));
|
||||
}
|
||||
|
||||
public Collection() { }
|
||||
|
||||
public Collection(string slug, string name, string overview, string imgPrimary)
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user