本文整理汇总了C#中Rock.Model.CategoryService.Save方法的典型用法代码示例。如果您正苦于以下问题:C# CategoryService.Save方法的具体用法?C# CategoryService.Save怎么用?C# CategoryService.Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.CategoryService
的用法示例。
在下文中一共展示了CategoryService.Save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: 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();
}
示例3: 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 categoryService = new CategoryService();
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;
categoryService.Delete( category, CurrentPersonId );
categoryService.Save( category, CurrentPersonId );
// 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 );
}
}
}
示例4: 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 );
}
示例5: MapCommunication
/// <summary>
/// Maps the communication data.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
private void MapCommunication( IQueryable<Row> tableData )
{
var categoryService = new CategoryService();
var personService = new PersonService();
List<DefinedValue> numberTypeValues = new DefinedValueService().Queryable()
.Where( dv => dv.DefinedType.Guid == new Guid( Rock.SystemGuid.DefinedType.PERSON_PHONE_TYPE ) ).ToList();
// Add a Social Media category if it doesn't exist
int attributeEntityTypeId = EntityTypeCache.Read( "Rock.Model.Attribute" ).Id;
int socialMediaCategoryId = categoryService.Queryable().Where( c => c.EntityType.Id == attributeEntityTypeId && c.Name == "Social Media" ).Select( c => c.Id ).FirstOrDefault();
if ( socialMediaCategoryId == 0 )
{
var socialMediaCategory = new Category();
socialMediaCategory.IsSystem = false;
socialMediaCategory.Name = "Social Media";
socialMediaCategory.IconCssClass = "fa fa-twitter";
socialMediaCategory.EntityTypeId = attributeEntityTypeId;
socialMediaCategory.EntityTypeQualifierColumn = "EntityTypeId";
socialMediaCategory.EntityTypeQualifierValue = PersonEntityTypeId.ToString();
socialMediaCategory.Order = 0;
categoryService.Add( socialMediaCategory, ImportPersonAlias );
categoryService.Save( socialMediaCategory, ImportPersonAlias );
socialMediaCategoryId = socialMediaCategory.Id;
}
int visitInfoCategoryId = categoryService.Queryable().Where( c => c.EntityTypeId == attributeEntityTypeId && c.Name == "Visit Information" ).Select( c => c.Id ).FirstOrDefault();
// Look up additional Person attributes (existing)
var personAttributes = new AttributeService().GetByEntityTypeId( PersonEntityTypeId ).ToList();
// Add an Attribute for the secondary email
int secondaryEmailAttributeId = personAttributes.Where( a => a.Key == "SecondaryEmail" ).Select( a => a.Id ).FirstOrDefault();
if ( secondaryEmailAttributeId == 0 )
{
var newSecondaryEmailAttribute = new Rock.Model.Attribute();
newSecondaryEmailAttribute.Key = "SecondaryEmail";
newSecondaryEmailAttribute.Name = "Secondary Email";
newSecondaryEmailAttribute.FieldTypeId = TextFieldTypeId;
newSecondaryEmailAttribute.EntityTypeId = PersonEntityTypeId;
newSecondaryEmailAttribute.EntityTypeQualifierValue = string.Empty;
newSecondaryEmailAttribute.EntityTypeQualifierColumn = string.Empty;
newSecondaryEmailAttribute.Description = "The secondary email for this person";
newSecondaryEmailAttribute.DefaultValue = string.Empty;
newSecondaryEmailAttribute.IsMultiValue = false;
newSecondaryEmailAttribute.IsRequired = false;
newSecondaryEmailAttribute.Order = 0;
using ( new UnitOfWorkScope() )
{
var attributeService = new AttributeService();
attributeService.Add( newSecondaryEmailAttribute );
var visitInfoCategory = new CategoryService().Get( visitInfoCategoryId );
newSecondaryEmailAttribute.Categories.Add( visitInfoCategory );
attributeService.Save( newSecondaryEmailAttribute );
secondaryEmailAttributeId = newSecondaryEmailAttribute.Id;
}
}
// Add an Attribute for Twitter
int twitterAttributeId = personAttributes.Where( a => a.Key == "TwitterUsername" ).Select( a => a.Id ).FirstOrDefault();
if ( twitterAttributeId == 0 )
{
var newTwitterAttribute = new Rock.Model.Attribute();
newTwitterAttribute.Key = "TwitterUsername";
newTwitterAttribute.Name = "Twitter Username";
newTwitterAttribute.FieldTypeId = TextFieldTypeId;
newTwitterAttribute.EntityTypeId = PersonEntityTypeId;
newTwitterAttribute.EntityTypeQualifierValue = string.Empty;
newTwitterAttribute.EntityTypeQualifierColumn = string.Empty;
newTwitterAttribute.Description = "The Twitter username (or link) for this person";
newTwitterAttribute.DefaultValue = string.Empty;
newTwitterAttribute.IsMultiValue = false;
newTwitterAttribute.IsRequired = false;
newTwitterAttribute.Order = 0;
using ( new UnitOfWorkScope() )
{
var attributeService = new AttributeService();
attributeService.Add( newTwitterAttribute );
var socialMediaCategory = new CategoryService().Get( socialMediaCategoryId );
newTwitterAttribute.Categories.Add( socialMediaCategory );
attributeService.Save( newTwitterAttribute );
twitterAttributeId = newTwitterAttribute.Id;
}
}
// Add an Attribute for Facebook
var facebookAttributeId = personAttributes.Where( a => a.Key == "FacebookUsername" ).Select( a => a.Id ).FirstOrDefault();
if ( facebookAttributeId == 0 )
{
var newFacebookAttribute = new Rock.Model.Attribute();
newFacebookAttribute.Key = "FacebookUsername";
newFacebookAttribute.Name = "Facebook Username";
//.........这里部分代码省略.........