|
|
|
@ -47,36 +47,36 @@ public class EmbyCollectionRepository : IEmbyCollectionRepository |
|
|
|
// movies
|
|
|
|
// movies
|
|
|
|
result.AddRange( |
|
|
|
result.AddRange( |
|
|
|
await dbContext.Connection.QueryAsync<int>( |
|
|
|
await dbContext.Connection.QueryAsync<int>( |
|
|
|
@"SELECT JM.Id FROM Tag T
|
|
|
|
@"SELECT EM.Id FROM Tag T
|
|
|
|
INNER JOIN MovieMetadata MM on T.MovieMetadataId = MM.Id |
|
|
|
INNER JOIN MovieMetadata MM on T.MovieMetadataId = MM.Id |
|
|
|
INNER JOIN EmbyMovie JM on JM.Id = MM.MovieId |
|
|
|
INNER JOIN EmbyMovie EM on EM.Id = MM.MovieId |
|
|
|
WHERE T.ExternalCollectionId = @ItemId",
|
|
|
|
WHERE T.ExternalCollectionId = @ItemId",
|
|
|
|
new { collection.ItemId })); |
|
|
|
new { collection.ItemId })); |
|
|
|
|
|
|
|
|
|
|
|
// shows
|
|
|
|
// shows
|
|
|
|
result.AddRange( |
|
|
|
result.AddRange( |
|
|
|
await dbContext.Connection.QueryAsync<int>( |
|
|
|
await dbContext.Connection.QueryAsync<int>( |
|
|
|
@"SELECT JS.Id FROM Tag T
|
|
|
|
@"SELECT ES.Id FROM Tag T
|
|
|
|
INNER JOIN ShowMetadata SM on T.ShowMetadataId = SM.Id |
|
|
|
INNER JOIN ShowMetadata SM on T.ShowMetadataId = SM.Id |
|
|
|
INNER JOIN EmbyShow JS on JS.Id = SM.ShowId |
|
|
|
INNER JOIN EmbyShow ES on ES.Id = SM.ShowId |
|
|
|
WHERE T.ExternalCollectionId = @ItemId",
|
|
|
|
WHERE T.ExternalCollectionId = @ItemId",
|
|
|
|
new { collection.ItemId })); |
|
|
|
new { collection.ItemId })); |
|
|
|
|
|
|
|
|
|
|
|
// seasons
|
|
|
|
// seasons
|
|
|
|
result.AddRange( |
|
|
|
result.AddRange( |
|
|
|
await dbContext.Connection.QueryAsync<int>( |
|
|
|
await dbContext.Connection.QueryAsync<int>( |
|
|
|
@"SELECT JS.Id FROM Tag T
|
|
|
|
@"SELECT ES.Id FROM Tag T
|
|
|
|
INNER JOIN SeasonMetadata SM on T.SeasonMetadataId = SM.Id |
|
|
|
INNER JOIN SeasonMetadata SM on T.SeasonMetadataId = SM.Id |
|
|
|
INNER JOIN EmbySeason JS on JS.Id = SM.SeasonId |
|
|
|
INNER JOIN EmbySeason ES on ES.Id = SM.SeasonId |
|
|
|
WHERE T.ExternalCollectionId = @ItemId",
|
|
|
|
WHERE T.ExternalCollectionId = @ItemId",
|
|
|
|
new { collection.ItemId })); |
|
|
|
new { collection.ItemId })); |
|
|
|
|
|
|
|
|
|
|
|
// episodes
|
|
|
|
// episodes
|
|
|
|
result.AddRange( |
|
|
|
result.AddRange( |
|
|
|
await dbContext.Connection.QueryAsync<int>( |
|
|
|
await dbContext.Connection.QueryAsync<int>( |
|
|
|
@"SELECT JE.Id FROM Tag T
|
|
|
|
@"SELECT EE.Id FROM Tag T
|
|
|
|
INNER JOIN EpisodeMetadata EM on T.EpisodeMetadataId = EM.Id |
|
|
|
INNER JOIN EpisodeMetadata EM on T.EpisodeMetadataId = EM.Id |
|
|
|
INNER JOIN EmbyEpisode JE on JE.Id = EM.EpisodeId |
|
|
|
INNER JOIN EmbyEpisode EE on EE.Id = EM.EpisodeId |
|
|
|
WHERE T.ExternalCollectionId = @ItemId",
|
|
|
|
WHERE T.ExternalCollectionId = @ItemId",
|
|
|
|
new { collection.ItemId })); |
|
|
|
new { collection.ItemId })); |
|
|
|
|
|
|
|
|
|
|
|
@ -88,7 +88,7 @@ public class EmbyCollectionRepository : IEmbyCollectionRepository |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<int> AddTag(MediaItem item, EmbyCollection collection) |
|
|
|
public async Task<Option<int>> AddTag(MediaItem item, EmbyCollection collection) |
|
|
|
{ |
|
|
|
{ |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
switch (item) |
|
|
|
switch (item) |
|
|
|
@ -97,6 +97,11 @@ public class EmbyCollectionRepository : IEmbyCollectionRepository |
|
|
|
int movieId = await dbContext.Connection.ExecuteScalarAsync<int>( |
|
|
|
int movieId = await dbContext.Connection.ExecuteScalarAsync<int>( |
|
|
|
@"SELECT Id FROM EmbyMovie WHERE ItemId = @ItemId", |
|
|
|
@"SELECT Id FROM EmbyMovie WHERE ItemId = @ItemId", |
|
|
|
new { movie.ItemId }); |
|
|
|
new { movie.ItemId }); |
|
|
|
|
|
|
|
if (movieId <= 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Option<int>.None; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await dbContext.Connection.ExecuteAsync( |
|
|
|
await dbContext.Connection.ExecuteAsync( |
|
|
|
@"INSERT INTO Tag (Name, ExternalCollectionId, MovieMetadataId)
|
|
|
|
@"INSERT INTO Tag (Name, ExternalCollectionId, MovieMetadataId)
|
|
|
|
SELECT @Name, @ItemId, Id FROM |
|
|
|
SELECT @Name, @ItemId, Id FROM |
|
|
|
@ -107,6 +112,11 @@ public class EmbyCollectionRepository : IEmbyCollectionRepository |
|
|
|
int showId = await dbContext.Connection.ExecuteScalarAsync<int>( |
|
|
|
int showId = await dbContext.Connection.ExecuteScalarAsync<int>( |
|
|
|
@"SELECT Id FROM EmbyShow WHERE ItemId = @ItemId", |
|
|
|
@"SELECT Id FROM EmbyShow WHERE ItemId = @ItemId", |
|
|
|
new { show.ItemId }); |
|
|
|
new { show.ItemId }); |
|
|
|
|
|
|
|
if (showId <= 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Option<int>.None; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await dbContext.Connection.ExecuteAsync( |
|
|
|
await dbContext.Connection.ExecuteAsync( |
|
|
|
@"INSERT INTO Tag (Name, ExternalCollectionId, ShowMetadataId)
|
|
|
|
@"INSERT INTO Tag (Name, ExternalCollectionId, ShowMetadataId)
|
|
|
|
SELECT @Name, @ItemId, Id FROM |
|
|
|
SELECT @Name, @ItemId, Id FROM |
|
|
|
@ -117,6 +127,11 @@ public class EmbyCollectionRepository : IEmbyCollectionRepository |
|
|
|
int seasonId = await dbContext.Connection.ExecuteScalarAsync<int>( |
|
|
|
int seasonId = await dbContext.Connection.ExecuteScalarAsync<int>( |
|
|
|
@"SELECT Id FROM EmbySeason WHERE ItemId = @ItemId", |
|
|
|
@"SELECT Id FROM EmbySeason WHERE ItemId = @ItemId", |
|
|
|
new { season.ItemId }); |
|
|
|
new { season.ItemId }); |
|
|
|
|
|
|
|
if (seasonId <= 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Option<int>.None; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await dbContext.Connection.ExecuteAsync( |
|
|
|
await dbContext.Connection.ExecuteAsync( |
|
|
|
@"INSERT INTO Tag (Name, ExternalCollectionId, SeasonMetadataId)
|
|
|
|
@"INSERT INTO Tag (Name, ExternalCollectionId, SeasonMetadataId)
|
|
|
|
SELECT @Name, @ItemId, Id FROM |
|
|
|
SELECT @Name, @ItemId, Id FROM |
|
|
|
@ -127,6 +142,11 @@ public class EmbyCollectionRepository : IEmbyCollectionRepository |
|
|
|
int episodeId = await dbContext.Connection.ExecuteScalarAsync<int>( |
|
|
|
int episodeId = await dbContext.Connection.ExecuteScalarAsync<int>( |
|
|
|
@"SELECT Id FROM EmbyEpisode WHERE ItemId = @ItemId", |
|
|
|
@"SELECT Id FROM EmbyEpisode WHERE ItemId = @ItemId", |
|
|
|
new { episode.ItemId }); |
|
|
|
new { episode.ItemId }); |
|
|
|
|
|
|
|
if (episodeId <= 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Option<int>.None; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await dbContext.Connection.ExecuteAsync( |
|
|
|
await dbContext.Connection.ExecuteAsync( |
|
|
|
@"INSERT INTO Tag (Name, ExternalCollectionId, EpisodeMetadataId)
|
|
|
|
@"INSERT INTO Tag (Name, ExternalCollectionId, EpisodeMetadataId)
|
|
|
|
SELECT @Name, @ItemId, Id FROM |
|
|
|
SELECT @Name, @ItemId, Id FROM |
|
|
|
@ -134,7 +154,7 @@ public class EmbyCollectionRepository : IEmbyCollectionRepository |
|
|
|
new { collection.Name, collection.ItemId, EpisodeId = episodeId }); |
|
|
|
new { collection.Name, collection.ItemId, EpisodeId = episodeId }); |
|
|
|
return episodeId; |
|
|
|
return episodeId; |
|
|
|
default: |
|
|
|
default: |
|
|
|
return 0; |
|
|
|
return Option<int>.None; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|