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 Customer AddMoviePurchase(MoviePurchase moviePurchase) { var customer = context.Customers.Find(moviePurchase.CustomerId); customer.AddMoviePurchase(moviePurchase); context.Add(moviePurchase); context.SaveChanges(); return(customer); }
public PurchaseResponse(MoviePurchase moviePurchase, string movieStreamWithDownload) { MoviePurchase = moviePurchase; MovieStreamWithDownload = movieStreamWithDownload; }