Пример #1
0
        /// <summary>
        /// Updates an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer to update.</param>
        /// <param name="offer">The updated offer.</param>
        /// <returns>The updated offer.</returns>
        public async Task <Offer> UpdateAsync(string offerName, Offer offer)
        {
            if (offer is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(Offer).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(Offer).Name, offer.OfferName, payload: JsonSerializer.Serialize(offer)));

            // Get the offer that matches the offerName provided
            var offerDb = await GetAsync(offerName);

            // Check if (the offerName has been updated) &&
            //          (an offer with the same new name does not already exist)
            if ((offerName != offer.OfferName) && (await ExistsAsync(offer.OfferName)))
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposeNameMismatchErrorMessage(typeof(Offer).Name),
                                                      UserErrorCode.NameMismatch);
            }

            // Copy over the changes
            offerDb.Copy(offer);

            // Update the offer last updated time
            offerDb.LastUpdatedTime = DateTime.UtcNow;

            // Update offerDb values and save changes in db
            _context.Offers.Update(offerDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(Offer).Name, offer.OfferName));

            return(offerDb);
        }
        /// <summary>
        /// Updates a customMeter.
        /// </summary>
        /// <param name="meterName">The name of the customMeter to update.</param>
        /// <param name="customMeter">The updated customMeter.</param>
        /// <returns>The updated customMeter.</returns>
        public async Task <CustomMeter> UpdateAsync(string meterName, CustomMeter customMeter)
        {
            if (customMeter is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(CustomMeter).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(CustomMeter).Name, customMeter.MeterName, payload: JsonSerializer.Serialize(customMeter)));

            // Get the customMeter that matches the meterName provided
            var customMeterDb = await GetAsync(meterName);

            // Check if (the meterName has been updated) &&
            //          (a customMeter with the same new name does not already exist)
            if ((meterName != customMeter.MeterName) && (await ExistsAsync(customMeter.MeterName)))
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposeNameMismatchErrorMessage(typeof(CustomMeter).Name),
                                                      UserErrorCode.NameMismatch);
            }

            // Copy over the changes
            customMeterDb.Copy(customMeter);

            // Update customMeterDb values and save changes in db
            _context.CustomMeters.Update(customMeterDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(CustomMeter).Name, customMeter.MeterName));

            return(customMeterDb);
        }
Пример #3
0
        /// <summary>
        /// Updates an aadSecretTmp object within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="name">The name of the aadSecretTmp object to update.</param>
        /// <param name="aadSecretTmp">The updated aadSecretTmp object.</param>
        /// <returns>The updated aadSecretTmp object.</returns>
        public async Task <AadSecretTmp> UpdateAsync(string offerName, string name, AadSecretTmp aadSecretTmp)
        {
            if (aadSecretTmp is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(AadSecretTmp).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }

            // Check if (the name has been updated) &&
            //          (an aadSecretTmp with the same new name does not already exist)
            if ((name != aadSecretTmp.Name) && (await ExistsAsync(offerName, aadSecretTmp.Name)))
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposeNameMismatchErrorMessage(typeof(AadSecretTmp).Name),
                                                      UserErrorCode.NameMismatch);
            }

            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(AadSecretTmp).Name, name, offerName: offerName, payload: JsonSerializer.Serialize(aadSecretTmp)));

            // Get the aadSecretTmp that matches the name provided
            var aadSecretTmpDb = await GetAsync(offerName, name);

            // Copy over the changes
            aadSecretTmpDb.Copy(aadSecretTmp);

            // Update aadSecretTmpDb values and save changes in db
            _context.AadSecretTmps.Update(aadSecretTmpDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(AadSecretTmp).Name, name, offerName: offerName));

            return(aadSecretTmpDb);
        }
        /// <summary>
        /// Updates a customMeterDimension.
        /// </summary>
        /// <param name="id">The id of the customMeterDimension to update.</param>
        /// <param name="customMeterDimension">The updated customMeterDimension.</param>
        /// <returns>The updated customMeterDimension.</returns>
        public async Task <CustomMeterDimension> UpdateAsync(long id, CustomMeterDimension customMeterDimension)
        {
            if (customMeterDimension is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(CustomMeterDimension).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(
                                       typeof(CustomMeterDimension).Name,
                                       customMeterDimension.Id.ToString(),
                                       planName: customMeterDimension.Plan.PlanName,
                                       payload: JsonSerializer.Serialize(customMeterDimension)));

            // Get the customMeterDimension that matches the id provided
            var customMeterDimensionDb = await GetAsync(id);

            // update the FK to customMeter in case the meterName has been changed
            customMeterDimensionDb.MeterId = (await _customMeterService.GetAsync(customMeterDimension.MeterName)).Id;

            // Copy over the changes
            customMeterDimensionDb.Copy(customMeterDimension);

            // Update customMeterDimensionDb values and save changes in db
            _context.CustomMeterDimensions.Update(customMeterDimensionDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(
                                       typeof(CustomMeterDimension).Name,
                                       customMeterDimension.Id.ToString(),
                                       planName: customMeterDimension.Plan.PlanName));

            return(customMeterDimensionDb);
        }
