Finding events

Sitefinity allows you to search for a specific event. For more information about querying events by ID, see Querying events.

To search for a specific event you can use the Native API or the Fluent API.

The section contains the following:

Searching for an event by title

The following examples search for a specific event with the specified Title.

Native API

public Event GetEventByTitleNativeAPI(string titleToSearch)
{
    EventsManager eventsManager = EventsManager.GetManager();
    Event eventItem = eventsManager.GetEvents().Where(e => (e.Title == titleToSearch && e.Status == ContentLifecycleStatus.Live))
        .FirstOrDefault();
    return eventItem;
}

First, you initialize EventsManager. Then, you get all events using GetEvents() and filter based on the Title and Status properties. Finally, you return the event.

Fluent API

public Event GetEventByTitleFluentAPI(string titleToSearch)
{
    Event eventItem = App.WorkWith().Events().Where(ev => (ev.Title == titleToSearch && ev.Status == ContentLifecycleStatus.Live))
        .Get().FirstOrDefault();
    return eventItem;
}

First, you initialize the plural facade of the event using App.WorkWith().Events(). Then, you filter based on the Title and Status properties. To get the event, you use the Get method. Finally, you return the event.

Searching for events by content match

The following examples search for all events that have the specified string in their content.

Native API

public IQueryable<Event> GetEventByContentMatchNativeAPI(string contentToSearch)
{
    EventsManager eventsManager = EventsManager.GetManager();
    IQueryable<Event> events = eventsManager.GetEvents()
                            .Where(ev => (ev.Content.Contains(contentToSearch) && ev.Status == ContentLifecycleStatus.Live));
    return events;
}

First, you initialize EventsManager. Then, you get all events using GetEvents() and filter based on the Content and Status properties. Finally, you return the events.

Fluent API

public IQueryable<Event> GetEventByContentMatchFluentAPI(string contentToSearch)
{
    IQueryable<Event> events = App.WorkWith().Events()
                                    .Where(ev => (ev.Content.Contains(contentToSearch) && ev.Status == ContentLifecycleStatus.Live)).Get();
    return events;
}

First, you initialize the plural facade of the event using App.WorkWith().Events(). Then, you filter based on the Content and Statusproperties. To get the events, you use the Get method. Finally, you return the events.

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK