public async Task <Either <BaseError, Unit> > Handle(
        AddEpisodeToCollection request,
        CancellationToken cancellationToken)
    {
        await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);

        Validation <BaseError, Parameters> validation = await Validate(dbContext, request);

        return(await LanguageExtensions.Apply(
                   validation,
                   parameters => ApplyAddTelevisionEpisodeRequest(dbContext, parameters)));
    }
        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 static async Task <Validation <BaseError, Parameters> > Validate(
     TvContext dbContext,
     AddEpisodeToCollection request) =>
 (await CollectionMustExist(dbContext, request), await ValidateEpisode(dbContext, request))
 private async Task <Validation <BaseError, Unit> > Validate(AddEpisodeToCollection request) =>
 (await CollectionMustExist(request), await ValidateEpisode(request))
 public Task <Either <BaseError, Unit> > Handle(
     AddEpisodeToCollection request,
     CancellationToken cancellationToken) =>
 Validate(request)
 .MapT(_ => ApplyAddTelevisionEpisodeRequest(request))
 .Bind(v => v.ToEitherAsync());