Пример #5
0
        /// <summary>
        /// Updates a plan within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="planUniqueName">The name of the plan to update.</param>
        /// <param name="plan">The updated plan.</param>
        /// <returns>The updated plan.</returns>
        public async Task <Plan> UpdateAsync(string offerName, string planUniqueName, Plan plan)
        {
            if (plan is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(Plan).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }

            // Check if (the planUniqueName has been updated) &&
            //          (a plan with the same new planUniqueName does not already exist)
            if ((planUniqueName != plan.PlanName) && (await ExistsAsync(offerName, plan.PlanName)))
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposeNameMismatchErrorMessage(typeof(Plan).Name),
                                                      UserErrorCode.NameMismatch);
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(Plan).Name, planUniqueName, offerName: offerName, payload: JsonSerializer.Serialize(plan)));

            var dbPlan = await GetAsync(offerName, planUniqueName);

            dbPlan.Copy(plan);

            dbPlan = await SetArmTemplateAndWebhookIds(offerName, dbPlan);

            _context.Plans.Update(dbPlan);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(Plan).Name, planUniqueName, offerName: offerName));

            return(dbPlan);
        }
Пример #6
0
        /// <summary>
        /// Updates a webhook within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="webhookName">The name of the webhook to update.</param>
        /// <param name="webhook">The new webhook.</param>
        /// <returns>The updated webhook.</returns>
        public async Task <Webhook> UpdateAsync(string offerName, string webhookName, Webhook webhook)
        {
            if (webhook is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(Webhook).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }

            // Check if (the webhookName has been updated) &&
            //          (a webhook with the same new webhookName does not already exist)
            if ((webhookName != webhook.WebhookName) && (await ExistsAsync(offerName, webhook.WebhookName)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(Webhook).Name,
                                                                                             webhook.WebhookName, offerName: offerName));
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(Webhook).Name, webhook.WebhookName, offerName: offerName, payload: JsonSerializer.Serialize(webhook)));

            // Get the webhook that matches the webhookName provided
            var webhookDb = await GetAsync(offerName, webhookName);

            // Copy over the changes
            webhookDb.Copy(webhook);

            // Update webhook values and save changes in db
            _context.Webhooks.Update(webhookDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(nameof(Webhook), webhookName, offerName: offerName));

            await UpdateWebhookParameters(await _offerService.GetAsync(offerName), webhookDb, webhookDb.Id);

            return(webhook);
        }
        /// <summary>
        /// Updates a TelemetryDataConnector.
        /// </summary>
        /// <param name="name">The name of the TelemetryDataConnector.</param>
        /// <param name="connector">The updated TelemetryDataConnector.</param>
        /// <returns>The updated TelemetryDataConnector.</returns>
        public async Task <TelemetryDataConnector> UpdateAsync(string name, TelemetryDataConnector connector)
        {
            if (connector is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(TelemetryDataConnector).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(TelemetryDataConnector).Name,
                                                                             name, payload: JsonSerializer.Serialize(connector)));

            if (!await ExistsAsync(name))
            {
                throw new LunaConflictUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(TelemetryDataConnector).Name,
                                                                                             name));
            }

            // Get the customMeter that matches the meterName provided
            var connectorDb = await GetAsync(name);

            // Copy over the changes
            connectorDb.Copy(connector);

            // Update connector values and save changes in db
            _context.TelemetryDataConnectors.Update(connectorDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(TelemetryDataConnector).Name, name));

            return(connector);
        }
