本文整理汇总了C#中Rock.Model.GroupService.GetByGuids方法的典型用法代码示例。如果您正苦于以下问题:C# GroupService.GetByGuids方法的具体用法?C# GroupService.GetByGuids怎么用?C# GroupService.GetByGuids使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupService
的用法示例。
在下文中一共展示了GroupService.GetByGuids方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
var groupGuidList = options[0].Split( ',' ).AsGuidList();
ComparisonType comparisonType = options[1].ConvertToEnum<ComparisonType>( ComparisonType.GreaterThanOrEqualTo );
int? attended = options[2].AsIntegerOrNull();
string slidingDelimitedValues = options[3].Replace( ',', '|' );
var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues( slidingDelimitedValues );
bool includeChildGroups = options.Length >= 5 ? options[4].AsBooleanOrNull() ?? false : false;
var groupService = new GroupService( new RockContext() );
var groups = groupService.GetByGuids( groupGuidList );
List<int> groupIds = new List<int>();
foreach ( var group in groups )
{
groupIds.Add( group.Id );
if ( includeChildGroups )
{
var childGroups = groupService.GetAllDescendents( group.Id );
if ( childGroups.Any() )
{
groupIds.AddRange( childGroups.Select( a => a.Id ) );
// get rid of any duplicates
groupIds = groupIds.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 ( groupIds.Count == 1 )
{
int groupId = groupIds[0];
attendanceQry = attendanceQry.Where( a => a.GroupId.HasValue && a.GroupId.Value == groupId );
}
else if ( groupIds.Count > 1 )
{
attendanceQry = attendanceQry.Where( a => a.GroupId.HasValue && groupIds.Contains( a.GroupId.Value ) );
}
else
{
// no groups 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;
}
示例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[] selectionValues = selection.Split( '|' );
if ( selectionValues.Length >= 2 )
{
GroupMemberService groupMemberService = new GroupMemberService( (RockContext)serviceInstance.Context );
List<Guid> groupGuids = selectionValues[0].Split( ',' ).AsGuidList();
var groupService = new GroupService( (RockContext)serviceInstance.Context );
var groupIds = groupService.GetByGuids( groupGuids ).Select( a => a.Id ).Distinct().ToList();
bool includeChildGroups = false;
bool includeChildGroupsIncludeSelected = false;
bool includeChildGroupsPlusDescendants = false;
bool includeInactiveGroups = false;
if ( selectionValues.Length >= 3 )
{
includeChildGroups = selectionValues[2].AsBooleanOrNull() ?? false;
}
if ( selectionValues.Length >= 6 )
{
includeChildGroupsIncludeSelected = selectionValues[4].AsBooleanOrNull() ?? false;
includeChildGroupsPlusDescendants = selectionValues[5].AsBooleanOrNull() ?? false;
}
else if ( includeChildGroups )
{
// in case the selection was saved before these options where added
includeChildGroupsIncludeSelected = true;
includeChildGroupsPlusDescendants = true;
}
if ( selectionValues.Length >= 7 )
{
includeInactiveGroups = selectionValues[6].AsBooleanOrNull() ?? true; ;
}
else
{
// if options where saved before this option was added, set to false, even though it would have included inactive before
includeInactiveGroups = false;
}
GroupMemberStatus? groupMemberStatus = null;
if ( selectionValues.Length >= 4 )
{
groupMemberStatus = selectionValues[3].ConvertToEnumOrNull<GroupMemberStatus>();
}
var groupMemberServiceQry = groupMemberService.Queryable();
if ( includeChildGroups )
{
List<int> childGroupIds = new List<int>();
foreach ( var groupId in groupIds )
{
if ( includeChildGroupsPlusDescendants )
{
// get all children and descendants of the selected group(s)
var descendants = groupService.GetAllDescendents( groupId );
if ( !includeInactiveGroups )
{
descendants = descendants.Where( a => a.IsActive == true );
}
childGroupIds.AddRange( descendants.Select( a => a.Id ).Distinct().ToList() );
}
else
{
// get only immediate children of the selected group(s)
var childGroups = groupService.Queryable().Where( a => a.ParentGroupId == groupId );
if ( !includeInactiveGroups )
{
childGroups = childGroups.Where( a => a.IsActive == true );
}
childGroupIds.AddRange( childGroups.Select( a => a.Id ) );
}
}
if ( includeChildGroupsIncludeSelected )
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => groupIds.Contains( xx.GroupId ) || childGroupIds.Contains( xx.GroupId ) );
}
else
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => childGroupIds.Contains( xx.GroupId ) );
}
}
else
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => groupIds.Contains( xx.GroupId ) );
}
//.........这里部分代码省略.........
示例3: 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[] selectionValues = selection.Split( '|' );
if ( selectionValues.Length >= 2 )
{
GroupMemberService groupMemberService = new GroupMemberService( (RockContext)serviceInstance.Context );
List<Guid> groupGuids = selectionValues[0].Split( ',' ).AsGuidList();
var groupService = new GroupService( (RockContext)serviceInstance.Context );
var groupIds = groupService.GetByGuids( groupGuids ).Select( a => a.Id ).Distinct().ToList();
bool includeChildGroups = false;
bool includeChildGroupsIncludeSelected = false;
bool includeChildGroupsPlusDescendants = false;
if ( selectionValues.Length >= 3 )
{
includeChildGroups = selectionValues[2].AsBooleanOrNull() ?? false;
}
if ( selectionValues.Length >= 6 )
{
includeChildGroupsIncludeSelected = selectionValues[4].AsBooleanOrNull() ?? false;
includeChildGroupsPlusDescendants = selectionValues[5].AsBooleanOrNull() ?? false;
}
else if ( includeChildGroups )
{
// in case the selection was saved before these options where added
includeChildGroupsIncludeSelected = true;
includeChildGroupsPlusDescendants = true;
}
GroupMemberStatus? groupMemberStatus = null;
if ( selectionValues.Length >= 4 )
{
groupMemberStatus = selectionValues[3].ConvertToEnumOrNull<GroupMemberStatus>();
}
var groupMemberServiceQry = groupMemberService.Queryable();
if ( includeChildGroups )
{
List<int> childGroupIds = new List<int>();
foreach ( var groupId in groupIds )
{
if ( includeChildGroupsPlusDescendants )
{
// get all children and descendants of the selected group(s)
childGroupIds.AddRange( groupService.GetAllDescendents( groupId ).Select( a => a.Id ).Distinct().ToList() );
}
else
{
// get only immediate children of the selected group(s)
childGroupIds.AddRange( groupService.Queryable().Where( a => a.ParentGroupId == groupId ).Select( a => a.Id ) );
}
}
if ( includeChildGroupsIncludeSelected )
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => groupIds.Contains( xx.GroupId ) || childGroupIds.Contains( xx.GroupId ) );
}
else
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => childGroupIds.Contains( xx.GroupId ) );
}
}
else
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => groupIds.Contains( xx.GroupId ) );
}
if ( groupMemberStatus.HasValue )
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => xx.GroupMemberStatus == groupMemberStatus.Value );
}
var groupRoleGuids = selectionValues[1].Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ).Select( n => n.AsGuid() ).ToList();
if ( groupRoleGuids.Count() > 0 )
{
groupMemberServiceQry = groupMemberServiceQry.Where( xx => groupRoleGuids.Contains( xx.GroupRole.Guid ) );
}
var qry = new PersonService( (RockContext)serviceInstance.Context ).Queryable()
.Where( p => groupMemberServiceQry.Any( xx => xx.PersonId == p.Id ) );
Expression extractedFilterExpression = FilterExpressionExtractor.Extract<Rock.Model.Person>( qry, parameterExpression, "p" );
return extractedFilterExpression;
}
return null;
}