mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Solving a bug with libraries links
This commit is contained in:
parent
d307308fb4
commit
b9b00192bc
@ -1,3 +1,6 @@
|
||||
using System;
|
||||
|
||||
#nullable enable
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
public class LibraryLink
|
||||
|
@ -345,12 +345,12 @@ namespace Kyoo.Controllers
|
||||
|
||||
public void RegisterShowLinks(Library library, Collection collection, Show show)
|
||||
{
|
||||
if (collection != null)
|
||||
if (collection != null)
|
||||
{
|
||||
_database.LibraryLinks.Add(new LibraryLink {LibraryID = library.ID, CollectionID = collection.ID});
|
||||
_database.CollectionLinks.Add(new CollectionLink { CollectionID = collection.ID, ShowID = show.ID});
|
||||
_database.LibraryLinks.AddIfNotExist(new LibraryLink {LibraryID = library.ID, CollectionID = collection.ID}, x => x.LibraryID == library.ID && x.CollectionID == collection.ID && x.ShowID == null);
|
||||
_database.CollectionLinks.AddIfNotExist(new CollectionLink { CollectionID = collection.ID, ShowID = show.ID}, x => x.CollectionID == collection.ID && x.ShowID == show.ID);
|
||||
}
|
||||
_database.LibraryLinks.Add(new LibraryLink {LibraryID = library.ID, ShowID = show.ID});
|
||||
_database.LibraryLinks.AddIfNotExist(new LibraryLink {LibraryID = library.ID, ShowID = show.ID}, x => x.LibraryID == library.ID && x.CollectionID == null && x.ShowID == show.ID);
|
||||
_database.SaveChanges();
|
||||
}
|
||||
|
||||
|
@ -50,4 +50,13 @@ namespace Kyoo
|
||||
.ValueGeneratedNever();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DbSetExtension
|
||||
{
|
||||
public static EntityEntry<T> AddIfNotExist<T>(this DbSet<T> db, T entity, Func<T, bool> predicate) where T : class
|
||||
{
|
||||
bool exists = db.Any(predicate);
|
||||
return exists ? null : db.Add(entity);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user