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
@ -19,6 +19,14 @@ namespace Kyoo.Models
|
|||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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() { }
|
||||||
|
|
||||||
|
@ -115,7 +115,14 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
throw new ArgumentNullException(nameof(obj));
|
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();
|
await _database.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user