/// <summary> /// Checks if an offer exists. /// </summary> /// <param name="offerName">The name of the offer to check exists.</param> /// <returns>True if exists, false otherwise.</returns> public async Task <bool> ExistsAsync(string offerName) { _logger.LogInformation(LoggingUtils.ComposeCheckResourceExistsMessage(typeof(Offer).Name, offerName)); // Check that only one offer with this offerName exists and has not been deleted var count = await _context.Offers .CountAsync(o => (o.OfferName == offerName) && (o.DeletedTime == null)); // More than one instance of an object with the same name exists, this should not happen if (count > 1) { throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(Offer).Name, offerName)); } else if (count == 0) { _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(Offer).Name, offerName, false)); return(false); } else { _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(Offer).Name, offerName, true)); // count = 1 return(true); } }
public async Task <bool> ExistsAsync(Guid subscriptionID, string name) { _logger.LogInformation(LoggingUtils.ComposeCheckResourceExistsMessage(typeof(SubscriptionParameter).Name, name)); // Check that only one armTemplateParameter with this name exists within the offer var count = await _context.SubscriptionParameters .CountAsync(p => (p.SubscriptionId == subscriptionID) && (p.Name == name)); // More than one instance of an object with the same name exists, this should not happen if (count > 1) { throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(SubscriptionParameter).Name, name, subscriptionId: subscriptionID)); } else if (count == 0) { _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(SubscriptionParameter).Name, name, false)); return(false); } else { _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(SubscriptionParameter).Name, name, true)); // count = 1 return(true); } }
/// <summary> /// Checks if an aadSecretTmp object exists within an offer. /// </summary> /// <param name="offerName">The name of the offer.</param> /// <param name="name">The name of the aadSecretTmp to check exists.</param> /// <returns>True if exists, false otherwise.</returns> public async Task <bool> ExistsAsync(string offerName, string name) { _logger.LogInformation(LoggingUtils.ComposeCheckResourceExistsMessage(typeof(AadSecretTmp).Name, name, offerName: offerName)); //Get the offer associated with the offerName provided var offer = await _offerService.GetAsync(offerName); // Check that only one aadSecretTmp with this name exists within the offer var count = await _context.AadSecretTmps .CountAsync(a => (a.OfferId == offer.Id) && (a.Name == name)); // More than one instance of an object with the same name exists, this should not happen if (count > 1) { throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(AadSecretTmp).Name, name, offerName: offerName)); } else if (count == 0) { _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(AadSecretTmp).Name, name, false, offerName: offerName)); return(false); } else { _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(AadSecretTmp).Name, name, true, offerName: offerName)); // count = 1 return(true); } }
public async Task <bool> ExistsAsync(string offerName, string planName, Guid tenantId) { _logger.LogInformation(LoggingUtils.ComposeCheckResourceExistsMessage(typeof(RestrictedUser).Name, tenantId.ToString(), offerName: offerName, planName: planName)); var plan = await _planService.GetAsync(offerName, planName); // Check that only one restructed user with this templateName exists within the offer var count = await _context.RestrictedUsers .CountAsync(a => (a.PlanId == plan.Id) && (a.TenantId == tenantId)); // More than one instance of an object with the same name exists, this should not happen if (count > 1) { throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(RestrictedUser).Name, tenantId.ToString(), offerName: offerName, planName: planName)); } else if (count == 0) { _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(RestrictedUser).Name, tenantId.ToString(), false, offerName: offerName, planName: planName)); return(false); } else { _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(RestrictedUser).Name, tenantId.ToString(), true, offerName: offerName, planName: planName)); // count = 1 return(true); } }
/// <summary> /// Checks if a subscription exists. /// </summary> /// <param name="subscriptionId">The id of the subscription to check exists.</param> /// <returns>True if exists, false otherwise.</returns> public async Task <bool> ExistsAsync(Guid subscriptionId) { _logger.LogInformation(LoggingUtils.ComposeCheckResourceExistsMessage(typeof(Subscription).Name, subscriptionId.ToString())); // Check that only one subscription with this subscriptionId exists var count = await _context.Subscriptions .CountAsync(s => s.SubscriptionId == subscriptionId); // More than one instance of an object with the same name exists, this should not happen if (count > 1) { throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(Subscription).Name, subscriptionId.ToString())); } else if (count == 0) { _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(Subscription).Name, subscriptionId.ToString(), false)); return(false); } else { _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(Subscription).Name, subscriptionId.ToString(), true)); // count = 1 return(true); } }