Пример #8
0
        /// <summary>
        /// Updates a customMeter.
        /// </summary>
        /// <param name="subscriptionId">The subscription id.</param>
        /// <param name="meterName">The name of the customMeter to update.</param>
        /// <param name="customMeter">The updated customMeter.</param>
        /// <returns>The updated customMeter.</returns>
        public async Task <SubscriptionCustomMeterUsage> UpdateAsync(Guid subscriptionId,
                                                                     string meterName,
                                                                     SubscriptionCustomMeterUsage subscriptionCustomMeterUsage)
        {
            if (subscriptionCustomMeterUsage is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(SubscriptionCustomMeterUsage).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }
            var subscription = await _subscriptionService.GetAsync(subscriptionId);

            var customMeter = await _customMeterService.GetAsync(subscription.OfferName, meterName);

            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(
                                       typeof(SubscriptionCustomMeterUsage).Name,
                                       customMeter.MeterName,
                                       payload: JsonSerializer.Serialize(customMeter),
                                       subscriptionId: subscriptionId));

            // Get the customMeter that matches the meterName provided
            var subscriptionCustomMeterUsageDb = await GetAsync(subscriptionId, meterName);

            // Check if (the meterName has been updated) &&
            //          (a customMeter with the same new name does not already exist)
            if (subscriptionCustomMeterUsageDb.SubscriptionId != subscriptionCustomMeterUsage.SubscriptionId ||
                subscriptionCustomMeterUsageDb.MeterId != subscriptionCustomMeterUsage.MeterId)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposeNameMismatchErrorMessage(typeof(SubscriptionCustomMeterUsage).Name),
                                                      UserErrorCode.NameMismatch);
            }

            // Copy over the changes
            subscriptionCustomMeterUsageDb.Copy(subscriptionCustomMeterUsage);

            // Update customMeterDb values and save changes in db
            _context.SubscriptionCustomMeterUsages.Update(subscriptionCustomMeterUsageDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(
                                       typeof(SubscriptionCustomMeterUsage).Name,
                                       customMeter.MeterName,
                                       subscriptionId: subscriptionId));

            return(subscriptionCustomMeterUsageDb);
        }
Пример #9
0
        /// <summary>
        /// Updates a restrictedUser
        /// </summary>
        /// <param name="offerName">The offer name.</param>
        /// <param name="planName">The plan name.</param>
        /// <param name="restrictedUser">The updated restrictedUser.</param>
        /// <returns>The updated restrictedUser.</returns>
        public async Task <RestrictedUser> UpdateAsync(string offerName, string planName, RestrictedUser restrictedUser)
        {
            if (restrictedUser is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(RestrictedUser).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(RestrictedUser).Name, restrictedUser.TenantId.ToString(), offerName: offerName, planName: planName, payload: JsonSerializer.Serialize(restrictedUser)));

            var dbUser = await GetAsync(offerName, planName, restrictedUser.TenantId);

            dbUser.Copy(restrictedUser);

            // Update restrictedUserDb values and save changes in db
            _context.RestrictedUsers.Update(dbUser);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(RestrictedUser).Name, restrictedUser.TenantId.ToString(), offerName: offerName, planName: planName));

            return(dbUser);
        }
