使用Microsoft Graph过滤两个扩展属性

时间:2017-09-07 12:33:14

标签: microsoft-graph extended-properties

我的一些日历活动有两个扩展属性:

// Extended Properties
var extendedProperties = new EventSingleValueExtendedPropertiesCollectionPage();
extendedProperties.Add(new SingleValueLegacyExtendedProperty
{
    Id = _Property_TruckleSoft1,
    Value = oSettings.CalendarEntryType
});

if(!string.IsNullOrEmpty(oSettings.ScheduleType))
{
    extendedProperties.Add(new SingleValueLegacyExtendedProperty
    {
        Id = _Property_TruckleSoft2,
        Value = oSettings.ScheduleType
    });
}

在其他代码中,我想过滤这些事件:

string strFilterProperty = $"singleValueExtendedProperties/Any(ep: ep/id eq '{eventTypeTag}' and ep/value eq '{oData.Settings.CalendarEntryType}')";

string strFilterProperty = $"singleValueExtendedProperties/Any(ep: ep/id eq '{scheduleTypeTag}' and ep/value eq '{oData.Settings.ScheduleType}')";

那么如何过滤上述扩展属性两者的事件呢?

1 个答案:

答案 0 :(得分:0)

这个question的回答确实有帮助。我过度复杂了!

所以:

public async Task<bool> DeleteExistingEvents(string idCalendar, DateTime dateStart, DateTime dateEnd, string typeEvent, string typeSchedule = "")
{
    try
    {
        // We only want events within the desired date range
        string strFilterDateRange = String.Format("start/dateTime ge '{0}T00:00' and end/dateTime le '{1}T23:59'",
            dateStart.ToString("yyyy-MM-dd"),
            dateEnd.ToString("yyyy-MM-dd"));

        // We only want events of the right type
        string strFilterProperty = $"singleValueExtendedProperties/Any(ep: ep/id eq '{_Property_TruckleSoft1}' and ep/value eq '{typeEvent}')";

        string strFilter = strFilterDateRange + " and " + strFilterProperty;

        if(typeSchedule != "")
        {
            strFilterProperty = $"singleValueExtendedProperties/Any(ep: ep/id eq '{_Property_TruckleSoft2}' and ep/value eq '{typeSchedule}')";
            strFilter += " and " + strFilterProperty;
        }

        // Select the events (if any) and delete them
        var oEvents = await _graphClient
                                .Me
                                .Calendars[idCalendar]
                                .Events
                                .Request()
                                .Filter(strFilter)
                                .GetAsync();
        if (oEvents?.Count > 0)
        {
            foreach (Event oEvent in oEvents)
            {
                // Delete the event (Do I need to use the specific calendar events list?)
                await _graphClient.Me.Events[oEvent.Id].Request().DeleteAsync();
            }
        }
    }
    catch (Exception ex)
    {
        SimpleLog.Log(ex);
        return false;
    }

    return true;
}

关键是简单地使用and并将两个单独的过滤器拼接在一起。