mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Fixing show's repository
This commit is contained in:
parent
93d271b192
commit
4b56ec4114
@ -28,6 +28,13 @@ namespace Kyoo.Models
|
||||
return new(first, second);
|
||||
}
|
||||
|
||||
public static Link<T, T2> UCreate<T, T2>(T first, T2 second)
|
||||
where T : class, IResource
|
||||
where T2 : class, IResource
|
||||
{
|
||||
return new(first, second, true);
|
||||
}
|
||||
|
||||
public static Expression<Func<Link, object>> PrimaryKey
|
||||
{
|
||||
get
|
||||
@ -47,13 +54,15 @@ namespace Kyoo.Models
|
||||
|
||||
public Link() {}
|
||||
|
||||
public Link(T1 first, T2 second)
|
||||
public Link(T1 first, T2 second, bool privateItems = false)
|
||||
: base(first, second)
|
||||
{
|
||||
if (privateItems)
|
||||
return;
|
||||
First = first;
|
||||
Second = second;
|
||||
}
|
||||
|
||||
|
||||
public new static Expression<Func<Link<T1, T2>, object>> PrimaryKey
|
||||
{
|
||||
get
|
||||
|
@ -167,9 +167,8 @@ namespace Kyoo.Controllers
|
||||
|
||||
if (resetOld)
|
||||
Utility.Nullify(old);
|
||||
await EditRelations(old, edited, resetOld);
|
||||
Utility.Complete(old, edited, x => x.GetCustomAttribute<LoadableRelationAttribute>() == null);
|
||||
await Validate(old);
|
||||
await EditRelations(old, edited, resetOld);
|
||||
await Database.SaveChangesAsync();
|
||||
return old;
|
||||
}
|
||||
|
@ -100,32 +100,45 @@ namespace Kyoo.Controllers
|
||||
{
|
||||
await base.Validate(resource);
|
||||
resource.Studio = await _studios.CreateIfNotExists(resource.Studio, true);
|
||||
resource.Genres = await resource.Genres
|
||||
.SelectAsync(x => _genres.CreateIfNotExists(x, true))
|
||||
resource.GenreLinks = await resource.Genres
|
||||
.SelectAsync(async x => Link.UCreate(resource, await _genres.CreateIfNotExists(x, true)))
|
||||
.ToListAsync();
|
||||
await resource.ExternalIDs.ForEachAsync(async id =>
|
||||
id.Provider = await _providers.CreateIfNotExists(id.Provider, true));
|
||||
await resource.ExternalIDs.ForEachAsync(async id =>
|
||||
{
|
||||
id.ProviderID = (await _providers.CreateIfNotExists(id.Provider, true)).ID;
|
||||
id.Provider = null;
|
||||
});
|
||||
await resource.People.ForEachAsync(async role =>
|
||||
role.People = await _people.CreateIfNotExists(role.People, true));
|
||||
{
|
||||
role.PeopleID = (await _people.CreateIfNotExists(role.People, true)).ID;
|
||||
role.People = null;
|
||||
});
|
||||
}
|
||||
|
||||
protected override async Task EditRelations(Show resource, Show changed, bool resetOld)
|
||||
{
|
||||
await Validate(changed);
|
||||
|
||||
if (changed.Aliases != null || resetOld)
|
||||
resource.Aliases = changed.Aliases;
|
||||
|
||||
|
||||
if (changed.Genres != null || resetOld)
|
||||
await Database.Entry(resource).Collection(x => x.Genres).LoadAsync();
|
||||
resource.Genres = changed.Genres;
|
||||
|
||||
{
|
||||
await Database.Entry(resource).Collection(x => x.GenreLinks).LoadAsync();
|
||||
resource.GenreLinks = changed.GenreLinks;
|
||||
}
|
||||
|
||||
if (changed.People != null || resetOld)
|
||||
{
|
||||
await Database.Entry(resource).Collection(x => x.People).LoadAsync();
|
||||
resource.People = changed.People;
|
||||
|
||||
resource.People = changed.People;
|
||||
}
|
||||
|
||||
if (changed.ExternalIDs != null || resetOld)
|
||||
{
|
||||
await Database.Entry(resource).Collection(x => x.ExternalIDs).LoadAsync();
|
||||
resource.ExternalIDs = changed.ExternalIDs;
|
||||
await base.EditRelations(resource, changed, resetOld);
|
||||
resource.ExternalIDs = changed.ExternalIDs;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task AddShowLink(int showID, int? libraryID, int? collectionID)
|
||||
|
Loading…
x
Reference in New Issue
Block a user