Пример #10
0
        /// <summary>
        /// Updates an ArmTemplateParameter within an offer by name.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="parameterName">The name of the ArmTemplateParameter to update.</param>
        /// <param name="armTemplateParameter">The updated ArmTemplateParameter object.</param>
        /// <returns>The updated ArmTemplateParameter object.</returns>
        public async Task <ArmTemplateParameter> UpdateAsync(string offerName, string parameterName, ArmTemplateParameter armTemplateParameter)
        {
            if (armTemplateParameter is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(ArmTemplateParameter).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(ArmTemplateParameter).Name, armTemplateParameter.Name, offerName: offerName, payload: JsonSerializer.Serialize(armTemplateParameter)));

            Offer offer = await _offerService.GetAsync(offerName);

            ArmTemplateParameter armTemplateParameterDb = await GetAsync(offerName, parameterName);

            armTemplateParameterDb.Copy(armTemplateParameter);
            armTemplateParameterDb.OfferId = offer.Id;

            _context.ArmTemplateParameters.Update(armTemplateParameterDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(ArmTemplateParameter).Name, armTemplateParameter.Name, offerName: offerName));

            return(armTemplateParameterDb);
        }
Пример #11
0
        /// <summary>
        /// Updates a webhookParameter within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="parameterName">The name of the webhookParameter to update.</param>
        /// <param name="webhookParameter">The updated webhookParameter.</param>
        /// <returns>The updated webhookParameter.</returns>
        public async Task <WebhookParameter> UpdateAsync(string offerName, string parameterName, WebhookParameter webhookParameter)
        {
            if (webhookParameter is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(WebhookParameter).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }

            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(WebhookParameter).Name, webhookParameter.Name, offerName: offerName, payload: JsonSerializer.Serialize(webhookParameter)));

            // Get the webhookParameter that matches the name provided
            var webhookParameterDb = await GetAsync(offerName, parameterName);

            // Copy over the changes
            webhookParameterDb.Copy(webhookParameter);

            // Update webhookParameterDb values and save changes in db
            _context.WebhookParameters.Update(webhookParameterDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(WebhookParameter).Name, webhookParameter.Name, offerName: offerName));

            return(webhookParameterDb);
        }
Пример #12
0
        /// <summary>
        /// Updates a customMeter.
        /// </summary>
        /// <param name="offerName">The offer name of the customMeter.</param>
        /// <param name="meterName">The name of the customMeter to update.</param>
        /// <param name="customMeter">The updated customMeter.</param>
        /// <returns>The updated customMeter.</returns>
        public async Task <CustomMeter> UpdateAsync(string offerName, string meterName, CustomMeter customMeter)
        {
            if (customMeter is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(CustomMeter).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(CustomMeter).Name, customMeter.MeterName, payload: JsonSerializer.Serialize(customMeter)));

            // Get the customMeter that matches the meterName provided
            var customMeterDb = await GetAsync(offerName, meterName);

            if ((meterName != customMeter.MeterName) || (offerName != customMeter.OfferName))
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposeNameMismatchErrorMessage(typeof(CustomMeter).Name),
                                                      UserErrorCode.NameMismatch);
            }

            // Copy over the changes
            customMeterDb.Copy(customMeter);

            var offer = await _offerService.GetAsync(offerName);

            var connector = await _telemetryDataconnectorService.GetAsync(customMeter.TelemetryDataConnectorName);

            customMeterDb.TelemetryDataConnectorId = connector.Id;
            customMeterDb.OfferId = offer.Id;

            // Update customMeterDb values and save changes in db
            _context.CustomMeters.Update(customMeterDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(CustomMeter).Name, customMeter.MeterName));

            return(customMeterDb);
        }
