reate Query Part And A Filter

Topics: Writing modules
Nov 26, 2014 at 4:33 AM
Edited Nov 26, 2014 at 4:33 AM
hi everyone,i want to create a query part instance and a new filter instead of group filter,what should i do? my code like this:
    string  s = "beijing"+new Random().Next();
    var item = _orchardServices.ContentManager.New("Query");
    item.As<TitlePart>().Title = s;
    _orchardServices.ContentManager.Create(item, VersionOptions.Draft);
    if (!item.Has<IPublishingControlAspect>() && !item.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable)
        _orchardServices.ContentManager.Publish(item);

    var queryPart = item.As<QueryPart>();
    queryPart.ContentItem.ContentType = s;
    string desc =" HI,this is my new filter";
    string contentType = "CommonPart.ChannelID.";
    var filterGroupRecord = new FilterGroupRecord();
    var filterRecord = new FilterRecord()
    {
        Category = "CommonPartContentFields",
        Type = contentType,
        Position = 0,
    };
    filterRecord.State = "<Form><Description>" + desc + "</Description><Operator>Equals</Operator><Value>ChannelId</Value></Form>";
    filterGroupRecord.Filters.Add(filterRecord);
    queryPart.FilterGroups.Insert(0, filterGroupRecord);
Developer
Nov 26, 2014 at 2:26 PM
Hey, I don't understand what you are trying to do.

Where is this filter used?