示例#1
0
        public ReleaseState AddSubscription(string subscriptionId, SubscriptionCreateCommand command)
        {
            var state = new ReleaseState(this);

            state.Subscription = new SubscriptionState(subscriptionId, command);
            return(state);
        }
示例#2
0
 public static ValidationResult Validate(SubscriptionCreateCommand command)
 {
     if (command != null && !string.IsNullOrEmpty(command.ReleaseId) && command.UtcExpiration > DateTime.UtcNow)
     {
         return(ValidationResult.Ok);
     }
     return(ValidationResult.ErrorOf("Command has to have release id specified and have expiration date greater than UTC Now"));
 }
示例#3
0
 public SubscriptionState(string subscriptionId, SubscriptionCreateCommand command)
 {
     SubscriptionId = subscriptionId;
     UtcExpiration  = command.UtcExpiration;
     ReleaseId      = command.ReleaseId;
     ShopIds        = command.ShopIds;
     Cost           = command.Cost;
     Timestamp      = command.Timestamp;
 }
示例#4
0
        public void FinishPayment(string paymentId)
        {
            //this is emulation too. Payment Id should be used to get subscription id
            //and only after that we can get subscription instance
            Subscription sub;

            AwaitingSubscriptions.TryGetValue(paymentId, out sub);
            var cost = _priceService.CalculatePrice(sub);
            var subscriptionCommand = new SubscriptionCreateCommand(sub.ReleaseId, sub.UtcExpirationDate, cost, sub.ShopIds, sub.OwnerId);

            ActorModel.TellReleaseActor(subscriptionCommand.ReleaseId, subscriptionCommand);
        }
示例#5
0
        private bool OnSubscriptionCreate(SubscriptionCreateCommand command)
        {
            if (!IsSubscriptionValid(command) || _state.Subscription != null)
            {
                return(false);
            }

            PersistAsync(command, cmd =>
            {
                _state = _state.AddSubscription(Guid.NewGuid().ToString(), command);
                TellStateUpdated();
            });
            return(true);
        }
示例#6
0
 private bool IsSubscriptionValid(SubscriptionCreateCommand command)
 {
     return(command != null && command.ReleaseId == PersistenceId && command.UtcExpiration > DateTime.UtcNow);
 }