/// <summary> /// Binds the grid for defined types. /// </summary> private void gDefinedType_Bind() { var queryable = new DefinedTypeService(new RockContext()).Queryable(); if (_categoryGuids.Any()) { queryable = queryable.Where(a => a.Category != null && _categoryGuids.Contains(a.Category.Guid)); } else { int?categoryId = tFilter.GetUserPreference("Category").AsIntegerOrNull(); if (categoryId.HasValue) { queryable = queryable.Where(a => a.CategoryId.HasValue && a.CategoryId.Value == categoryId.Value); } } SortProperty sortProperty = gDefinedType.SortProperty; if (sortProperty != null) { queryable = queryable.Sort(sortProperty); } else { queryable = queryable.OrderBy(a => a.Category.Name).ThenBy(a => a.Name); } gDefinedType.DataSource = queryable .Select(a => new { a.Id, Category = a.Category.Name, a.Name, a.Description, a.IsSystem, FieldTypeName = a.FieldType.Name }) .ToList(); // SanitizeHtml can't be compilied into a SQL query so we have to ToList() the data and then sanitize the field in the List<T> //gDefinedType.DataSource = dataSource // .Select( a => // new // { // a.Id, // a.Category, // a.Name, // Description = a.Description.ScrubHtmlForGridDisplay(), // a.IsSystem, // a.FieldTypeName // } ) // .ToList(); gDefinedType.DataBind(); }
/// <summary> /// Binds the grid for defined types. /// </summary> private void gDefinedType_Bind() { var queryable = new DefinedTypeService(new RockContext()).Queryable(); if (_categoryGuids.Any()) { queryable = queryable.Where(a => a.Category != null && _categoryGuids.Contains(a.Category.Guid)); } else { int?categoryId = tFilter.GetUserPreference("Category").AsIntegerOrNull(); if (categoryId.HasValue) { queryable = queryable.Where(a => a.CategoryId.HasValue && a.CategoryId.Value == categoryId.Value); } } SortProperty sortProperty = gDefinedType.SortProperty; if (sortProperty != null) { queryable = queryable.Sort(sortProperty); } else { queryable = queryable.OrderBy(a => a.Category.Name).ThenBy(a => a.Name); } gDefinedType.DataSource = queryable .Select(a => new { a.Id, Category = a.Category.Name, a.Name, a.Description, a.IsSystem, FieldTypeName = a.FieldType.Name }) .ToList(); gDefinedType.DataBind(); }