private static IList <SubscriptionParameter> ParseParameters(XElement element) { var parameters = new List <SubscriptionParameter>(); foreach (var parameter in element.Elements().Where(x => x.Name.LocalName == "param")) { var param = new SubscriptionParameter(); foreach (var elt in parameter.Elements()) { if (elt.Name.LocalName == "name") { param.ParameterName = elt.Value; } else if (elt.Name.LocalName == "value") { param.Values.Add(new SubscriptionParameterValue { Parameter = param, Value = elt.Value }); } else { throw new Exception($"Element '{elt.Name.LocalName}' is not expected here."); } } parameters.Add(param); } return(parameters.ToArray()); }
public async Task <SubscriptionParameter> CreateAsync(SubscriptionParameter subscriptionParameter) { if (subscriptionParameter is null) { throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(typeof(SubscriptionParameter).Name), UserErrorCode.PayloadNotProvided); } // Check that the offer does not already have an armTemplateParameter with the same name if (await ExistsAsync(subscriptionParameter.SubscriptionId, subscriptionParameter.Name)) { throw new LunaConflictUserException(LoggingUtils.ComposeAlreadyExistsErrorMessage(typeof(SubscriptionParameter).Name, subscriptionParameter.Name)); } if (!await _subscriptionService.ExistsAsync(subscriptionParameter.SubscriptionId)) { throw new ArgumentException("Subscription doesn't exist."); } _logger.LogInformation(LoggingUtils.ComposeCreateResourceMessage(typeof(SubscriptionParameter).Name, subscriptionParameter.Name, payload: JsonSerializer.Serialize(subscriptionParameter))); // Add armTemplateParameter to db _context.SubscriptionParameters.Add(subscriptionParameter); await _context._SaveChangesAsync(); _logger.LogInformation(LoggingUtils.ComposeResourceCreatedMessage(typeof(SubscriptionParameter).Name, subscriptionParameter.Name)); return(subscriptionParameter); }