Beispiel #1
0
        public async Task <IActionResult> UpdateSubscription(UpdateSubscriptionViewModel model)
        {
            var subscription = _dbContext.Subscriptions.Where(
                subscription => subscription.Id == model.Subscription.Id).Single();

            OperationUpdate operation = null;

            // check if the plan is changed
            if (model.Subscription.PlanId != subscription.PlanId)
            {
                // create change plan operation
                operation = new OperationUpdate()
                {
                    Id             = Guid.NewGuid(),
                    Action         = SaaSActionEnum.ChangePlan,
                    SubscriptionId = subscription.Id,
                    Quantity       = model.Subscription.Quantity,
                    Status         = SaasStatusEnum.InProgress,
                    PlanId         = model.Subscription.PlanId
                };
            }
            else
            {
                // create change quantity operation
                operation = new OperationUpdate()
                {
                    Id             = Guid.NewGuid(),
                    Action         = SaaSActionEnum.ChangeQuantity,
                    SubscriptionId = subscription.Id,
                    Quantity       = model.Subscription.Quantity,
                    Status         = SaasStatusEnum.InProgress,
                    PlanId         = model.Subscription.PlanId
                };
            }
            model.OperationUpdateId = operation.Id;

            // save data in cache
            _cache.Set(operation.Id, operation, _cacheEntryOptions);
            // webhook trigger: send notifaction to ISV service
            await _webhookTriggerService.NotifyAsync(operation);

            return(View(model));
        }
        public IActionResult PatchSubscription([FromRoute] Guid subscriptionId, [FromBody] ChangeQuantityPayload changeQuantityPayload)
        {
            // create cancel subscription operation
            var operation = new OperationUpdate()
            {
                Id             = Guid.NewGuid(),
                Action         = SaaSActionEnum.ChangeQuantity,
                SubscriptionId = subscriptionId,
                Quantity       = changeQuantityPayload.Quantity,
                Status         = SaasStatusEnum.InProgress
            };

            // save data in cache.
            _cache.Set(operation.Id, operation, _cacheEntryOptions);

            _webhookTriggerService.NotifyAsync(operation);

            return(StatusCode(202));
        }