0
votes

Using Orchard 1.6, I've set up a form that allows the user to upload an image (using a field).

I want the user to be able to navigate to a search page (on the dashboard) that allows them to search through all the uploads relating to this form. Bear in mind, this user will have some authority, so they can access the dashboard (but can't access the 'content' section, which allows the user to search through all the content items). Also, I only want the content items for this content part to be listed.

I've set up a new controller and a view, so the user can access an empty page on the dashboard. In the function, I want to display a list of all the content items for that content type and include a search feature.

The trouble is, where I have done this before I have been using the tables I created myself ("Supplier", for example) and used a loop to add to another list if it's a match, and then display that second list.

However, the content items are saved to their own contentItemRecord as a column:

<Data><AddressPart>
      <Name></Name>
      <AddressLine1></AddressLine1>
      <AddressLine2></AddressLine2>
      <Zipcode></Zipcode>
      <City></City>
      <Country></Country>
      </AddressPart>
</Data>

How can I use this to search?

1

1 Answers

1
votes

I would use the Orchard HQL API, which I have found is really good in cases where you need some sort of search where the filters may change. If the filters (like if they can search either by address or city) don't change I would just use the regular Orchard API. Here is an example of using the HQL API:

public class ExampleService : IExampleService
        {
            private readonly IContentManager _contentManager;


            public ExampleService
                (
                IContentManager contentManager
                )
            {
                _contentManager = contentManager;
            }

    public IEnumerable<ContentItem>(){
    IHqlQuery query = _contentManager.HqlQuery().ForType("YourContentType");

    //You can also make joins on content parts and set criteria
    Action<IAliasFactory> selector = alias => alias.ContentPartRecord<ExamplePartRecord>();    
    //Put any type of filter you want here, you can use conjunctions as well as disjunctions.
    Action<IHqlExpressionFactory> filter = x => x.IsNotNull("Id");

    query = query.Where(selector,filter);

    return query.List();
    }
}