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)); }
public string WatchMovie(Customer customer, Movie movie) { var currentlyRentedMovie = customer.MovieRentals .FirstOrDefault(mr => mr.MovieId == movie.Id && mr.EndDate > DateTime.Now); var purchasedMovie = customer.MoviePurchases.FirstOrDefault(m => m.MovieId == movie.Id); if (currentlyRentedMovie == null && purchasedMovie == null) { throw new MovieNotAcquiredException("Movie is not acquired. Please rent or purchase movie and try again."); } if (currentlyRentedMovie != null) { return(streamingService.GetMovieStream(currentlyRentedMovie.Movie)); } if (purchasedMovie != null) { return(streamingService.GetMovieStreamWithDownload(purchasedMovie.Movie)); } return(string.Empty); }