public RentResponse RentMovie(Customer customer, Movie movie) { if (customer.MovieRentals.FirstOrDefault(r => r.MovieId == movie.Id && r.EndDate > DateTime.Now) != null) { throw new MovieAlreadyRentedException("Movie already rented."); } if (customer.MoviePurchases.Select(r => r.MovieId).Contains(movie.Id)) { throw new MovieAlreadyPurchasedException("Movie already purchased."); } if (!paymentService.Rent(customer)) { InvalidateCustomerCreditCard(customer); throw new PaymentFailedException( $"Payment failed for customer {customer.FullName.ToString()}. " + "Please check and update your credit card details." ); } var movieRental = MovieRental.Create(customer, movie, DateTime.Now.AddDays(RentalDays)); customersRepository.AddMovieRental(movieRental); var movieStream = streamingService.GetMovieStream(movie); return(new RentResponse(movieRental, movieStream)); }