private async Task <Unit> ApplyAddItemsRequest( TvContext dbContext, Collection collection, AddItemsToCollection request) { var allItems = request.MovieIds .Append(request.ShowIds) .Append(request.SeasonIds) .Append(request.EpisodeIds) .Append(request.ArtistIds) .Append(request.MusicVideoIds) .Append(request.OtherVideoIds) .Append(request.SongIds) .ToList(); var toAddIds = allItems.Where(item => collection.MediaItems.All(mi => mi.Id != item)).ToList(); List <MediaItem> toAdd = await dbContext.MediaItems .Filter(mi => toAddIds.Contains(mi.Id)) .ToListAsync(); collection.MediaItems.AddRange(toAdd); if (await dbContext.SaveChangesAsync() > 0) { // refresh all playouts that use this collection foreach (int playoutId in await _mediaCollectionRepository .PlayoutIdsUsingCollection(request.CollectionId)) { await _channel.WriteAsync(new BuildPlayout(playoutId, PlayoutBuildMode.Refresh)); } } return(Unit.Default); }
private async Task <Unit> ApplyUpdateRequest( TvContext dbContext, Collection c, UpdateCollectionCustomOrder request) { foreach (MediaItemCustomOrder updateItem in request.MediaItemCustomOrders) { Option <CollectionItem> maybeCollectionItem = c.CollectionItems .FirstOrDefault(ci => ci.MediaItemId == updateItem.MediaItemId); foreach (CollectionItem collectionItem in maybeCollectionItem) { collectionItem.CustomIndex = updateItem.CustomIndex; } } if (await dbContext.SaveChangesAsync() > 0) { // refresh all playouts that use this collection foreach (int playoutId in await _mediaCollectionRepository .PlayoutIdsUsingCollection(request.CollectionId)) { await _channel.WriteAsync(new BuildPlayout(playoutId, PlayoutBuildMode.Refresh)); } } return(Unit.Default); }
private async Task <Unit> ApplyAddTelevisionEpisodeRequest(AddEpisodeToCollection request) { if (await _mediaCollectionRepository.AddMediaItem(request.CollectionId, request.EpisodeId)) { // rebuild all playouts that use this collection foreach (int playoutId in await _mediaCollectionRepository .PlayoutIdsUsingCollection(request.CollectionId)) { await _channel.WriteAsync(new BuildPlayout(playoutId, true)); } } return(Unit.Default); }
private async Task <Unit> ApplyAddTelevisionEpisodeRequest(TvContext dbContext, Parameters parameters) { parameters.Collection.MediaItems.Add(parameters.Episode); if (await dbContext.SaveChangesAsync() > 0) { // refresh all playouts that use this collection foreach (int playoutId in await _mediaCollectionRepository .PlayoutIdsUsingCollection(parameters.Collection.Id)) { await _channel.WriteAsync(new BuildPlayout(playoutId, PlayoutBuildMode.Refresh)); } } return(Unit.Default); }
private async Task <Unit> ApplyAddItemsRequest(AddItemsToCollection request) { if (await _mediaCollectionRepository.AddMediaItems( request.CollectionId, request.MovieIds.Append(request.ShowIds).ToList())) { // rebuild all playouts that use this collection foreach (int playoutId in await _mediaCollectionRepository .PlayoutIdsUsingCollection(request.CollectionId)) { await _channel.WriteAsync(new BuildPlayout(playoutId, true)); } } return(Unit.Default); }
private async Task <Unit> ApplyAddTelevisionShowRequest(AddShowToCollection request) { var result = new Unit(); if (await _mediaCollectionRepository.AddMediaItem(request.CollectionId, request.ShowId)) { // rebuild all playouts that use this collection foreach (int playoutId in await _mediaCollectionRepository .PlayoutIdsUsingCollection(request.CollectionId)) { await _channel.WriteAsync(new BuildPlayout(playoutId, true)); } } return(result); }
private async Task <Unit> ApplyUpdateRequest(Collection c, UpdateCollection request) { c.Name = request.Name; request.UseCustomPlaybackOrder.IfSome( useCustomPlaybackOrder => c.UseCustomPlaybackOrder = useCustomPlaybackOrder); if (await _mediaCollectionRepository.Update(c) && request.UseCustomPlaybackOrder.IsSome) { // rebuild all playouts that use this collection foreach (int playoutId in await _mediaCollectionRepository.PlayoutIdsUsingCollection( request.CollectionId)) { await _channel.WriteAsync(new BuildPlayout(playoutId, true)); } } return(Unit.Default); }
private async Task <Unit> ApplyUpdateRequest(TvContext dbContext, Collection c, UpdateCollection request) { c.Name = request.Name; foreach (bool useCustomPlaybackOrder in request.UseCustomPlaybackOrder) { c.UseCustomPlaybackOrder = useCustomPlaybackOrder; } if (await dbContext.SaveChangesAsync() > 0 && request.UseCustomPlaybackOrder.IsSome) { // refresh all playouts that use this collection foreach (int playoutId in await _mediaCollectionRepository.PlayoutIdsUsingCollection( request.CollectionId)) { await _channel.WriteAsync(new BuildPlayout(playoutId, PlayoutBuildMode.Refresh)); } } return(Unit.Default); }
private async Task <Unit> ApplyRemoveItemsRequest( RemoveItemsFromCollection request, Collection collection) { var itemsToRemove = collection.MediaItems .Filter(m => request.MediaItemIds.Contains(m.Id)) .ToList(); itemsToRemove.ForEach(m => collection.MediaItems.Remove(m)); if (itemsToRemove.Any() && await _mediaCollectionRepository.Update(collection)) { // rebuild all playouts that use this collection foreach (int playoutId in await _mediaCollectionRepository.PlayoutIdsUsingCollection(collection.Id)) { await _channel.WriteAsync(new BuildPlayout(playoutId, true)); } } return(Unit.Default); }
private async Task <Unit> ApplyUpdateRequest(Collection c, UpdateCollectionCustomOrder request) { foreach (MediaItemCustomOrder updateItem in request.MediaItemCustomOrders) { Option <CollectionItem> maybeCollectionItem = c.CollectionItems.FirstOrDefault(ci => ci.MediaItemId == updateItem.MediaItemId); maybeCollectionItem.IfSome(ci => ci.CustomIndex = updateItem.CustomIndex); } if (await _mediaCollectionRepository.Update(c)) { // rebuild all playouts that use this collection foreach (int playoutId in await _mediaCollectionRepository.PlayoutIdsUsingCollection( request.CollectionId)) { await _channel.WriteAsync(new BuildPlayout(playoutId, true)); } } return(Unit.Default); }