Solving a bug with collections

This commit is contained in:
Zoe Roux 2020-03-02 21:44:17 +01:00
parent 7e20e7d318
commit b79ed8a198
4 changed files with 14 additions and 15 deletions

View File

@ -60,7 +60,7 @@ namespace Kyoo.Models
{ {
Slug = slug; Slug = slug;
Title = title; Title = title;
Aliases = aliases.ToArray(); Aliases = aliases?.ToArray();
Path = path; Path = path;
Overview = overview; Overview = overview;
TrailerUrl = trailerUrl; TrailerUrl = trailerUrl;
@ -76,7 +76,7 @@ namespace Kyoo.Models
{ {
Slug = slug; Slug = slug;
Title = title; Title = title;
Aliases = aliases.ToArray(); Aliases = aliases?.ToArray();
Path = path; Path = path;
Overview = overview; Overview = overview;
TrailerUrl = trailerUrl; TrailerUrl = trailerUrl;

View File

@ -93,6 +93,8 @@ namespace Kyoo.Controllers
if (_libraryManager.RegisterEpisode(episode) == 0) if (_libraryManager.RegisterEpisode(episode) == 0)
return; return;
} }
if (collection != null)
_libraryManager.RegisterCollection(collection);
_libraryManager.RegisterShowLinks(library, collection, show); _libraryManager.RegisterShowLinks(library, collection, show);
} }

View File

@ -62,9 +62,7 @@ namespace Kyoo.Controllers
public IEnumerable<Show> GetShows() public IEnumerable<Show> GetShows()
{ {
return (from show in _database.Shows from l in _database.CollectionLinks.DefaultIfEmpty() return _database.LibraryLinks.AsEnumerable().Select(x => x.Show ?? x.Collection.AsShow());
where l.CollectionID == null select show).AsEnumerable().Union(
from collection in _database.Collections select collection.AsShow()).OrderBy(x => x.Title);
} }
public IEnumerable<Show> GetShows(string searchQuery) public IEnumerable<Show> GetShows(string searchQuery)
@ -220,7 +218,10 @@ namespace Kyoo.Controllers
public Collection GetCollection(string slug) public Collection GetCollection(string slug)
{ {
return (from collection in _database.Collections where collection.Slug == slug select collection).FirstOrDefault(); Collection collection = _database.Collections.Where(collection => collection.Slug == slug).FirstOrDefault();
if (collection != null)
collection.Shows = GetShowsInCollection(collection.ID);
return collection;
} }
public IEnumerable<Show> GetShowsInCollection(long collectionID) public IEnumerable<Show> GetShowsInCollection(long collectionID)
@ -232,12 +233,7 @@ namespace Kyoo.Controllers
{ {
return (from link in _database.LibraryLinks where link.LibraryID == libraryID select link) return (from link in _database.LibraryLinks where link.LibraryID == libraryID select link)
.AsEnumerable() .AsEnumerable()
.Select(link => .Select(link => link.Show ?? link.Collection.AsShow())
{
_database.Entry(link).Reference(l => l.Show).Load();
_database.Entry(link).Reference(l => l.Collection).Load();
return link.Show ?? link.Collection.AsShow();
})
.OrderBy(x => x.Title); .OrderBy(x => x.Title);
} }
@ -395,7 +391,8 @@ namespace Kyoo.Controllers
_database.LibraryLinks.AddIfNotExist(new LibraryLink {LibraryID = library.ID, CollectionID = collection.ID}, x => x.LibraryID == library.ID && x.CollectionID == collection.ID && x.ShowID == null); _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.CollectionLinks.AddIfNotExist(new CollectionLink { CollectionID = collection.ID, ShowID = show.ID}, x => x.CollectionID == collection.ID && x.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); else
_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();
} }

View File

@ -28,7 +28,7 @@ namespace Kyoo.Controllers
if (library.Providers.Contains(provider.Name)) if (library.Providers.Contains(provider.Name))
ret = ret.Merge(await providerCall(provider)); ret = ret.Merge(await providerCall(provider));
} catch (Exception ex) { } catch (Exception ex) {
Console.Error.WriteLine($"The provider {provider.Name} coudln't work for {what}. Exception: {ex.Message}"); Console.Error.WriteLine($"\tThe provider {provider.Name} coudln't work for {what}. Exception: {ex.Message}");
} }
} }
return ret; return ret;
@ -45,7 +45,7 @@ namespace Kyoo.Controllers
if (library.Providers.Contains(provider.Name)) if (library.Providers.Contains(provider.Name))
ret.AddRange(await providerCall(provider) ?? new List<T>()); ret.AddRange(await providerCall(provider) ?? new List<T>());
} catch (Exception ex) { } catch (Exception ex) {
Console.Error.WriteLine($"The provider {provider.Name} coudln't work for {what}. Exception: {ex.Message}"); Console.Error.WriteLine($"\tThe provider {provider.Name} coudln't work for {what}. Exception: {ex.Message}");
} }
} }
return ret; return ret;