本文整理汇总了C#中Rock.Model.CategoryService.Get方法的典型用法代码示例。如果您正苦于以下问题:C# CategoryService.Get方法的具体用法?C# CategoryService.Get怎么用?C# CategoryService.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.CategoryService
的用法示例。
在下文中一共展示了CategoryService.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: gCategories_Delete
/// <summary>
/// Handles the Delete event of the gCategories 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 gCategories_Delete( object sender, RowEventArgs e )
{
var service = new CategoryService();
var category = service.Get( (int)gCategories.DataKeys[e.RowIndex]["id"] );
if ( category != null )
{
string errorMessage = string.Empty;
if ( service.CanDelete( category, out errorMessage ) )
{
service.Delete( category, CurrentPersonId );
service.Save( category, CurrentPersonId );
}
else
{
nbMessage.Text = errorMessage;
nbMessage.Visible = true;
}
}
BindGrid();
}
示例2: mdDetails_SaveClick
/// <summary>
/// Handles the SaveClick event of the modalDetails 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 mdDetails_SaveClick( object sender, EventArgs e )
{
int categoryId = 0;
if ( hfIdValue.Value != string.Empty && !int.TryParse( hfIdValue.Value, out categoryId ) )
{
categoryId = 0;
}
var service = new CategoryService();
Category category = null;
if ( categoryId != 0 )
{
category = service.Get( categoryId );
}
if ( category == null )
{
category = new Category();
category.EntityTypeId = _entityTypeId;
var lastCategory = GetUnorderedCategories()
.OrderByDescending( c => c.Order ).FirstOrDefault();
category.Order = lastCategory != null ? lastCategory.Order + 1 : 0;
service.Add( category, CurrentPersonId );
}
category.Name = tbName.Text;
category.Description = tbDescription.Text;
category.ParentCategoryId = catpParentCategory.SelectedValueAsInt();
category.IconCssClass = tbIconCssClass.Text;
List<int> orphanedBinaryFileIdList = new List<int>();
if ( category.IsValid )
{
RockTransactionScope.WrapTransaction( () =>
{
service.Save( category, CurrentPersonId );
BinaryFileService binaryFileService = new BinaryFileService();
foreach ( int binaryFileId in orphanedBinaryFileIdList )
{
var binaryFile = binaryFileService.Get( binaryFileId );
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
binaryFileService.Save( binaryFile, CurrentPersonId );
}
}
} );
hfIdValue.Value = string.Empty;
mdDetails.Hide();
BindGrid();
}
}
示例3: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e )
{
Category category;
var rockContext = new RockContext();
CategoryService categoryService = new CategoryService( rockContext );
int categoryId = hfCategoryId.ValueAsInt();
if ( categoryId == 0 )
{
category = new Category();
category.IsSystem = false;
category.EntityTypeId = entityTypeId;
category.EntityTypeQualifierColumn = entityTypeQualifierProperty;
category.EntityTypeQualifierValue = entityTypeQualifierValue;
category.Order = 0;
categoryService.Add( category );
}
else
{
category = categoryService.Get( categoryId );
}
category.Name = tbName.Text;
category.ParentCategoryId = cpParentCategory.SelectedValueAsInt();
category.IconCssClass = tbIconCssClass.Text;
category.HighlightColor = tbHighlightColor.Text;
List<int> orphanedBinaryFileIdList = new List<int>();
if ( !Page.IsValid )
{
return;
}
if ( !category.IsValid )
{
// Controls will render the error messages
return;
}
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
foreach ( int binaryFileId in orphanedBinaryFileIdList )
{
var binaryFile = binaryFileService.Get( binaryFileId );
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
}
}
rockContext.SaveChanges();
CategoryCache.Flush( category.Id );
var qryParams = new Dictionary<string, string>();
qryParams["CategoryId"] = category.Id.ToString();
NavigateToPage( RockPage.Guid, qryParams );
}
示例4: ShowDetail
/// <summary>
/// Shows the detail.
/// </summary>
/// <param name="categoryId">The category identifier.</param>
/// <param name="parentCategoryId">The parent category id.</param>
public void ShowDetail( int categoryId, int? parentCategoryId )
{
pnlDetails.Visible = false;
var categoryService = new CategoryService( new RockContext() );
Category category = null;
if ( !categoryId.Equals( 0 ) )
{
category = categoryService.Get( categoryId );
}
if ( category == null )
{
category = new Category { Id = 0, IsSystem = false, ParentCategoryId = parentCategoryId};
// fetch the ParentCategory (if there is one) so that security can check it
category.ParentCategory = categoryService.Get( parentCategoryId ?? 0 );
category.EntityTypeId = entityTypeId;
category.EntityTypeQualifierColumn = entityTypeQualifierProperty;
category.EntityTypeQualifierValue = entityTypeQualifierValue;
}
if (category.EntityTypeId != entityTypeId || !category.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
{
pnlDetails.Visible = false;
return;
}
pnlDetails.Visible = true;
hfCategoryId.Value = category.Id.ToString();
// render UI based on Authorized and IsSystem
bool readOnly = false;
nbEditModeMessage.Text = string.Empty;
// if the person is Authorized to EDIT the category, or has EDIT for the block
var canEdit = category.IsAuthorized( Authorization.EDIT, CurrentPerson ) || this.IsUserAuthorized(Authorization.EDIT);
if ( !canEdit )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Category.FriendlyTypeName );
}
if ( category.IsSystem )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( Category.FriendlyTypeName );
}
btnSecurity.Visible = category.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson );
btnSecurity.Title = category.Name;
btnSecurity.EntityId = category.Id;
if ( readOnly )
{
btnEdit.Visible = false;
btnDelete.Visible = false;
ShowReadonlyDetails( category );
}
else
{
btnEdit.Visible = true;
string errorMessage = string.Empty;
btnDelete.Visible = true;
btnDelete.Enabled = categoryService.CanDelete(category, out errorMessage);
btnDelete.ToolTip = btnDelete.Enabled ? string.Empty : errorMessage;
if ( category.Id > 0 )
{
ShowReadonlyDetails( category );
}
else
{
ShowEditDetails( category );
}
}
if ( btnDelete.Visible && btnDelete.Enabled )
{
btnDelete.Attributes["onclick"] = string.Format( "javascript: return Rock.dialogs.confirmDelete(event, '{0}');", Category.FriendlyTypeName.ToLower() );
}
}
示例5: modalDetails_SaveClick
/// <summary>
/// Handles the SaveClick event of the modalDetails 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 modalDetails_SaveClick( object sender, EventArgs e )
{
int categoryId = 0;
if ( hfIdValue.Value != string.Empty && !int.TryParse( hfIdValue.Value, out categoryId ) )
{
categoryId = 0;
}
var rockContext = new RockContext();
var service = new CategoryService( rockContext );
Category category = null;
if ( categoryId != 0 )
{
CategoryCache.Flush( categoryId );
category = service.Get( categoryId );
}
if ( category == null )
{
category = new Category();
category.EntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.Attribute ) ).Id;
category.EntityTypeQualifierColumn = "EntityTypeId";
var lastCategory = GetUnorderedCategories()
.OrderByDescending( c => c.Order ).FirstOrDefault();
category.Order = lastCategory != null ? lastCategory.Order + 1 : 0;
service.Add( category );
}
category.Name = tbName.Text;
category.Description = tbDescription.Text;
string QualifierValue = null;
if ( ( entityTypePicker.SelectedEntityTypeId ?? 0 ) != 0 )
{
QualifierValue = entityTypePicker.SelectedEntityTypeId.ToString();
}
category.EntityTypeQualifierValue = QualifierValue;
category.IconCssClass = tbIconCssClass.Text;
category.HighlightColor = tbHighlightColor.Text;
List<int> orphanedBinaryFileIdList = new List<int>();
if ( category.IsValid )
{
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
foreach ( int binaryFileId in orphanedBinaryFileIdList )
{
var binaryFile = binaryFileService.Get( binaryFileId );
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
}
}
rockContext.SaveChanges();
hfIdValue.Value = string.Empty;
modalDetails.Hide();
BindGrid();
}
}
示例6: gfFilter_DisplayFilterValue
/// <summary>
/// Handles displaying the stored filter values.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e as DisplayFilterValueArgs (hint: e.Key and e.Value).</param>
protected void gfFilter_DisplayFilterValue( object sender, GridFilter.DisplayFilterValueArgs e )
{
switch ( e.Key )
{
case "Prayer Category":
int categoryId = All.Id;
if ( int.TryParse( e.Value, out categoryId ) )
{
if ( categoryId == All.Id )
{
e.Value = "All";
}
else
{
var service = new CategoryService();
var category = service.Get( categoryId );
if ( category != null )
{
e.Value = category.Name;
}
}
}
break;
}
}
示例7: SaveAttributeEdits
/// <summary>
/// Saves any attribute edits made to an attribute
/// </summary>
/// <param name="newAttribute">The new attribute.</param>
/// <param name="entityTypeId">The entity type identifier.</param>
/// <param name="entityTypeQualifierColumn">The entity type qualifier column.</param>
/// <param name="entityTypeQualifierValue">The entity type qualifier value.</param>
/// <param name="rockContext">The rock context.</param>
/// <returns></returns>
/// <remarks>
/// If a rockContext value is included, this method will save any previous changes made to the context
/// </remarks>
public static Rock.Model.Attribute SaveAttributeEdits( Rock.Model.Attribute newAttribute, int? entityTypeId, string entityTypeQualifierColumn, string entityTypeQualifierValue, RockContext rockContext = null )
{
rockContext = rockContext ?? new RockContext();
var internalAttributeService = new AttributeService( rockContext );
var attributeQualifierService = new AttributeQualifierService( rockContext );
var categoryService = new CategoryService( rockContext );
// If attribute is not valid, return null
if (!newAttribute.IsValid)
{
return null;
}
// Create a attribute model that will be saved
Rock.Model.Attribute attribute = null;
// Check to see if this was an existing or new attribute
if (newAttribute.Id > 0)
{
// If editing an existing attribute, remove all the old qualifiers in case they were changed
foreach ( var oldQualifier in attributeQualifierService.GetByAttributeId( newAttribute.Id ).ToList() )
{
attributeQualifierService.Delete( oldQualifier );
}
rockContext.SaveChanges();
// Then re-load the existing attribute
attribute = internalAttributeService.Get( newAttribute.Id );
}
if ( attribute == null )
{
// If the attribute didn't exist, create it
attribute = new Rock.Model.Attribute();
internalAttributeService.Add( attribute );
}
else
{
// If it did exist, set the new attribute ID and GUID since we're copying all properties in the next step
newAttribute.Id = attribute.Id;
newAttribute.Guid = attribute.Guid;
}
// Copy all the properties from the new attribute to the attribute model
attribute.CopyPropertiesFrom( newAttribute );
// Add any qualifiers
foreach ( var qualifier in newAttribute.AttributeQualifiers )
{
attribute.AttributeQualifiers.Add( new AttributeQualifier { Key = qualifier.Key, Value = qualifier.Value, IsSystem = qualifier.IsSystem } );
}
// Add any categories
attribute.Categories.Clear();
foreach ( var category in newAttribute.Categories )
{
attribute.Categories.Add( categoryService.Get( category.Id ) );
}
attribute.EntityTypeId = entityTypeId;
attribute.EntityTypeQualifierColumn = entityTypeQualifierColumn;
attribute.EntityTypeQualifierValue = entityTypeQualifierValue;
rockContext.SaveChanges();
if ( attribute != null )
{
Rock.Web.Cache.AttributeCache.Flush( attribute.Id );
// If this is a global attribute, flush all global attributes
if ( !entityTypeId.HasValue && entityTypeQualifierColumn == string.Empty && entityTypeQualifierValue == string.Empty )
{
Rock.Web.Cache.GlobalAttributesCache.Flush();
}
}
return attribute;
}
示例8: btnCancel_Click
/// <summary>
/// Handles the Click event of the btnCancel 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 btnCancel_Click( object sender, EventArgs e )
{
if ( hfCategoryId.Value.Equals( "0" ) )
{
int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsIntegerOrNull();
if ( parentCategoryId.HasValue )
{
// Cancelling on Add, and we know the parentCategoryId, so we are probably in treeview mode, so navigate to the current page
var qryParams = new Dictionary<string, string>();
qryParams["CategoryId"] = parentCategoryId.ToString();
NavigateToPage( RockPage.Guid, qryParams );
}
else
{
// Cancelling on Add. Return to Grid
NavigateToParentPage();
}
}
else
{
// Cancelling on Edit. Return to Details
CategoryService service = new CategoryService( new RockContext() );
Category category = service.Get( hfCategoryId.ValueAsInt() );
ShowReadonlyDetails( category );
}
}
示例9: ShowDetail
/// <summary>
/// Shows the detail.
/// </summary>
/// <param name="itemKey">The item key.</param>
/// <param name="itemKeyValue">The item key value.</param>
/// <param name="parentCategoryId">The parent category id.</param>
public void ShowDetail( string itemKey, int itemKeyValue, int? parentCategoryId )
{
pnlDetails.Visible = false;
if ( !itemKey.Equals( "categoryId" ) )
{
return;
}
var categoryService = new CategoryService();
Category category = null;
if ( !itemKeyValue.Equals( 0 ) )
{
category = categoryService.Get( itemKeyValue );
}
else
{
category = new Category { Id = 0, IsSystem = false, ParentCategoryId = parentCategoryId};
category.EntityTypeId = entityTypeId;
category.EntityTypeQualifierColumn = entityTypeQualifierProperty;
category.EntityTypeQualifierValue = entityTypeQualifierValue;
}
if ( category == null || !category.IsAuthorized( "View", CurrentPerson ) )
{
return;
}
pnlDetails.Visible = true;
hfCategoryId.Value = category.Id.ToString();
// render UI based on Authorized and IsSystem
bool readOnly = false;
nbEditModeMessage.Text = string.Empty;
if ( !category.IsAuthorized( "Edit", CurrentPerson ) )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Category.FriendlyTypeName );
}
if ( category.IsSystem )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( Category.FriendlyTypeName );
}
btnSecurity.Visible = category.IsAuthorized( "Administrate", CurrentPerson );
btnSecurity.Title = category.Name;
btnSecurity.EntityId = category.Id;
if ( readOnly )
{
btnEdit.Visible = false;
btnDelete.Visible = false;
ShowReadonlyDetails( category );
}
else
{
btnEdit.Visible = true;
string errorMessage = string.Empty;
btnDelete.Visible = categoryService.CanDelete(category, out errorMessage);
if ( category.Id > 0 )
{
ShowReadonlyDetails( category );
}
else
{
ShowEditDetails( category );
}
}
}
示例10: UpdateAttribute
/// <summary>
/// Adds or Updates a <see cref="Rock.Model.Attribute" /> item for the attribute.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="entityTypeId">The entity type id.</param>
/// <param name="entityQualifierColumn">The entity qualifier column.</param>
/// <param name="entityQualifierValue">The entity qualifier value.</param>
/// <param name="rockContext">The rock context.</param>
/// <returns></returns>
/// <remarks>
/// If a rockContext value is included, this method will save any previous changes made to the context
/// </remarks>
private static bool UpdateAttribute( FieldAttribute property, int? entityTypeId, string entityQualifierColumn, string entityQualifierValue, RockContext rockContext = null )
{
bool updated = false;
rockContext = rockContext ?? new RockContext();
var attributeService = new AttributeService( rockContext );
var attributeQualifierService = new AttributeQualifierService( rockContext );
var fieldTypeService = new FieldTypeService(rockContext);
var categoryService = new CategoryService( rockContext );
var propertyCategories = property.Category.SplitDelimitedValues( false ).ToList();
// Look for an existing attribute record based on the entity, entityQualifierColumn and entityQualifierValue
Model.Attribute attribute = attributeService.Get( entityTypeId, entityQualifierColumn, entityQualifierValue, property.Key );
if ( attribute == null )
{
// If an existing attribute record doesn't exist, create a new one
updated = true;
attribute = new Model.Attribute();
attribute.EntityTypeId = entityTypeId;
attribute.EntityTypeQualifierColumn = entityQualifierColumn;
attribute.EntityTypeQualifierValue = entityQualifierValue;
attribute.Key = property.Key;
attribute.IconCssClass = string.Empty;
attribute.IsGridColumn = false;
}
else
{
// Check to see if the existing attribute record needs to be updated
if ( attribute.Name != property.Name ||
attribute.DefaultValue != property.DefaultValue ||
attribute.Description != property.Description ||
attribute.Order != property.Order ||
attribute.FieldType.Assembly != property.FieldTypeAssembly ||
attribute.FieldType.Class != property.FieldTypeClass ||
attribute.IsRequired != property.IsRequired )
{
updated = true;
}
// Check category
else if ( attribute.Categories.Select( c => c.Name ).Except( propertyCategories ).Any() ||
propertyCategories.Except( attribute.Categories.Select( c => c.Name ) ).Any() )
{
updated = true;
}
// Check the qualifier values
else if ( attribute.AttributeQualifiers.Select( q => q.Key ).Except( property.FieldConfigurationValues.Select( c => c.Key ) ).Any() ||
property.FieldConfigurationValues.Select( c => c.Key ).Except( attribute.AttributeQualifiers.Select( q => q.Key ) ).Any() )
{
updated = true;
}
else
{
foreach ( var attributeQualifier in attribute.AttributeQualifiers )
{
if ( !property.FieldConfigurationValues.ContainsKey( attributeQualifier.Key ) ||
property.FieldConfigurationValues[attributeQualifier.Key].Value != attributeQualifier.Value )
{
updated = true;
break;
}
}
}
}
if ( updated )
{
// Update the attribute
attribute.Name = property.Name;
attribute.Description = property.Description;
attribute.DefaultValue = property.DefaultValue;
attribute.Order = property.Order;
attribute.IsRequired = property.IsRequired;
attribute.Categories.Clear();
if ( propertyCategories.Any() )
{
foreach ( string propertyCategory in propertyCategories )
{
int attributeEntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.Attribute ) ).Id;
var category = categoryService.Get( propertyCategory, attributeEntityTypeId, "EntityTypeId", entityTypeId.ToString() ).FirstOrDefault();
if ( category == null )
{
//.........这里部分代码省略.........
示例11: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e )
{
Category category;
using ( new UnitOfWorkScope() )
{
CategoryService categoryService = new CategoryService();
int categoryId = hfCategoryId.ValueAsInt();
if ( categoryId == 0 )
{
category = new Category();
category.IsSystem = false;
category.EntityTypeId = entityTypeId;
category.EntityTypeQualifierColumn = entityTypeQualifierProperty;
category.EntityTypeQualifierValue = entityTypeQualifierValue;
category.Order = 0;
}
else
{
category = categoryService.Get( categoryId );
}
category.Name = tbName.Text;
category.ParentCategoryId = cpParentCategory.SelectedValueAsInt();
category.IconCssClass = tbIconCssClass.Text;
List<int> orphanedBinaryFileIdList = new List<int>();
if ( !Page.IsValid )
{
return;
}
if ( !category.IsValid )
{
// Controls will render the error messages
return;
}
RockTransactionScope.WrapTransaction( () =>
{
if ( category.Id.Equals( 0 ) )
{
categoryService.Add( category, CurrentPersonId );
}
categoryService.Save( category, CurrentPersonId );
BinaryFileService binaryFileService = new BinaryFileService();
foreach (int binaryFileId in orphanedBinaryFileIdList)
{
var binaryFile = binaryFileService.Get(binaryFileId);
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
binaryFileService.Save( binaryFile, CurrentPersonId );
}
}
} );
}
var qryParams = new Dictionary<string, string>();
qryParams["CategoryId"] = category.Id.ToString();
NavigateToPage( RockPage.Guid, qryParams );
}
示例12: btnCancel_Click
/// <summary>
/// Handles the Click event of the btnCancel 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 btnCancel_Click( object sender, EventArgs e )
{
if ( hfCategoryId.Value.Equals( "0" ) )
{
// Cancelling on Add. Return to tree view with parent category selected
var qryParams = new Dictionary<string, string>();
string parentCategoryId = PageParameter( "parentCategoryId" );
if ( !string.IsNullOrWhiteSpace( parentCategoryId ) )
{
qryParams["CategoryId"] = parentCategoryId;
}
NavigateToPage( RockPage.Guid, qryParams );
}
else
{
// Cancelling on Edit. Return to Details
CategoryService service = new CategoryService();
Category category = service.Get( hfCategoryId.ValueAsInt() );
ShowReadonlyDetails( category );
}
}
示例13: ShowDetail
/// <summary>
/// Shows the detail.
/// </summary>
/// <param name="categoryId">The category identifier.</param>
/// <param name="parentCategoryId">The parent category id.</param>
public void ShowDetail( int categoryId, int? parentCategoryId )
{
pnlDetails.Visible = false;
var categoryService = new CategoryService( new RockContext() );
Category category = null;
if ( !categoryId.Equals( 0 ) )
{
category = categoryService.Get( categoryId );
}
if ( category == null )
{
category = new Category { Id = 0, IsSystem = false, ParentCategoryId = parentCategoryId};
category.EntityTypeId = entityTypeId;
category.EntityTypeQualifierColumn = entityTypeQualifierProperty;
category.EntityTypeQualifierValue = entityTypeQualifierValue;
}
if (category.EntityTypeId != entityTypeId || !category.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
{
pnlDetails.Visible = false;
return;
}
pnlDetails.Visible = true;
hfCategoryId.Value = category.Id.ToString();
// render UI based on Authorized and IsSystem
bool readOnly = false;
nbEditModeMessage.Text = string.Empty;
if ( !category.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Category.FriendlyTypeName );
}
if ( category.IsSystem )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( Category.FriendlyTypeName );
}
btnSecurity.Visible = category.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson );
btnSecurity.Title = category.Name;
btnSecurity.EntityId = category.Id;
if ( readOnly )
{
btnEdit.Visible = false;
btnDelete.Visible = false;
ShowReadonlyDetails( category );
}
else
{
btnEdit.Visible = true;
string errorMessage = string.Empty;
btnDelete.Visible = categoryService.CanDelete(category, out errorMessage);
if ( category.Id > 0 )
{
ShowReadonlyDetails( category );
}
else
{
ShowEditDetails( category );
}
}
}
示例14: 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? parentCategoryId = null;
var rockContext = new RockContext();
var categoryService = new CategoryService( rockContext );
var category = categoryService.Get( int.Parse( hfCategoryId.Value ) );
if ( category != null )
{
string errorMessage;
if ( !categoryService.CanDelete( category, out errorMessage ) )
{
ShowReadonlyDetails( category );
mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
}
else
{
parentCategoryId = category.ParentCategoryId;
CategoryCache.Flush( category.Id );
categoryService.Delete( category );
rockContext.SaveChanges();
// reload page, selecting the deleted category's parent
var qryParams = new Dictionary<string, string>();
if ( parentCategoryId != null )
{
qryParams["CategoryId"] = parentCategoryId.ToString();
}
NavigateToPage( RockPage.Guid, qryParams );
}
}
}
示例15: rGrid_Delete
/// <summary>
/// Handles the Delete event of the rGrid 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 rGrid_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
var service = new CategoryService( rockContext );
var category = service.Get( (int)rGrid.DataKeys[e.RowIndex]["id"] );
if ( category != null )
{
string errorMessage = string.Empty;
if ( service.CanDelete( category, out errorMessage ) )
{
service.Delete( category );
rockContext.SaveChanges();
}
else
{
nbMessage.Text = errorMessage;
nbMessage.Visible = true;
}
}
BindGrid();
}