/// <summary> /// Get the data source for the list after applying the specified filter settings. /// </summary> /// <param name="dataContext"></param> /// <param name="filterSettingsKeyValueMap"></param> /// <returns></returns> private void OnPopulateListItems(RockContext dataContext, Grid listControl, Dictionary <string, string> filterSettingsKeyValueMap, SortProperty sortProperty) { if (_exceptionTemplate == null) { return; } string filterDescriptionPrefix = null; filterDescriptionPrefix = _exceptionTemplate.Description; // Construct the query... var exceptionService = new ExceptionLogService(dataContext); // Get the set of exceptions in the filter group. var exceptionQuery = exceptionService.Queryable().AsNoTracking(); exceptionQuery = exceptionService.FilterByOutermost(exceptionQuery); exceptionQuery = exceptionService.FilterByDescriptionPrefix(exceptionQuery, filterDescriptionPrefix); // Filter by: SiteId int siteId = filterSettingsKeyValueMap.GetValueOrDefault(FilterSettingName.Site, string.Empty).AsInteger(); if (siteId != 0) { exceptionQuery = exceptionQuery.Where(e => e.SiteId == siteId); } // Filter by: PageId int pageId = filterSettingsKeyValueMap.GetValueOrDefault(FilterSettingName.Page, string.Empty).AsInteger(); if (pageId != 0) { exceptionQuery = exceptionQuery.Where(e => e.PageId == pageId); } // Filter by: PersonId int userPersonID = filterSettingsKeyValueMap.GetValueOrDefault(FilterSettingName.User, string.Empty).AsInteger(); if (userPersonID != 0) { exceptionQuery = exceptionQuery.Where(e => e.CreatedByPersonAlias != null && e.CreatedByPersonAlias.PersonId == userPersonID); } // Filter by: Date Range var dateRangeSettings = filterSettingsKeyValueMap.GetValueOrDefault(FilterSettingName.DateRange, string.Empty); var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(dateRangeSettings); if (dateRange.Start.HasValue) { exceptionQuery = exceptionQuery.Where(e => e.CreatedDateTime.HasValue && e.CreatedDateTime.Value >= dateRange.Start.Value); } if (dateRange.End.HasValue) { exceptionQuery = exceptionQuery.Where(e => e.CreatedDateTime.HasValue && e.CreatedDateTime.Value < dateRange.End.Value); } // Materialize the list items. var listQuery = exceptionQuery.Select(e => new { Id = e.Id, CreatedDateTime = e.CreatedDateTime, PageName = e.Page.InternalName ?? e.PageUrl, FullName = (e.CreatedByPersonAlias != null && e.CreatedByPersonAlias.Person != null) ? e.CreatedByPersonAlias.Person.LastName + ", " + e.CreatedByPersonAlias.Person.NickName : "", Description = e.Description, }); // Sort the results. if (sortProperty == null) { listQuery = listQuery.OrderByDescending(e => e.CreatedDateTime); } else { listQuery = listQuery.Sort(sortProperty); } // Populate the grid. gExceptionList.SetLinqDataSource(listQuery); gExceptionList.DataBind(); }