public async Task <dynamic> FindItemsWhereArrayContainsWithAndClauseAsync(string arrayName, string propertyName, string andPropertyName, ResourceFilter resourceFilter, bool isResourceCountCall = false) { EnsureParametersAreNotNullOrEmpty(arrayName, propertyName, andPropertyName, resourceFilter.ResourceType); string arrayContainsWithAndClause = ArrayContainsWithOrClause(arrayName, propertyName, resourceFilter.TopicIds); if (!string.IsNullOrEmpty(arrayContainsWithAndClause)) { arrayContainsWithAndClause = "(" + arrayContainsWithAndClause + ")"; } if (resourceFilter.ResourceType.ToUpperInvariant() != Constants.ResourceTypeAll && !isResourceCountCall) { arrayContainsWithAndClause += string.IsNullOrEmpty(arrayContainsWithAndClause) ? $" c.{andPropertyName} = '" + resourceFilter.ResourceType + "'" : $" AND c.{andPropertyName} = '" + resourceFilter.ResourceType + "'"; } string resourceIsActiveFilter = FindItemsWhereResourceIsActive(resourceFilter.ResourceType); if (!string.IsNullOrEmpty(resourceIsActiveFilter)) { arrayContainsWithAndClause = string.IsNullOrEmpty(arrayContainsWithAndClause) ? resourceIsActiveFilter : arrayContainsWithAndClause + " AND " + resourceIsActiveFilter; } string locationFilter = FindLocationWhereArrayContains(resourceFilter.Location); if (!string.IsNullOrEmpty(locationFilter)) { arrayContainsWithAndClause = string.IsNullOrEmpty(arrayContainsWithAndClause) ? locationFilter : arrayContainsWithAndClause + " AND " + locationFilter; } PagedResources pagedResources = new PagedResources(); if (isResourceCountCall) { var query = $"SELECT c.resourceType FROM c WHERE {arrayContainsWithAndClause}"; pagedResources = await backendDatabaseService.QueryResourcesCountAsync(query); } else { var query = $"SELECT * FROM c WHERE {arrayContainsWithAndClause}"; if (resourceFilter.IsOrder) { if (resourceFilter?.OrderByField == "date") { resourceFilter.OrderByField = "modifiedTimeStamp"; } var orderByField = (resourceFilter.OrderByField != null) ? resourceFilter.OrderByField : "name"; query = $"SELECT * FROM c WHERE {arrayContainsWithAndClause} order by c.{orderByField} {resourceFilter.OrderBy}"; } if (resourceFilter.PageNumber == 0) { pagedResources = await backendDatabaseService.QueryPagedResourcesAsync(query, ""); pagedResources.TopicIds = resourceFilter.TopicIds; } else { pagedResources = await backendDatabaseService.QueryPagedResourcesAsync(query, resourceFilter.ContinuationToken); pagedResources.TopicIds = resourceFilter.TopicIds; } } return(pagedResources); }