本文整理汇总了C#中Rock.Model.GroupService.GetByIds方法的典型用法代码示例。如果您正苦于以下问题:C# GroupService.GetByIds方法的具体用法?C# GroupService.GetByIds怎么用?C# GroupService.GetByIds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupService
的用法示例。
在下文中一共展示了GroupService.GetByIds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: gp_SelectItem
/// <summary>
/// Handles the SelectItem event of the gp control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void gp_SelectItem( object sender, EventArgs e )
{
var rockContext = new RockContext();
var groupIdList = gp.SelectedValues.AsIntegerList();
var groupService = new GroupService( rockContext );
var qryGroups = groupService.GetByIds( groupIdList );
if ( qryGroups.Any() )
{
var groupTypeRoleService = new GroupTypeRoleService( rockContext );
var qryGroupTypeRoles = groupTypeRoleService.Queryable();
List<int> selectedGroupTypeIds = qryGroups.Select( a => a.GroupTypeId ).Distinct().ToList();
if ( cbChildGroups.Checked )
{
List<int> childGroupTypeIds = new List<int>();
foreach ( var groupId in qryGroups.Select( a => a.Id ).ToList() )
{
if ( cbChildGroupsPlusDescendants.Checked )
{
// get all children and descendants of the selected group(s)
var descendants = groupService.GetAllDescendents( groupId );
if ( !cbIncludeInactiveGroups.Checked )
{
descendants = descendants.Where( a => a.IsActive == true );
}
childGroupTypeIds.AddRange( descendants.Select( a => a.GroupTypeId ).Distinct().ToList() );
}
else
{
// get only immediate children of the selected group(s)
var childGroups = groupService.Queryable().Where( a => a.ParentGroupId == groupId );
if ( !cbIncludeInactiveGroups.Checked )
{
childGroups = childGroups.Where( a => a.IsActive == true );
}
childGroupTypeIds.AddRange( childGroups.Select( a => a.GroupTypeId ).Distinct().ToList() );
}
}
childGroupTypeIds = childGroupTypeIds.Distinct().ToList();
if ( cbIncludeSelectedGroup.Checked )
{
qryGroupTypeRoles = qryGroupTypeRoles.Where( a => a.GroupTypeId.HasValue && ( selectedGroupTypeIds.Contains( a.GroupTypeId.Value ) || childGroupTypeIds.Contains( a.GroupTypeId.Value ) ) );
}
else
{
qryGroupTypeRoles = qryGroupTypeRoles.Where( a => a.GroupTypeId.HasValue && childGroupTypeIds.Contains( a.GroupTypeId.Value ) );
}
}
else
{
qryGroupTypeRoles = qryGroupTypeRoles.Where( a => a.GroupTypeId.HasValue && selectedGroupTypeIds.Contains( a.GroupTypeId.Value ) );
}
var list = qryGroupTypeRoles.OrderBy( a => a.GroupType.Order ).ThenBy( a => a.GroupType.Name ).ThenBy( a => a.Order ).ThenBy( a => a.Name ).ToList();
cblRole.Items.Clear();
foreach ( var item in list )
{
cblRole.Items.Add( new ListItem( string.Format( "{0} ({1})", item.Name, item.GroupType.Name ), item.Guid.ToString() ) );
}
cblRole.Visible = list.Count > 0;
}
else
{
cblRole.Visible = false;
}
}
示例2: btnSave_Click
//.........这里部分代码省略.........
if ( !cvGroup.IsValid )
{
cvGroup.ErrorMessage = group.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" );
return;
}
// use WrapTransaction since SaveAttributeValues does it's own RockContext.SaveChanges()
rockContext.WrapTransaction( () =>
{
var adding = group.Id.Equals( 0 );
if ( adding )
{
groupService.Add( group );
}
rockContext.SaveChanges();
if ( adding )
{
// add ADMINISTRATE to the person who added the group
Rock.Security.Authorization.AllowPerson( group, Authorization.ADMINISTRATE, this.CurrentPerson, rockContext );
}
group.SaveAttributeValues( rockContext );
/* Take care of Group Member Attributes */
var entityTypeId = EntityTypeCache.Read( typeof( GroupMember ) ).Id;
string qualifierColumn = "GroupId";
string qualifierValue = group.Id.ToString();
// Get the existing attributes for this entity type and qualifier value
var attributes = attributeService.Get( entityTypeId, qualifierColumn, qualifierValue );
// Delete any of those attributes that were removed in the UI
var selectedAttributeGuids = GroupMemberAttributesState.Select( a => a.Guid );
foreach ( var attr in attributes.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ) )
{
Rock.Web.Cache.AttributeCache.Flush( attr.Id );
attributeService.Delete( attr );
}
// Update the Attributes that were assigned in the UI
foreach ( var attributeState in GroupMemberAttributesState )
{
Rock.Attribute.Helper.SaveAttributeEdits( attributeState, entityTypeId, qualifierColumn, qualifierValue, rockContext );
}
rockContext.SaveChanges();
if ( group.IsActive == false && cbInactivateChildGroups.Checked )
{
var allActiveChildGroupsId = groupService.GetAllDescendents( group.Id ).Where( a => a.IsActive ).Select( a => a.Id ).ToList();
var allActiveChildGroups = groupService.GetByIds( allActiveChildGroupsId );
foreach ( var childGroup in allActiveChildGroups )
{
if ( childGroup.IsActive )
{
childGroup.IsActive = false;
}
}
rockContext.SaveChanges();
}
} );
bool isNowSecurityRole = group.IsActive && ( group.IsSecurityRole || group.GroupTypeId == roleGroupTypeId );
if ( group != null && wasSecurityRole )
{
if ( !isNowSecurityRole )
{
// if this group was a SecurityRole, but no longer is, flush
Rock.Security.Role.Flush( group.Id );
Rock.Security.Authorization.Flush();
}
}
else
{
if ( isNowSecurityRole )
{
// new security role, flush
Rock.Security.Authorization.Flush();
}
}
AttributeCache.FlushEntityAttributes();
if ( triggersUpdated )
{
GroupMemberWorkflowTriggerService.FlushCachedTriggers();
}
var qryParams = new Dictionary<string, string>();
qryParams["GroupId"] = group.Id.ToString();
qryParams["ExpandedIds"] = PageParameter( "ExpandedIds" );
NavigateToPage( RockPage.Guid, qryParams );
}