本文整理汇总了C#中Rock.Model.GroupTypeService.GetAllAssociatedDescendents方法的典型用法代码示例。如果您正苦于以下问题:C# GroupTypeService.GetAllAssociatedDescendents方法的具体用法?C# GroupTypeService.GetAllAssociatedDescendents怎么用?C# GroupTypeService.GetAllAssociatedDescendents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupTypeService
的用法示例。
在下文中一共展示了GroupTypeService.GetAllAssociatedDescendents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindGrid
/// <summary>
/// Binds the grid.
/// </summary>
protected void BindGrid()
{
AddScheduleColumns();
var rockContext = new RockContext();
var groupLocationService = new GroupLocationService( rockContext );
var groupTypeService = new GroupTypeService( rockContext );
IEnumerable<GroupTypePath> groupPaths = new List<GroupTypePath>();
var groupLocationQry = groupLocationService.Queryable();
int groupTypeId;
// if this page has a PageParam for groupTypeId use that to limit which groupTypeId to see. Otherwise, use the groupTypeId specified in the filter
int? groupTypeIdPageParam = this.PageParameter( "groupTypeId" ).AsIntegerOrNull();
if ( groupTypeIdPageParam.HasValue )
{
groupTypeId = groupTypeIdPageParam ?? Rock.Constants.All.Id;
}
else
{
groupTypeId = ddlGroupType.SelectedValueAsInt() ?? Rock.Constants.All.Id;
}
if ( groupTypeId != Rock.Constants.All.Id )
{
var descendantGroupTypeIds = groupTypeService.GetAllAssociatedDescendents( groupTypeId ).Select( a => a.Id );
// filter to groups that either are of the GroupType or are of a GroupType that has the selected GroupType as a parent (ancestor)
groupLocationQry = groupLocationQry.Where( a => a.Group.GroupType.Id == groupTypeId || descendantGroupTypeIds.Contains( a.Group.GroupTypeId ) );
groupPaths = groupTypeService.GetAllAssociatedDescendentsPath( groupTypeId );
}
else
{
// if no specific GroupType is specified, show all GroupTypes with GroupTypePurpose of Checkin Template and their descendents (since this blocktype is specifically for Checkin)
int groupTypePurposeCheckInTemplateId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.GROUPTYPE_PURPOSE_CHECKIN_TEMPLATE ) ).Id;
List<int> descendantGroupTypeIds = new List<int>();
foreach ( var templateGroupType in groupTypeService.Queryable().Where( a => a.GroupTypePurposeValueId == groupTypePurposeCheckInTemplateId ) )
{
foreach ( var childGroupType in groupTypeService.GetChildGroupTypes( templateGroupType.Id ) )
{
descendantGroupTypeIds.Add( childGroupType.Id );
descendantGroupTypeIds.AddRange( groupTypeService.GetAllAssociatedDescendents( childGroupType.Id ).Select( a => a.Id ).ToList() );
}
}
groupLocationQry = groupLocationQry.Where( a => descendantGroupTypeIds.Contains( a.Group.GroupTypeId ) );
}
if ( gGroupLocationSchedule.SortProperty != null )
{
groupLocationQry = groupLocationQry.Sort( gGroupLocationSchedule.SortProperty );
}
else
{
groupLocationQry = groupLocationQry.OrderBy( a => a.Group.Name ).ThenBy( a => a.Location.Name );
}
var qryList = groupLocationQry.Select( a =>
new
{
GroupLocationId = a.Id,
GroupName = a.Group.Name,
LocationName = a.Location.Name,
ScheduleIdList = a.Schedules.Select( s => s.Id ),
a.LocationId,
GroupTypeId = a.Group.GroupTypeId
} ).ToList();
int parentLocationId = pkrParentLocation.SelectedValueAsInt() ?? Rock.Constants.All.Id;
if ( parentLocationId != Rock.Constants.All.Id )
{
var descendantLocationIds = new LocationService( rockContext ).GetAllDescendents( parentLocationId ).Select( a => a.Id );
qryList = qryList.Where( a => descendantLocationIds.Contains( a.LocationId ) ).ToList();
}
// put stuff in a datatable so we can dynamically have columns for each Schedule
DataTable dataTable = new DataTable();
dataTable.Columns.Add( "GroupLocationId" );
dataTable.Columns.Add( "GroupName" );
dataTable.Columns.Add( "LocationName" );
dataTable.Columns.Add( "Path" );
foreach ( var field in gGroupLocationSchedule.Columns.OfType<CheckBoxEditableField>() )
{
dataTable.Columns.Add( field.DataField, typeof( bool ) );
}
foreach ( var row in qryList )
{
DataRow dataRow = dataTable.NewRow();
dataRow["GroupLocationId"] = row.GroupLocationId;
dataRow["GroupName"] = row.GroupName;
dataRow["LocationName"] = row.LocationName;
dataRow["Path"] = groupPaths.Where( gt => gt.GroupTypeId == row.GroupTypeId ).Select( gt => gt.Path ).FirstOrDefault();
foreach ( var field in gGroupLocationSchedule.Columns.OfType<CheckBoxEditableField>() )
{
int scheduleId = int.Parse( field.DataField.Replace( "scheduleField_", string.Empty ) );
//.........这里部分代码省略.........
示例2: GetExpression
/// <summary>
/// Gets the expression.
/// </summary>
/// <param name="entityType">Type of the entity.</param>
/// <param name="serviceInstance">The service instance.</param>
/// <param name="parameterExpression">The parameter expression.</param>
/// <param name="selection">The selection.</param>
/// <returns></returns>
public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
{
string[] options = selection.Split( '|' );
if ( options.Length < 4 )
{
return null;
}
Guid groupTypeGuid = options[0].AsGuid();
ComparisonType comparisonType = options[1].ConvertToEnum<ComparisonType>( ComparisonType.GreaterThanOrEqualTo );
int? attended = options[2].AsIntegerOrNull();
string slidingDelimitedValues;
if ( options[3].AsIntegerOrNull().HasValue )
{
//// selection was from when it just simply a LastXWeeks instead of Sliding Date Range
// Last X Weeks was treated as "LastXWeeks * 7" days, so we have to convert it to a SlidingDateRange of Days to keep consistent behavior
int lastXWeeks = options[3].AsIntegerOrNull() ?? 1;
var fakeSlidingDateRangePicker = new SlidingDateRangePicker();
fakeSlidingDateRangePicker.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.Last;
fakeSlidingDateRangePicker.TimeUnit = SlidingDateRangePicker.TimeUnitType.Day;
fakeSlidingDateRangePicker.NumberOfTimeUnits = lastXWeeks * 7;
slidingDelimitedValues = fakeSlidingDateRangePicker.DelimitedValues;
}
else
{
slidingDelimitedValues = options[3].Replace( ',', '|' );
}
var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues( slidingDelimitedValues );
bool includeChildGroupTypes = options.Length >= 5 ? options[4].AsBooleanOrNull() ?? false : false;
var groupTypeService = new GroupTypeService( new RockContext() );
var groupType = groupTypeService.Get( groupTypeGuid );
List<int> groupTypeIds = new List<int>();
if ( groupType != null )
{
groupTypeIds.Add( groupType.Id );
if ( includeChildGroupTypes )
{
var childGroupTypes = groupTypeService.GetAllAssociatedDescendents( groupType.Guid );
if ( childGroupTypes.Any() )
{
groupTypeIds.AddRange( childGroupTypes.Select( a => a.Id ) );
// get rid of any duplicates
groupTypeIds = groupTypeIds.Distinct().ToList();
}
}
}
var rockContext = serviceInstance.Context as RockContext;
var attendanceQry = new AttendanceService( rockContext ).Queryable().Where( a => a.DidAttend.HasValue && a.DidAttend.Value );
if ( dateRange.Start.HasValue )
{
var startDate = dateRange.Start.Value;
attendanceQry = attendanceQry.Where( a => a.StartDateTime >= startDate );
}
if ( dateRange.End.HasValue )
{
var endDate = dateRange.End.Value;
attendanceQry = attendanceQry.Where( a => a.StartDateTime < endDate );
}
if ( groupTypeIds.Count == 1 )
{
int groupTypeId = groupTypeIds[0];
attendanceQry = attendanceQry.Where( a => a.Group.GroupTypeId == groupTypeId );
}
else if ( groupTypeIds.Count > 1 )
{
attendanceQry = attendanceQry.Where( a => groupTypeIds.Contains( a.Group.GroupTypeId ) );
}
else
{
// no group type selected, so return nothing
return Expression.Constant( false );
}
var qry = new PersonService( rockContext ).Queryable()
.Where( p => attendanceQry.Where( xx => xx.PersonAlias.PersonId == p.Id ).Count() == attended );
BinaryExpression compareEqualExpression = FilterExpressionExtractor.Extract<Rock.Model.Person>( qry, parameterExpression, "p" ) as BinaryExpression;
BinaryExpression result = FilterExpressionExtractor.AlterComparisonType( comparisonType, compareEqualExpression, null );
return result;
}