本文整理汇总了C#中Rock.Model.DefinedValueService.CanDelete方法的典型用法代码示例。如果您正苦于以下问题:C# DefinedValueService.CanDelete方法的具体用法?C# DefinedValueService.CanDelete怎么用?C# DefinedValueService.CanDelete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.DefinedValueService
的用法示例。
在下文中一共展示了DefinedValueService.CanDelete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: gDefinedType_Delete
/// <summary>
/// Handles the Delete event of the gDefinedType 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 gDefinedType_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
var definedValueService = new DefinedValueService( rockContext );
var definedTypeService = new DefinedTypeService( rockContext );
DefinedType type = definedTypeService.Get( e.RowKeyId );
if ( type != null )
{
string errorMessage;
if ( !definedTypeService.CanDelete( type, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
// if this DefinedType has DefinedValues, see if they can be deleted
var definedValues = definedValueService.GetByDefinedTypeId( type.Id ).ToList();
foreach ( var value in definedValues )
{
if ( !definedValueService.CanDelete( value, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
}
foreach ( var value in definedValues )
{
definedValueService.Delete( value );
}
definedTypeService.Delete( type );
rockContext.SaveChanges();
}
gDefinedType_Bind();
}
示例2: gDefinedValues_Delete
/// <summary>
/// Handles the Delete event of the gDefinedValues 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 gDefinedValues_Delete( object sender, RowEventArgs e )
{
using ( var rockContext = new RockContext() )
{
var definedValueService = new DefinedValueService( rockContext );
var value = definedValueService.Get( e.RowKeyId );
if ( value != null )
{
string errorMessage;
if ( !definedValueService.CanDelete( value, out errorMessage ) )
{
mdGridWarningValues.Show( errorMessage, ModalAlertType.Information );
return;
}
definedValueService.Delete( value );
rockContext.SaveChanges();
DefinedTypeCache.Flush( value.DefinedTypeId );
DefinedValueCache.Flush( value.Id );
}
BindPackageGrid();
}
}
示例3: gDefinedType_Delete
/// <summary>
/// Handles the Delete event of the gDefinedType 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 gDefinedType_Delete( object sender, RowEventArgs e )
{
var definedValueService = new DefinedValueService();
var definedTypeService = new DefinedTypeService();
DefinedType type = definedTypeService.Get( e.RowKeyId );
if ( type != null )
{
string errorMessage;
if ( !definedTypeService.CanDelete( type, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
// if this DefinedType has DefinedValues, see if they can be deleted
var definedValues = definedValueService.GetByDefinedTypeId( type.Id ).ToList();
foreach ( var value in definedValues )
{
if ( !definedValueService.CanDelete( value, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
}
RockTransactionScope.WrapTransaction( () =>
{
foreach ( var value in definedValues )
{
definedValueService.Delete( value, CurrentPersonId );
definedValueService.Save( value, CurrentPersonId );
}
definedTypeService.Delete( type, CurrentPersonId );
definedTypeService.Save( type, CurrentPersonId );
} );
}
gDefinedType_Bind();
}