/// <summary> /// Gets a SubscriptionCustomMeterUsage. /// </summary> /// <param name="subscriptionId">The subscription id.</param> /// <param name="meterName">The name of the SubscriptionCustomMeterUsage.</param> /// <returns>The SubscriptionCustomMeterUsage.</returns> public async Task <SubscriptionCustomMeterUsage> GetAsync(Guid subscriptionId, string meterName) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(SubscriptionCustomMeterUsage).Name, meterName)); if (!(await ExistsAsync(subscriptionId, meterName))) { throw new LunaNotFoundUserException( LoggingUtils.ComposeNotFoundErrorMessage(typeof(SubscriptionCustomMeterUsage).Name, meterName, subscriptionId: subscriptionId)); } var subscription = await _subscriptionService.GetAsync(subscriptionId); // Get the subscriptionCustomMeterUsage that matches the provided subscription id and meterName var customMeter = await _customMeterService.GetAsync(subscription.OfferName, meterName); var subscriptionCustomMeterUsage = await _context.SubscriptionCustomMeterUsages .SingleOrDefaultAsync(c => c.MeterId == customMeter.Id && c.SubscriptionId.Equals(subscriptionId)); _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage( typeof(SubscriptionCustomMeterUsage).Name, meterName, JsonSerializer.Serialize(subscriptionCustomMeterUsage))); return(subscriptionCustomMeterUsage); }
/// <summary> /// Gets a customMeterDimension by id. /// </summary> /// <param name="id">The id of the customMeterDimension.</param> /// <returns>The customMeterDimension.</returns> public async Task <CustomMeterDimension> GetAsync(string offerName, string planName, string meterName) { _logger.LogInformation(LoggingUtils.ComposeGetSingleResourceMessage(typeof(CustomMeterDimension).Name, meterName, planName, offerName)); var meter = await _customMeterService.GetAsync(offerName, meterName); var plan = await _planService.GetAsync(offerName, planName); // Find the customMeterDimension that matches the id provided var customMeterDimension = await _context.CustomMeterDimensions.SingleOrDefaultAsync(c => c.PlanId == plan.Id && c.MeterId == meter.Id); // Check that an customMeterDimension with the provided id exists if (customMeterDimension is null) { throw new LunaNotFoundUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(CustomMeterDimension).Name, meterName, planName, offerName)); } // Set the customMeterDimension's meterName customMeterDimension.MeterName = meter.MeterName; customMeterDimension.PlanName = plan.PlanName; _logger.LogInformation(LoggingUtils.ComposeReturnValueMessage(typeof(CustomMeterDimension).Name, meterName, JsonSerializer.Serialize(customMeterDimension), planName, offerName)); return(customMeterDimension); }
public async Task <ActionResult> GetAsync(string offerName, string meterName) { AADAuthHelper.VerifyUserAccess(this.HttpContext, _logger, true); _logger.LogInformation($"Get custom meter {meterName} in offer {offerName}."); return(Ok(await _customMeterService.GetAsync(offerName, meterName))); }
/// <summary> /// Creates a customMeterDimension within a plan within an offer. /// </summary> /// <param name="offerName">The name of the offer.</param> /// <param name="planUniqueName">The name of the plan.</param> /// <param name="customMeterDimension">The customMeterDimension object to create.</param> /// <returns>The created customMeterDimension.</returns> public async Task <CustomMeterDimension> CreateAsync(string offerName, string planUniqueName, CustomMeterDimension customMeterDimension) { if (customMeterDimension is null) { throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(CustomMeterDimension).Name), UserErrorCode.PayloadNotProvided); } _logger.LogInformation(LoggingUtils.ComposeCreateResourceMessage( typeof(CustomMeterDimension).Name, customMeterDimension.Id.ToString(), offerName: offerName, planName: planUniqueName, payload: JsonSerializer.Serialize(customMeterDimension))); // Get the plan associated with the offerName and planUniqueName provided var plan = await _planService.GetAsync(offerName, planUniqueName); // Set the FK to plan customMeterDimension.PlanId = plan.Id; // Set the FK to customMeter customMeterDimension.MeterId = (await _customMeterService.GetAsync(customMeterDimension.MeterName)).Id; // Reset the PK (should not be modified in request) customMeterDimension.Id = 0; // Add customMeterDimension to db _context.CustomMeterDimensions.Add(customMeterDimension); await _context._SaveChangesAsync(); _logger.LogInformation(LoggingUtils.ComposeResourceCreatedMessage( typeof(ArmTemplateParameter).Name, customMeterDimension.Id.ToString(), offerName: offerName, planName: planUniqueName)); return(customMeterDimension); }
public async Task <ActionResult> GetAsync(string meterName) { return(Ok(await _customMeterService.GetAsync(meterName))); }