public ReleaseState AddSubscription(string subscriptionId, SubscriptionCreateCommand command) { var state = new ReleaseState(this); state.Subscription = new SubscriptionState(subscriptionId, command); return(state); }
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")); }
public SubscriptionState(string subscriptionId, SubscriptionCreateCommand command) { SubscriptionId = subscriptionId; UtcExpiration = command.UtcExpiration; ReleaseId = command.ReleaseId; ShopIds = command.ShopIds; Cost = command.Cost; Timestamp = command.Timestamp; }
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); }
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); }
private bool IsSubscriptionValid(SubscriptionCreateCommand command) { return(command != null && command.ReleaseId == PersistenceId && command.UtcExpiration > DateTime.UtcNow); }