Exemplo n.º 1
0
        public PurchaseResponseDto PurchaseMovie(Guid customerId, Guid movieId)
        {
            var customer = customersRepository.FindByIdWithPurchasesAndRentals(customerId);

            if (customer == null)
            {
                throw new HttpException("Customer not found.", HttpStatusCode.NotFound);
            }

            var movie = moviesRepository.FindById(movieId);

            if (movie == null)
            {
                throw new HttpException("Movie not found.", HttpStatusCode.NotFound);
            }

            try
            {
                var purchaseResponse = movieAcquisitionService.PurchaseMovie(customer, movie);

                return(mapper.Map <PurchaseResponseDto>(purchaseResponse));
            }
            catch (Exception ex)
            {
                throw new HttpException("Movie purchase failed.", ex);
            }
        }