本文整理汇总了C#中Rock.Model.GroupService.Select方法的典型用法代码示例。如果您正苦于以下问题:C# GroupService.Select方法的具体用法?C# GroupService.Select怎么用?C# GroupService.Select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupService
的用法示例。
在下文中一共展示了GroupService.Select方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindGrid
/// <summary>
/// Binds the grid.
/// </summary>
private void BindGrid()
{
// Find all the Group Types
var groupTypeIds = GetAvailableGroupTypes();
if ( ( GetAttributeValue( "DisplayFilter" ) ?? "false" ).AsBoolean() )
{
int? groupTypeFilter = gfSettings.GetUserPreference( "Group Type" ).AsInteger( false );
if ( groupTypeFilter.HasValue )
{
groupTypeIds = groupTypeIds.Where( g => g == groupTypeFilter.Value ).ToList();
}
}
var rockContext = new RockContext();
SortProperty sortProperty = gGroups.SortProperty;
if ( sortProperty == null )
{
sortProperty = new SortProperty( new GridViewSortEventArgs( "GroupTypeOrder, GroupTypeName, GroupOrder, Name", SortDirection.Ascending ) );
}
bool onlySecurityGroups = GetAttributeValue( "LimittoSecurityRoleGroups" ).AsBoolean();
bool showDescriptionColumn = GetAttributeValue( "DisplayDescriptionColumn" ).AsBoolean();
bool showActiveStatusColumn = GetAttributeValue( "DisplayActiveStatusColumn" ).AsBoolean();
bool showSystemColumn = GetAttributeValue( "DisplaySystemColumn" ).AsBoolean();
if ( !showDescriptionColumn )
{
gGroups.TooltipField = "Description";
}
Dictionary<string, BoundField> boundFields = gGroups.Columns.OfType<BoundField>().ToDictionary( a => a.DataField );
boundFields["GroupTypeName"].Visible = GetAttributeValue( "DisplayGroupTypeColumn" ).AsBoolean();
boundFields["Description"].Visible = showDescriptionColumn;
Dictionary<string, BoolField> boolFields = gGroups.Columns.OfType<BoolField>().ToDictionary( a => a.DataField );
boolFields["IsActive"].Visible = showActiveStatusColumn;
boolFields["IsSystem"].Visible = showSystemColumn;
// Person context will exist if used on a person detail page
var personContext = ContextEntity<Person>();
if ( personContext != null )
{
boundFields["GroupRole"].Visible = true;
boundFields["DateAdded"].Visible = true;
boundFields["MemberCount"].Visible = false;
gGroups.Actions.ShowAdd = false;
gGroups.IsDeleteEnabled = false;
gGroups.Columns.OfType<DeleteField>().ToList().ForEach( f => f.Visible = false );
var qry = new GroupMemberService( rockContext ).Queryable()
.Where( m =>
m.PersonId == personContext.Id &&
groupTypeIds.Contains( m.Group.GroupTypeId ) &&
( !onlySecurityGroups || m.Group.IsSecurityRole ) );
// Filter by active/inactive
if ( ddlActiveFilter.SelectedIndex > -1 )
{
if ( ddlActiveFilter.SelectedValue == "inactive" )
{
qry = qry.Where( a => a.Group.IsActive == false );
}
else if ( ddlActiveFilter.SelectedValue == "active" )
{
qry = qry.Where( a => a.Group.IsActive == true );
}
}
gGroups.DataSource = qry
.Select( m => new
{
Id = m.Group.Id,
Name = m.Group.Name,
GroupTypeName = m.Group.GroupType.Name,
GroupOrder = m.Group.Order,
GroupTypeOrder = m.Group.GroupType.Order,
Description = m.Group.Description,
IsSystem = m.Group.IsSystem,
GroupRole = m.GroupRole.Name,
DateAdded = m.CreatedDateTime,
IsActive = m.Group.IsActive,
MemberCount = 0
} )
.Sort( sortProperty )
.ToList();
}
else
{
bool canEdit = IsUserAuthorized( Authorization.EDIT );
gGroups.Actions.ShowAdd = canEdit;
gGroups.IsDeleteEnabled = canEdit;
boundFields["GroupRole"].Visible = false;
boundFields["DateAdded"].Visible = false;
//.........这里部分代码省略.........
示例2: GetExpression
/// <summary>
/// Gets the expression.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="entityIdProperty">The entity identifier property.</param>
/// <param name="selection">The selection.</param>
/// <returns></returns>
public override System.Linq.Expressions.Expression GetExpression( Data.RockContext context, System.Linq.Expressions.MemberExpression entityIdProperty, string selection )
{
bool showAsLink = this.GetAttributeValueFromSelection( "ShowAsLink", selection ).AsBooleanOrNull() ?? false;
var groupQry = new GroupService( context ).Queryable();
IQueryable<string> groupLinkQry;
string baseGroupUrl = System.Web.VirtualPathUtility.ToAbsolute( "~/Group/" );
if ( showAsLink )
{
// return string in format: <a href='/group/{groupId}'>Name</a>
groupLinkQry = groupQry.Select( p => "<a href='" + baseGroupUrl + p.Id.ToString() + "'>" + p.Name + "</a>" );
}
else
{
groupLinkQry = groupQry.Select( p => p.Name );
}
return SelectExpressionExtractor.Extract( groupLinkQry, entityIdProperty, "p" );
}
示例3: GetNavigationData
private NavigationData GetNavigationData( CampusCache campus )
{
using ( var rockContext = new RockContext() )
{
var validLocationids = new List<int>();
if ( campus.LocationId.HasValue )
{
// Get all the child locations
validLocationids.Add( campus.LocationId.Value );
new LocationService( rockContext )
.GetAllDescendents( campus.LocationId.Value )
.Select( l => l.Id )
.ToList()
.ForEach( l => validLocationids.Add( l ) );
}
var groupTypeTemplateGuid = PageParameter( "Area" ).AsGuidOrNull();
if ( !groupTypeTemplateGuid.HasValue )
{
groupTypeTemplateGuid = this.GetAttributeValue( "GroupTypeTemplate" ).AsGuidOrNull();
}
if ( !groupTypeTemplateGuid.HasValue )
{
// Check to see if a specific group was specified
Guid? guid = Rock.SystemGuid.DefinedValue.GROUPTYPE_PURPOSE_CHECKIN_TEMPLATE.AsGuid();
int? groupId = PageParameter( "Group" ).AsIntegerOrNull();
if ( groupId.HasValue && guid.HasValue )
{
var group = new GroupService( rockContext ).Get( groupId.Value );
if ( group != null && group.GroupType != null )
{
var groupType = GetParentPurposeGroupType( group.GroupType, guid.Value );
if ( groupType != null )
{
groupTypeTemplateGuid = groupType.Guid;
}
}
}
}
if ( groupTypeTemplateGuid.HasValue )
{
pnlContent.Visible = true;
NavData = new NavigationData();
var chartTimes = GetChartTimes();
// Get the group types
var parentGroupType = GroupTypeCache.Read( groupTypeTemplateGuid.Value );
if ( parentGroupType != null )
{
foreach ( var childGroupType in parentGroupType.ChildGroupTypes )
{
AddGroupType( childGroupType, chartTimes );
}
}
// Get the groups
var groupTypeIds = NavData.GroupTypes.Select( t => t.Id ).ToList();
var groups = new GroupService( rockContext )
.Queryable( "GroupLocations" ).AsNoTracking()
.Where( g =>
groupTypeIds.Contains( g.GroupTypeId ) &&
g.IsActive )
.ToList();
var groupIds = groups.Select( g => g.Id ).ToList();
foreach( var group in groups )
{
var childGroupIds = groups
.Where( g =>
g.ParentGroupId.HasValue &&
g.ParentGroupId.Value == group.Id )
.Select( g => g.Id )
.ToList();
var childLocationIds = group.GroupLocations
.Where( l => validLocationids.Contains( l.LocationId ) )
.Select( l => l.LocationId )
.ToList();
if ( childLocationIds.Any() || childGroupIds.Any() )
{
var navGroup = new NavigationGroup( group, chartTimes );
navGroup.ChildLocationIds = childLocationIds;
navGroup.ChildGroupIds = childGroupIds;
NavData.Groups.Add( navGroup );
if ( !group.ParentGroupId.HasValue || groupIds.Contains( group.ParentGroupId.Value ) )
{
NavData.GroupTypes.Where( t => t.Id == group.GroupTypeId ).ToList()
.ForEach( t => t.ChildGroupIds.Add( group.Id ) );
}
}
}
// Remove any groups without child locations
//.........这里部分代码省略.........
示例4: GetExpression
/// <summary>
/// Gets the expression.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="entityIdProperty">The entity identifier property.</param>
/// <param name="selection">The selection.</param>
/// <returns></returns>
public override Expression GetExpression( RockContext context, MemberExpression entityIdProperty, string selection )
{
var qryGroupService = new GroupService( context ).Queryable();
var memberListQuery = qryGroupService.Select( p => p.ParentGroup.Members
.Select( m => new MemberInfo
{
NickName = m.Person.NickName,
LastName = m.Person.LastName,
SuffixValueId = m.Person.SuffixValueId,
PersonId = m.PersonId,
GroupMemberId = m.Id
} ).OrderBy( a => a.LastName ).ThenBy( a => a.NickName ) );
var selectChildrenExpression = SelectExpressionExtractor.Extract( memberListQuery, entityIdProperty, "p" );
return selectChildrenExpression;
}
示例5: BindGrid
/// <summary>
/// Binds the grid.
/// </summary>
private void BindGrid()
{
// Find all the Group Types
var groupTypeIds = GetAvailableGroupTypes();
if ( GetAttributeValue( "DisplayFilter" ).AsBooleanOrNull() ?? false )
{
int? groupTypeFilter = gfSettings.GetUserPreference( "Group Type" ).AsIntegerOrNull();
if ( groupTypeFilter.HasValue )
{
groupTypeIds = groupTypeIds.Where( g => g == groupTypeFilter.Value ).ToList();
}
}
var rockContext = new RockContext();
SortProperty sortProperty = gGroups.SortProperty;
if ( sortProperty == null )
{
sortProperty = new SortProperty( new GridViewSortEventArgs( "GroupTypeOrder, GroupTypeName, GroupOrder, Name", SortDirection.Ascending ) );
}
bool onlySecurityGroups = GetAttributeValue( "LimittoSecurityRoleGroups" ).AsBoolean();
var qryGroups = new GroupService( rockContext ).Queryable().Where( g => groupTypeIds.Contains( g.GroupTypeId ) && ( !onlySecurityGroups || g.IsSecurityRole ) );
string limitToActiveStatus = GetAttributeValue( "LimittoActiveStatus" );
if ( limitToActiveStatus == "all" && gfSettings.Visible )
{
// Filter by active/inactive unless the block settings restrict it
if ( ddlActiveFilter.SelectedIndex > -1 )
{
if ( ddlActiveFilter.SelectedValue == "inactive" )
{
qryGroups = qryGroups.Where( a => a.IsActive == false );
}
else if ( ddlActiveFilter.SelectedValue == "active" )
{
qryGroups = qryGroups.Where( a => a.IsActive == true );
}
}
}
else if ( limitToActiveStatus != "all")
{
// filter by the block settinf for Active Status
if ( limitToActiveStatus == "inactive")
{
qryGroups = qryGroups.Where( a => a.IsActive == false );
}
else if ( limitToActiveStatus == "active" )
{
qryGroups = qryGroups.Where( a => a.IsActive == true );
}
}
// Person context will exist if used on a person detail page
int personEntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id;
if ( ContextTypesRequired.Any( e => e.Id == personEntityTypeId ) )
{
var personContext = ContextEntity<Person>();
if ( personContext != null )
{
// limit to Groups that the person is a member of
var qry = new GroupMemberService( rockContext ).Queryable( true )
.Where( m => m.PersonId == personContext.Id )
.Join( qryGroups, gm => gm.GroupId, g => g.Id, ( gm, g ) => new { Group = g, GroupMember = gm } );
gGroups.DataSource = qry
.Select( m => new
{
Id = m.Group.Id,
Name = m.Group.Name,
GroupTypeName = m.Group.GroupType.Name,
GroupOrder = m.Group.Order,
GroupTypeOrder = m.Group.GroupType.Order,
Description = m.Group.Description,
IsSystem = m.Group.IsSystem,
GroupRole = m.GroupMember.GroupRole.Name,
DateAdded = m.GroupMember.CreatedDateTime,
IsActive = m.Group.IsActive,
MemberCount = 0
} )
.Sort( sortProperty )
.ToList();
}
}
else
{
var roleGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() );
int roleGroupTypeId = roleGroupType != null ? roleGroupType.Id : 0;
bool useRolePrefix = onlySecurityGroups || groupTypeIds.Contains( roleGroupTypeId );
gGroups.DataSource = qryGroups.Select( g => new
{
Id = g.Id,
Name = (( useRolePrefix && g.GroupType.Id != roleGroupTypeId ) ? "GROUP - " : "" ) + g.Name,
//.........这里部分代码省略.........
示例6: GroupFilterFormatSelection
/// <summary>
/// Formats the selection for the InGroupFilter/NotInGroupFilter based on if we are in "Not" mode
/// </summary>
/// <param name="selection">The selection.</param>
/// <param name="not">if set to <c>true</c> [not].</param>
/// <returns></returns>
public virtual string GroupFilterFormatSelection( string selection, bool not )
{
string result = "Group Member";
string[] selectionValues = selection.Split( '|' );
if ( selectionValues.Length >= 2 )
{
var rockContext = new RockContext();
var groupGuids = selectionValues[0].Split( ',' ).AsGuidList();
var groups = new GroupService( rockContext ).GetByGuids( groupGuids );
var groupTypeRoleGuidList = selectionValues[1].Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ).Select( a => a.AsGuid() ).ToList();
var groupTypeRoles = new GroupTypeRoleService( rockContext ).Queryable().Where( a => groupTypeRoleGuidList.Contains( a.Guid ) ).ToList();
SlidingDateRangePicker fakeSlidingDateRangePicker = null;
bool includeChildGroups = false;
bool includeChildGroupsPlusDescendants = false;
bool includeChildGroupsIncludeSelected = 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;
}
if ( selectionValues.Length >= 7 )
{
includeInactiveGroups = selectionValues[6].AsBooleanOrNull() ?? false;
}
if ( selectionValues.Length >= 8 )
{
fakeSlidingDateRangePicker = new SlidingDateRangePicker();
// convert comma delimited to pipe
fakeSlidingDateRangePicker.DelimitedValues = selectionValues[7].Replace( ',', '|' );
}
}
GroupMemberStatus? groupMemberStatus = null;
if ( selectionValues.Length >= 4 )
{
groupMemberStatus = selectionValues[3].ConvertToEnumOrNull<GroupMemberStatus>();
}
if ( groups != null )
{
result = string.Format( not ? "Not in groups: {0}" : "In groups: {0}", groups.Select( a => a.Name ).ToList().AsDelimited( ", ", " or " ) );
if ( includeChildGroups )
{
if ( includeChildGroupsPlusDescendants )
{
result += " or descendant groups";
}
else
{
result += " or child groups";
}
if ( includeInactiveGroups )
{
result += ", including inactive groups";
}
if ( !includeChildGroupsIncludeSelected )
{
result += ", not including selected groups";
}
}
if ( groupTypeRoles.Count() > 0 )
{
result += string.Format( ", with role(s): {0}", groupTypeRoles.Select( a => string.Format( "{0} ({1})", a.Name, a.GroupType.Name ) ).ToList().AsDelimited( "," ) );
}
if ( groupMemberStatus.HasValue )
{
result += string.Format( ", with member status: {0}", groupMemberStatus.ConvertToString() );
}
if ( fakeSlidingDateRangePicker != null )
{
result += string.Format( ", added to group in Date Range: {0}", SlidingDateRangePicker.FormatDelimitedValues( fakeSlidingDateRangePicker.DelimitedValues ) );
}
}
}
return result;
}
示例7: GetExpression
/// <summary>
/// Gets the expression.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="entityIdProperty">The entity identifier property.</param>
/// <param name="selection">The selection.</param>
/// <returns></returns>
public override Expression GetExpression( RockContext context, MemberExpression entityIdProperty, string selection )
{
var qryGroupService = new GroupService( context ).Queryable();
Expression<Func<Rock.Model.GroupMember, bool>> memberWhereGroupType = a => 1 == 1;
Expression<Func<Rock.Model.GroupMember, bool>> memberWhereGroupRoles = a => 1 == 1;
Expression<Func<Rock.Model.GroupMember, bool>> memberWhereStatus = a => 1 == 1;
string[] selectionValues = selection.Split( '|' );
if ( selectionValues.Length >= 3 )
{
GroupMemberService groupMemberService = new GroupMemberService( context );
int? groupTypeId = null;
Guid groupTypeGuid = selectionValues[1].AsGuid();
var groupType = GroupTypeCache.Read( groupTypeGuid );
if ( groupType != null )
{
groupTypeId = groupType.Id;
}
if ( groupTypeId.HasValue )
{
memberWhereGroupType = xx => xx.Group.GroupTypeId == groupTypeId;
}
var groupRoleGuids = selectionValues[2].Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ).Select( n => n.AsGuid() ).ToList();
List<int> groupRoleIds = null;
if ( groupRoleGuids.Count() > 0 )
{
groupRoleIds = new GroupTypeRoleService( context ).Queryable().Where( a => groupRoleGuids.Contains( a.Guid ) ).Select( a => a.Id ).ToList();
memberWhereGroupRoles = xx => groupRoleIds.Contains( xx.GroupRoleId );
}
GroupMemberStatus? groupMemberStatus = selectionValues[3].ConvertToEnumOrNull<GroupMemberStatus>();
if ( groupMemberStatus.HasValue )
{
memberWhereStatus = xx => xx.GroupMemberStatus == groupMemberStatus.Value;
}
}
var memberListQuery = qryGroupService.Select( p => p.Members.AsQueryable()
.Where( memberWhereGroupType )
.Where( memberWhereGroupRoles )
.Where( memberWhereStatus )
.Select( m => new MemberInfo
{
NickName = m.Person.NickName,
LastName = m.Person.LastName,
SuffixValueId = m.Person.SuffixValueId,
PersonId = m.PersonId,
GroupMemberId = m.Id
} ).OrderBy( a => a.LastName ).ThenBy( a => a.NickName ) );
var selectChildrenExpression = SelectExpressionExtractor.Extract( memberListQuery, entityIdProperty, "p" );
return selectChildrenExpression;
}