Query through (unpublished) content on property value
I have a set of events that I created from a external data set. When syncing these events I need to see if this content is already exists based on the value of a property.
I have a document type with a properly EventId. Now I want to query through all content in a specific collection. And see if there already is content where the EventId matches my external event id.
private bool ContentExists(string searchString)
{
const int pageSize = 100;
var propertyAlias = MyDetailPage.GetModelPropertyType(i => i.Propety).Alias;
var collectionNode = _contentService.GetById(GetCollectionGuid()); // get Guid of the parent node, create method yourself
var pages = Convert.ToInt32(Math.Ceiling(_contentService.CountChildren(collectionNode.Id, MyDetailPage.ModelTypeAlias) / (float)pageSize)); // count the number of children for the parent node
if (pages <= 0)
{
return false; // if 0 zero it means there are no children
}
// umbraco only allows us to navigate through children paginated
for (var pageIndex = 0; pageIndex < pages; pageIndex++)
{
var children = _contentService.GetPagedChildren(eventCollectionNode.Id, pageIndex, pageSize, out _);
if (children.Any(i => i.GetValue<object>(propertyAlias).Equals(searchString, StringComparison.OrdinalIgnoreCase)))
{
return true;
}
}
return false;
}
Query through (unpublished) content on property value
I have a set of events that I created from a external data set. When syncing these events I need to see if this content is already exists based on the value of a property.
I have a document type with a properly
EventId
. Now I want to query through all content in a specific collection. And see if there already is content where theEventId
matches my external event id.I saw some posts using the
But the
Descendents
method doesn't exist in Umbraco 8?For anyone in the future, my working code:
is working on a reply...