예제 #1
0
    public async Task <Either <BaseError, Unit> > Handle(
        AddMovieToCollection 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 => ApplyAddMovieRequest(dbContext, parameters)));
    }
        private async Task <Unit> ApplyAddMoviesRequest(AddMovieToCollection request)
        {
            if (await _mediaCollectionRepository.AddMediaItem(request.CollectionId, request.MovieId))
            {
                // 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);
        }
예제 #3
0
 private static async Task <Validation <BaseError, Parameters> > Validate(
     TvContext dbContext,
     AddMovieToCollection request) =>
 (await CollectionMustExist(dbContext, request), await ValidateMovie(dbContext, request))
 private async Task <Validation <BaseError, Unit> > Validate(AddMovieToCollection request) =>
 (await CollectionMustExist(request), await ValidateMovies(request))
 public Task <Either <BaseError, Unit> > Handle(
     AddMovieToCollection request,
     CancellationToken cancellationToken) =>
 Validate(request)
 .MapT(_ => ApplyAddMoviesRequest(request))
 .Bind(v => v.ToEitherAsync());