Esempio n. 1
0
        public Result <MovieCatalogDto> GetCatalog(string customerId)
        {
            var customer = _customersGetter.Get(customerId);

            if (customer.HasNoValue)
            {
                return(Result.Fail <MovieCatalogDto>(Errors.CustomerNotFound));
            }

            var movies = _moviesGetter.GetAll();

            var movieCatalog = new MovieCatalog(movies, new MoviePriceCalculatorFactory());
            var movieOffers  = movieCatalog.GetMovies(customer.Value);

            return(Result.Ok(MovieCatalogDtoMapper.MapToDto(movieOffers)));
        }
        public void BuyMovie(BuyMovieDto buyMovieRequest, IEnumerable <IHandleMoviePurchased> moviePurchasedHandlers)
        {
            var customer = _customerGetter.Get(buyMovieRequest.CustomerId).ToResult(Errors.CustomerNotFound);
            var movie    = _movieGetter.Get(buyMovieRequest.MovieId).ToResult(Errors.MovieNotFound);

            Result.Combine(customer, movie)
            .OnSuccess(() =>
            {
                var moviePriceCalculator = _moviePriceCalculatorFactory.GetPriceCalculatorFor(customer.Value);

                var offer     = MovieOffer.Create(movie.Value, moviePriceCalculator);
                var buyMethod = GetBuyMethod(buyMovieRequest.MovieLicenseType, customer.Value);

                buyMethod(offer);

                HandleMoviePurchased(moviePurchasedHandlers, Result.Ok <MovieOffer>(offer));
            })
            .OnFailure(message => HandleMoviePurchased(moviePurchasedHandlers, Result.Fail <MovieOffer>(message)));
        }