コード例 #1
0
ファイル: Movie.cs プロジェクト: vkhorikov/DddWorkshop
        public ExpirationDate GetExpirationDate()
        {
            ExpirationDate result = LicensingModel switch
            {
                LicensingModel.TwoDays => ExpirationDate.Create(DateTime.UtcNow.AddDays(2)).Value,
                LicensingModel.LifeLong => ExpirationDate.Infinite,
                _ => throw new ArgumentOutOfRangeException()
            };

            return(result);
        }
コード例 #2
0
        public void PurchaseMovie(Movie movie, DateTime now)
        {
            if (HasPurchasedMovie(movie, now))
            {
                throw new Exception();
            }

            ExpirationDate expirationDate = movie.GetExpirationDate();
            Dollars        price          = movie.CalculatePrice(Status, DateTime.UtcNow);

            var purchasedMovie = new PurchasedMovie(movie.Id, Id, price, now, expirationDate);

            _purchasedMovies.Add(purchasedMovie);

            MoneySpent += price;
        }
コード例 #3
0
        public PurchasedMovie(long movieId, long customerId, Dollars price, DateTime now, ExpirationDate expirationDate)
        {
            if (price == null || price.IsZero)
            {
                throw new ArgumentException(nameof(price));
            }
            if (expirationDate == null || expirationDate.IsExpired(now))
            {
                throw new ArgumentException(nameof(expirationDate));
            }

            MovieId        = movieId;
            CustomerId     = customerId;
            Price          = price;
            PurchaseDate   = now;
            ExpirationDate = expirationDate;
        }
コード例 #4
0
 private CustomerStatus(CustomerStatusType type, ExpirationDate expirationDate)
     : this()
 {
     Type           = type;
     ExpirationDate = expirationDate;
 }