Пример #13
0
        /// <summary>
        /// Updates an ipConfig within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="name">The name of the ipConfig to update.</param>
        /// <param name="ipConfig">The updated ipConfig.</param>
        /// <returns>The updated ipConfig.</returns>
        public async Task <IpConfig> UpdateAsync(string offerName, string name, IpConfig ipConfig)
        {
            if (ipConfig is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(Plan).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }

            // Check that that an IpConfig with the given name exists within the Offer
            if (!(await ExistsAsync(offerName, name)))
            {
                throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(IpConfig).Name,
                                                                                             name,
                                                                                             offerName: offerName));
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(IpConfig).Name, name, offerName: offerName, payload: JsonSerializer.Serialize(ipConfig)));

            // Validate that the values provided for the IpConfig are syntactically and logically correct
            ipConfig = validateIpConfig(ipConfig);

            // Get the ipConfig that matches the name provided
            var ipConfigDb = await GetAsync(offerName, name);

            // Verify that the only change is the addition of new IpBlocks
            List <string> addedBlocks = OnlyIpBlocksAdded(ipConfigDb, ipConfig);

            // Process the added IpBlocks
            await ProcessIpBlocks(addedBlocks, ipConfigDb.Id);

            // Get the ipConfig from the db again to repopulate the IpBlocks
            ipConfigDb = await GetAsync(offerName, name);

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(IpConfig).Name, name, offerName: offerName));

            return(ipConfigDb);
        }
Пример #14
0
        /// <summary>
        /// Updates a subscription.
        /// </summary>
        /// <param name="subscription">The updated subscription.</param>
        /// <returns>The updated subscription.</returns>
        public async Task <Subscription> UpdateAsync(Subscription subscription, Guid operationId)
        {
            if (subscription is null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(Subscription).Name),
                                                      UserErrorCode.PayloadNotProvided);
            }
            _logger.LogInformation(LoggingUtils.ComposeUpdateResourceMessage(typeof(Subscription).Name, subscription.Name, offerName: subscription.OfferName, planName: subscription.PlanName, payload: JsonSerializer.Serialize(subscription)));
            var newPlanName = subscription.PlanName;
            var newQuantity = subscription.Quantity;

            Subscription subscriptionDb;

            try
            {
                // Get the subscription that matches the subscriptionId provided
                subscriptionDb = await GetAsync(subscription.SubscriptionId);
            }
            catch (Exception)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposeSubscriptionActionErrorMessage(subscription.SubscriptionId, SubscriptionAction.Update.ToVerb()), UserErrorCode.ResourceNotFound);
            }

            CheckSubscriptionInReadyState(subscriptionDb);

            // Get the offer and plan associated with the subscriptionId provided
            var offer = await _context.Offers.FindAsync(subscriptionDb.OfferId);

            var plan = await _context.Plans.FindAsync(subscriptionDb.PlanId);

            if (newPlanName != plan.PlanName && subscriptionDb.Quantity != newQuantity)
            {
                throw new ArgumentException("Cannot update plan and quantity at the same time.");
            }

            // Check if the plan has been upgraded or downgraded
            if (newPlanName != plan.PlanName)
            {
                _logger.LogInformation($"Updating subscription {subscription.SubscriptionId} from plan {plan.PlanName} to {newPlanName}.");
                // Get the new plan to change to
                var newPlan = await _planService.GetAsync(offer.OfferName, newPlanName);

                // Update the FK to the new plan
                subscription.OperationId          = operationId;
                subscriptionDb.PlanId             = newPlan.Id;
                subscriptionDb.ProvisioningStatus = nameof(ProvisioningState.ArmTemplatePending);
                subscriptionDb.ProvisioningType   = nameof(ProvisioningType.Update);
            }
            else if (subscriptionDb.Quantity != subscription.Quantity)
            {
                _logger.LogInformation($"Updating subscription {subscription.SubscriptionId} from quantity {subscriptionDb.Quantity} to {subscription.Quantity}");
                subscriptionDb.Quantity = newQuantity;
                //TODO: what to do?
            }

            // Set the updated time
            subscriptionDb.LastUpdatedTime = DateTime.UtcNow;

            // Update subscriptionDb values and save changes in db
            _context.Subscriptions.Update(subscriptionDb);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceUpdatedMessage(typeof(Subscription).Name, subscription.Name, offerName: subscription.OfferName, planName: subscription.PlanName));

            return(subscriptionDb);
        }