本文整理汇总了C#中Rock.Model.GroupService.CanDelete方法的典型用法代码示例。如果您正苦于以下问题:C# GroupService.CanDelete方法的具体用法?C# GroupService.CanDelete怎么用?C# GroupService.CanDelete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupService
的用法示例。
在下文中一共展示了GroupService.CanDelete方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: gGroups_Delete
/// <summary>
/// Handles the Delete event of the gGroups control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
protected void gGroups_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
AuthService authService = new AuthService( rockContext );
Group group = groupService.Get( e.RowKeyId );
if ( group != null )
{
if ( !group.IsAuthorized( Authorization.EDIT, this.CurrentPerson ) )
{
mdGridWarning.Show( "You are not authorized to delete this group", ModalAlertType.Information );
return;
}
string errorMessage;
if ( !groupService.CanDelete( group, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
bool isSecurityRoleGroup = group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() );
if ( isSecurityRoleGroup )
{
Rock.Security.Role.Flush( group.Id );
foreach ( var auth in authService.Queryable().Where( a => a.GroupId == group.Id ).ToList() )
{
authService.Delete( auth );
}
}
groupService.Delete( group );
rockContext.SaveChanges();
if ( isSecurityRoleGroup )
{
Rock.Security.Authorization.Flush();
}
}
BindGrid();
}
示例2: btnDelete_Click
/// <summary>
/// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e )
{
int? parentGroupId = null;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
AuthService authService = new AuthService( rockContext );
Group group = groupService.Get( int.Parse( hfGroupId.Value ) );
if ( group != null )
{
if ( !group.IsAuthorized( Authorization.EDIT, this.CurrentPerson ) )
{
mdDeleteWarning.Show( "You are not authorized to delete this group.", ModalAlertType.Information );
return;
}
parentGroupId = group.ParentGroupId;
string errorMessage;
if ( !groupService.CanDelete( group, out errorMessage ) )
{
mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
bool isSecurityRoleGroup = group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() );
if ( isSecurityRoleGroup )
{
Rock.Security.Role.Flush( group.Id );
foreach ( var auth in authService.Queryable().Where( a => a.GroupId == group.Id ).ToList() )
{
authService.Delete( auth );
}
}
groupService.Delete( group );
rockContext.SaveChanges();
if ( isSecurityRoleGroup )
{
Rock.Security.Authorization.Flush();
}
}
// reload page, selecting the deleted group's parent
var qryParams = new Dictionary<string, string>();
if ( parentGroupId != null )
{
qryParams["GroupId"] = parentGroupId.ToString();
}
NavigateToPage( RockPage.Guid, qryParams );
}
示例3: lbMerge_Click
//.........这里部分代码省略.........
// Update the attributes
primaryPerson.LoadAttributes( rockContext );
foreach ( var property in MergeData.Properties.Where( p => p.Key.StartsWith( "attr_" ) ) )
{
string attributeKey = property.Key.Substring( 5 );
string oldValue = primaryPerson.GetAttributeValue( attributeKey ) ?? string.Empty;
string newValue = GetNewStringValue( property.Key, changes ) ?? string.Empty;
if ( !oldValue.Equals( newValue ) )
{
var attribute = primaryPerson.Attributes[attributeKey];
Rock.Attribute.Helper.SaveAttributeValue( primaryPerson, attribute, newValue, rockContext );
}
}
HistoryService.SaveChanges( rockContext, typeof( Person ), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(),
primaryPerson.Id, changes );
// Delete the unselected photos
string photoKeeper = primaryPerson.PhotoId.HasValue ? primaryPerson.PhotoId.Value.ToString() : string.Empty;
foreach ( var photoValue in MergeData.Properties
.Where( p => p.Key == "Photo" )
.SelectMany( p => p.Values )
.Where( v => v.Value != "" && v.Value != photoKeeper )
.Select( v => v.Value ) )
{
int photoId = 0;
if ( int.TryParse( photoValue, out photoId ) )
{
var photo = binaryFileService.Get( photoId );
if ( photo != null )
{
string errorMessages;
if ( binaryFileService.CanDelete( photo, out errorMessages ) )
{
binaryFileService.Delete( photo );
}
}
}
}
rockContext.SaveChanges();
// Delete merged person's family records and any families that would be empty after merge
foreach ( var p in MergeData.People.Where( p => p.Id != primaryPersonId.Value ) )
{
// Delete the merged person's phone numbers (we've already updated the primary persons values)
foreach ( var phoneNumber in phoneNumberService.GetByPersonId( p.Id ) )
{
phoneNumberService.Delete( phoneNumber );
}
// If there was more than one email address and user has logins, then set any of the local
// logins ( database & AD ) to require a reconfirmation
if ( reconfirmRequired )
{
foreach ( var login in userLoginService.GetByPersonId( p.Id ) )
{
var component = Rock.Security.AuthenticationContainer.GetComponent( login.EntityType.Name );
if ( component != null && !component.RequiresRemoteAuthentication )
{
login.IsConfirmed = false;
}
}
}
rockContext.SaveChanges();
示例4: groupEditor_DeleteGroupClick
/// <summary>
/// Handles the DeleteGroupClick event of the groupEditor 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 groupEditor_DeleteGroupClick( object sender, EventArgs e )
{
CheckinGroupEditor groupEditor = sender as CheckinGroupEditor;
GroupService groupService = new GroupService( new RockContext() );
Group groupDB = groupService.Get( groupEditor.GroupGuid );
if ( groupDB != null )
{
string errorMessage;
if ( !groupService.CanDelete( groupDB, out errorMessage ) )
{
nbDeleteWarning.Text = "WARNING - Cannot Delete: " + errorMessage;
nbDeleteWarning.Visible = true;
return;
}
}
groupEditor.Parent.Controls.Remove( groupEditor );
}
示例5: btnDelete_Click
/// <summary>
/// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e )
{
int? parentGroupId = null;
// NOTE: Very similar code in GroupList.gGroups_Delete
RockTransactionScope.WrapTransaction( () =>
{
GroupService groupService = new GroupService();
AuthService authService = new AuthService();
Group group = groupService.Get( int.Parse( hfGroupId.Value ) );
if ( group != null )
{
parentGroupId = group.ParentGroupId;
string errorMessage;
if ( !groupService.CanDelete( group, out errorMessage ) )
{
mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
bool isSecurityRoleGroup = group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() );
if ( isSecurityRoleGroup )
{
Rock.Security.Role.Flush( group.Id );
foreach ( var auth in authService.Queryable().Where( a => a.GroupId.Equals( group.Id ) ).ToList() )
{
authService.Delete( auth, CurrentPersonId );
authService.Save( auth, CurrentPersonId );
}
}
groupService.Delete( group, CurrentPersonId );
groupService.Save( group, CurrentPersonId );
if ( isSecurityRoleGroup )
{
Rock.Security.Authorization.Flush();
}
}
} );
// reload page, selecting the deleted group's parent
var qryParams = new Dictionary<string, string>();
if ( parentGroupId != null )
{
qryParams["groupId"] = parentGroupId.ToString();
}
NavigateToPage( RockPage.Guid, qryParams );
}
示例6: btnDelete_Click
/// <summary>
/// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e )
{
int? parentGroupId = null;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
AuthService authService = new AuthService( rockContext );
Group group = groupService.Get( hfGroupId.Value.AsInteger() );
if ( group != null )
{
if ( !group.IsAuthorized( Authorization.EDIT, this.CurrentPerson ) )
{
mdDeleteWarning.Show( "You are not authorized to delete this group.", ModalAlertType.Information );
return;
}
parentGroupId = group.ParentGroupId;
string errorMessage;
if ( !groupService.CanDelete( group, out errorMessage ) )
{
mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
bool isSecurityRoleGroup = group.IsActive && ( group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() ) );
if ( isSecurityRoleGroup )
{
Rock.Security.Role.Flush( group.Id );
foreach ( var auth in authService.Queryable().Where( a => a.GroupId == group.Id ).ToList() )
{
authService.Delete( auth );
}
}
// If group has a non-named schedule, delete the schedule record.
if ( group.ScheduleId.HasValue )
{
var scheduleService = new ScheduleService( rockContext );
var schedule = scheduleService.Get( group.ScheduleId.Value );
if ( schedule != null && schedule.ScheduleType != ScheduleType.Named )
{
// Make sure this is the only group trying to use this schedule.
if ( !groupService.Queryable().Where( g => g.ScheduleId == schedule.Id && g.Id != group.Id ).Any() )
{
scheduleService.Delete( schedule );
}
}
}
groupService.Delete( group );
rockContext.SaveChanges();
if ( isSecurityRoleGroup )
{
Rock.Security.Authorization.Flush();
}
}
// reload page, selecting the deleted group's parent
var qryParams = new Dictionary<string, string>();
if ( parentGroupId != null )
{
qryParams["GroupId"] = parentGroupId.ToString();
}
qryParams["ExpandedIds"] = PageParameter( "ExpandedIds" );
NavigateToPage( RockPage.Guid, qryParams );
}
示例7: CheckinGroupRow_DeleteGroupClick
private void CheckinGroupRow_DeleteGroupClick( object sender, EventArgs e )
{
var row = sender as CheckinGroupRow;
using ( var rockContext = new RockContext() )
{
var groupService = new GroupService( rockContext );
var group = groupService.Get( row.GroupGuid );
if ( group != null )
{
string errorMessage;
if ( !groupService.CanDelete( group, out errorMessage ) )
{
nbDeleteWarning.Text = "WARNING - Cannot Delete: " + errorMessage;
nbDeleteWarning.Visible = true;
return;
}
groupService.Delete( group );
rockContext.SaveChanges();
Rock.CheckIn.KioskDevice.FlushAll();
SelectGroup( null );
}
}
BuildRows();
}
示例8: gGroups_Delete
/// <summary>
/// Handles the Delete event of the gGroups control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
protected void gGroups_Delete( object sender, RowEventArgs e )
{
// NOTE: Very similar code in GroupDetail.btnDelete_Click
RockTransactionScope.WrapTransaction( () =>
{
GroupService groupService = new GroupService();
AuthService authService = new AuthService();
Group group = groupService.Get( (int)e.RowKeyValue );
if ( group != null )
{
string errorMessage;
if ( !groupService.CanDelete( group, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
bool isSecurityRoleGroup = group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() );
if (isSecurityRoleGroup)
{
Rock.Security.Role.Flush( group.Id );
foreach ( var auth in authService.Queryable().Where( a => a.GroupId == group.Id ).ToList() )
{
authService.Delete( auth, CurrentPersonId );
authService.Save( auth, CurrentPersonId );
}
}
groupService.Delete( group, CurrentPersonId );
groupService.Save( group, CurrentPersonId );
if ( isSecurityRoleGroup )
{
Rock.Security.Authorization.Flush();
}
}
} );
BindGrid();
}