本文整理汇总了C#中Rock.Model.CategoryService.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CategoryService.Add方法的具体用法?C# CategoryService.Add怎么用?C# CategoryService.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.CategoryService
的用法示例。
在下文中一共展示了CategoryService.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例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: 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: 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 the category IsValid is false, and the UI controls didn't report any errors, it is probably because the custom rules of category didn't pass.
// So, make sure a message is displayed in the validation summary
cvCategory.IsValid = category.IsValid;
if ( !cvCategory.IsValid )
{
cvCategory.ErrorMessage = category.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" );
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 );
}
示例6: 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";
//.........这里部分代码省略.........