private async Task <Either <Error, Unit> > ClearMediaCollectionImpl( int mediaCollectionId, CancellationToken cancellationToken) { var mediaCollectionsApi = new MediaCollectionsApi(_serverUrl); await mediaCollectionsApi.ApiMediaCollectionsIdItemsPutAsync( mediaCollectionId, new List <int>(), cancellationToken); return(unit); }
private async Task <Either <Error, int> > EnsureMediaCollectionExists(CancellationToken cancellationToken) { var mediaCollectionsApi = new MediaCollectionsApi(_serverUrl); Option <MediaCollectionViewModel> maybeExisting = (await mediaCollectionsApi.ApiMediaCollectionsGetAsync(cancellationToken)) .SingleOrDefault(mc => mc.Name == Name); return(await maybeExisting.MatchAsync( existing => existing.Id, async() => { var data = new CreateSimpleMediaCollection(Name); MediaCollectionViewModel result = await mediaCollectionsApi.ApiMediaCollectionsPostAsync(data, cancellationToken); return result.Id; })); }
private async ValueTask AddItemToSchedule( CancellationToken cancellationToken, ProgramScheduleViewModel programSchedule) { var mediaCollectionsApi = new MediaCollectionsApi(_serverUrl); Option <MediaCollectionViewModel> maybeMediaCollection = await mediaCollectionsApi .ApiMediaCollectionsGetAsync(cancellationToken) .Map(list => list.SingleOrDefault(mc => mc.Name == CollectionName)); await maybeMediaCollection.Match( collection => AddScheduleItem(programSchedule.Id, collection.Id, cancellationToken), () => { _logger.LogError( "Unable to locate collection {Collection}", CollectionName); return(Task.CompletedTask); }); }
private async Task <Either <Error, Unit> > EnsureMediaCollectionExists(CancellationToken cancellationToken) { var mediaCollectionsApi = new MediaCollectionsApi(_serverUrl); bool needToAdd = await mediaCollectionsApi .ApiMediaCollectionsGetAsync(cancellationToken) .Map(list => list.All(mc => mc.Name != Name)); if (needToAdd) { var data = new CreateSimpleMediaCollection(Name); await mediaCollectionsApi.ApiMediaCollectionsPostAsync(data, cancellationToken); _logger.LogInformation("Successfully created media collection {MediaCollection}", Name); } else { _logger.LogInformation("Media collection {MediaCollection} is already present", Name); } return(unit); }