public PurchaseResponse PurchaseMovie(Customer customer, Movie movie) { if (customer.MoviePurchases.Select(r => r.MovieId).Contains(movie.Id)) { throw new MovieAlreadyPurchasedException("Movie already purchased."); } if (!paymentService.Pay(customer, movie)) { InvalidateCustomerCreditCard(customer); throw new PaymentFailedException( $"Payment failed for customer {customer.FullName.ToString()}. " + "Please check and update your credit card details." ); } var moviePurchase = MoviePurchase.Create(customer, movie); customersRepository.AddMoviePurchase(moviePurchase); FinishCurrentRentalIfExists(customer, movie); var movieLinkWithDownload = streamingService.GetMovieStreamWithDownload(movie); return(new PurchaseResponse(moviePurchase, movieLinkWithDownload)); }
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); }