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
|
namespace Kyoo.Models
|
||||||
{
|
{
|
||||||
public class LibraryLink
|
public class LibraryLink
|
||||||
|
@ -347,10 +347,10 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
if (collection != null)
|
if (collection != null)
|
||||||
{
|
{
|
||||||
_database.LibraryLinks.Add(new LibraryLink {LibraryID = library.ID, CollectionID = collection.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.Add(new CollectionLink { CollectionID = collection.ID, ShowID = show.ID});
|
_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();
|
_database.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,3 +51,12 @@ namespace Kyoo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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