本文整理汇总了C#中Rock.Model.AttributeService.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeService.Delete方法的具体用法?C# AttributeService.Delete怎么用?C# AttributeService.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.AttributeService
的用法示例。
在下文中一共展示了AttributeService.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 )
{
bool hasValidationErrors = false;
var rockContext = new RockContext();
GroupTypeService groupTypeService = new GroupTypeService( rockContext );
GroupService groupService = new GroupService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
int parentGroupTypeId = hfParentGroupTypeId.ValueAsInt();
var groupTypeUIList = new List<GroupType>();
foreach ( var checkinGroupTypeEditor in phCheckinGroupTypes.Controls.OfType<CheckinGroupTypeEditor>().ToList() )
{
var groupType = checkinGroupTypeEditor.GetCheckinGroupType( rockContext );
groupTypeUIList.Add( groupType );
}
var groupTypeDBList = new List<GroupType>();
var groupTypesToDelete = new List<GroupType>();
var groupsToDelete = new List<Group>();
var groupTypesToAddUpdate = new List<GroupType>();
var groupsToAddUpdate = new List<Group>();
GroupType parentGroupTypeDB = groupTypeService.Get( parentGroupTypeId );
GroupType parentGroupTypeUI = parentGroupTypeDB.Clone( false );
parentGroupTypeUI.ChildGroupTypes = groupTypeUIList;
PopulateDeleteLists( groupTypesToDelete, groupsToDelete, parentGroupTypeDB, parentGroupTypeUI );
PopulateAddUpdateLists( groupTypesToAddUpdate, groupsToAddUpdate, parentGroupTypeUI );
int binaryFileFieldTypeID = FieldTypeCache.Read( Rock.SystemGuid.FieldType.BINARY_FILE.AsGuid() ).Id;
rockContext.WrapTransaction( () =>
{
// delete in reverse order to get deepest child items first
groupsToDelete.Reverse();
foreach ( var groupToDelete in groupsToDelete )
{
groupService.Delete( groupToDelete );
}
// delete in reverse order to get deepest child items first
groupTypesToDelete.Reverse();
foreach ( var groupTypeToDelete in groupTypesToDelete )
{
groupTypeService.Delete( groupTypeToDelete );
}
rockContext.SaveChanges();
// Add/Update grouptypes and groups that are in the UI
// Note: We'll have to save all the groupTypes without changing the DB value of ChildGroupTypes, then come around again and save the ChildGroupTypes
// since the ChildGroupTypes may not exist in the database yet
foreach ( GroupType groupTypeUI in groupTypesToAddUpdate )
{
GroupType groupTypeDB = groupTypeService.Get( groupTypeUI.Guid );
if ( groupTypeDB == null )
{
groupTypeDB = new GroupType();
groupTypeDB.Id = 0;
groupTypeDB.Guid = groupTypeUI.Guid;
groupTypeDB.IsSystem = false;
groupTypeDB.ShowInNavigation = false;
groupTypeDB.ShowInGroupList = false;
groupTypeDB.TakesAttendance = true;
groupTypeDB.AttendanceRule = AttendanceRule.None;
groupTypeDB.AttendancePrintTo = PrintTo.Default;
groupTypeDB.AllowMultipleLocations = true;
groupTypeDB.EnableLocationSchedules = true;
}
groupTypeDB.Name = groupTypeUI.Name;
groupTypeDB.Order = groupTypeUI.Order;
groupTypeDB.InheritedGroupTypeId = groupTypeUI.InheritedGroupTypeId;
groupTypeDB.Attributes = groupTypeUI.Attributes;
groupTypeDB.AttributeValues = groupTypeUI.AttributeValues;
if ( groupTypeDB.Id == 0 )
{
groupTypeService.Add( groupTypeDB );
}
if ( !groupTypeDB.IsValid )
{
hasValidationErrors = true;
CheckinGroupTypeEditor groupTypeEditor = phCheckinGroupTypes.ControlsOfTypeRecursive<CheckinGroupTypeEditor>().First( a => a.GroupTypeGuid == groupTypeDB.Guid );
groupTypeEditor.Expanded = true;
//.........这里部分代码省略.........
示例2: SaveAttributes
/// <summary>
/// Saves the attributes.
/// </summary>
/// <param name="entityTypeId">The entity type identifier.</param>
/// <param name="qualifierColumn">The qualifier column.</param>
/// <param name="qualifierValue">The qualifier value.</param>
/// <param name="viewStateAttributes">The view state attributes.</param>
/// <param name="attributeService">The attribute service.</param>
/// <param name="qualifierService">The qualifier service.</param>
/// <param name="categoryService">The category service.</param>
private void SaveAttributes( int entityTypeId, string qualifierColumn, string qualifierValue, List<Attribute> viewStateAttributes, RockContext rockContext )
{
// Get the existing attributes for this entity type and qualifier value
var attributeService = new AttributeService( rockContext );
var regFieldService = new RegistrationTemplateFormFieldService( rockContext );
var attributes = attributeService.Get( entityTypeId, qualifierColumn, qualifierValue );
// Delete any of those attributes that were removed in the UI
var selectedAttributeGuids = viewStateAttributes.Select( a => a.Guid );
foreach ( var attr in attributes.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ) )
{
foreach( var field in regFieldService.Queryable().Where( f => f.AttributeId.HasValue && f.AttributeId.Value == attr.Id ).ToList() )
{
regFieldService.Delete( field );
}
attributeService.Delete( attr );
rockContext.SaveChanges();
Rock.Web.Cache.AttributeCache.Flush( attr.Id );
}
// Update the Attributes that were assigned in the UI
foreach ( var attributeState in viewStateAttributes )
{
Helper.SaveAttributeEdits( attributeState, entityTypeId, qualifierColumn, qualifierValue, rockContext );
}
}
示例3: SaveAttributes
/// <summary>
/// Saves the attributes.
/// </summary>
/// <param name="contentTypeId">The content type identifier.</param>
/// <param name="entityTypeId">The entity type identifier.</param>
/// <param name="attributes">The attributes.</param>
/// <param name="rockContext">The rock context.</param>
private void SaveAttributes( int contentTypeId, int entityTypeId, List<Attribute> attributes, RockContext rockContext )
{
string qualifierColumn = "ContentChannelTypeId";
string qualifierValue = contentTypeId.ToString();
AttributeService attributeService = new AttributeService( rockContext );
// Get the existing attributes for this entity type and qualifier value
var existingAttributes = attributeService.Get( entityTypeId, qualifierColumn, qualifierValue );
// Delete any of those attributes that were removed in the UI
var selectedAttributeGuids = attributes.Select( a => a.Guid );
foreach ( var attr in existingAttributes.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ) )
{
Rock.Web.Cache.AttributeCache.Flush( attr.Id );
attributeService.Delete( attr );
}
rockContext.SaveChanges();
// Update the Attributes that were assigned in the UI
foreach ( var attr in attributes )
{
Rock.Attribute.Helper.SaveAttributeEdits( attr, entityTypeId, qualifierColumn, qualifierValue, rockContext );
}
AttributeCache.FlushEntityAttributes();
}
示例4: SaveAttributes
private void SaveAttributes( int entityTypeId, string qualifierColumn, string qualifierValue, ViewStateList<Attribute> viewStateAttributes, RockContext rockContext )
{
// Get the existing attributes for this entity type and qualifier value
var attributeService = new AttributeService( rockContext );
var attributes = attributeService.Get( entityTypeId, qualifierColumn, qualifierValue );
// Delete any of those attributes that were removed in the UI
var selectedAttributeGuids = viewStateAttributes.Select( a => a.Guid );
foreach ( var attr in attributes.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ) )
{
attributeService.Delete( attr );
rockContext.SaveChanges();
Rock.Web.Cache.AttributeCache.Flush( attr.Id );
}
// Update the Attributes that were assigned in the UI
foreach ( var attributeState in viewStateAttributes )
{
Helper.SaveAttributeEdits( attributeState, entityTypeId, qualifierColumn, qualifierValue, rockContext );
}
}
示例5: MapCommunication
/// <summary>
/// Maps the communication data.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
private void MapCommunication( IQueryable<Row> tableData )
{
var lookupContext = new RockContext();
var personService = new PersonService( lookupContext );
var attributeService = new AttributeService( lookupContext );
var numberTypeValues = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_PHONE_TYPE ), lookupContext ).DefinedValues;
// Look up additional Person attributes (existing)
var personAttributes = attributeService.GetByEntityTypeId( PersonEntityTypeId ).ToList();
// Remove previously defined Excavator social attributes & categories if they exist
var oldFacebookAttribute = personAttributes.Where( a => a.Key == "FacebookUsername" ).FirstOrDefault();
if ( oldFacebookAttribute != null )
{
Rock.Web.Cache.AttributeCache.Flush( oldFacebookAttribute.Id );
attributeService.Delete( oldFacebookAttribute );
lookupContext.SaveChanges( true );
}
var oldTwitterAttribute = personAttributes.Where( a => a.Key == "TwitterUsername" ).FirstOrDefault();
if ( oldTwitterAttribute != null )
{
Rock.Web.Cache.AttributeCache.Flush( oldTwitterAttribute.Id );
attributeService.Delete( oldTwitterAttribute );
lookupContext.SaveChanges( true );
}
int attributeEntityTypeId = EntityTypeCache.Read( "Rock.Model.Attribute" ).Id;
var socialMediaCategory = new CategoryService( lookupContext ).GetByEntityTypeId( attributeEntityTypeId )
.Where( c => c.Name == "Social Media" &&
c.EntityTypeQualifierValue == PersonEntityTypeId.ToString() &&
c.IconCssClass == "fa fa-twitter" )
.FirstOrDefault();
if ( socialMediaCategory != null )
{
lookupContext.Categories.Remove( socialMediaCategory );
lookupContext.SaveChanges( true );
}
// Cached Rock attributes: Facebook, Twitter, Instagram
var twitterAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Twitter" ) );
var facebookAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Facebook" ) );
var instagramAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Instagram" ) );
var secondaryEmailAttribute = AttributeCache.Read( SecondaryEmailAttributeId );
var existingNumbers = new PhoneNumberService( lookupContext ).Queryable().ToList();
var newNumberList = new List<PhoneNumber>();
var updatedPersonList = new List<Person>();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying communication import ({0:N0} found, {1:N0} already exist).", totalRows, existingNumbers.Count() ) );
foreach ( var row in tableData )
{
string value = row["Communication_Value"] as string;
int? individualId = row["Individual_ID"] as int?;
int? householdId = row["Household_ID"] as int?;
var personList = new List<int?>();
if ( individualId != null )
{
int? personId = GetPersonAliasId( individualId, householdId );
if ( personId != null )
{
personList.Add( personId );
}
}
else
{
List<int?> personIds = GetFamilyByHouseholdId( householdId );
if ( personIds.Any() )
{
personList.AddRange( personIds );
}
}
if ( personList.Any() && !string.IsNullOrWhiteSpace( value ) )
{
DateTime? lastUpdated = row["LastUpdatedDate"] as DateTime?;
string communicationComment = row["Communication_Comment"] as string;
string type = row["Communication_Type"] as string;
bool isListed = (bool)row["Listed"];
value = value.RemoveWhitespace();
// Communication value is a number
if ( type.Contains( "Phone" ) || type.Contains( "Mobile" ) )
{
var extension = string.Empty;
var countryCode = Rock.Model.PhoneNumber.DefaultCountryCode();
var normalizedNumber = string.Empty;
var countryIndex = value.IndexOf( '+' );
//.........这里部分代码省略.........
示例6: 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 )
{
var rockContext = new RockContext();
MarketingCampaignAdType marketingCampaignAdType;
MarketingCampaignAdTypeService marketingCampaignAdTypeService = new MarketingCampaignAdTypeService( rockContext );
int marketingCampaignAdTypeId = int.Parse( hfMarketingCampaignAdTypeId.Value );
if ( marketingCampaignAdTypeId == 0 )
{
marketingCampaignAdType = new MarketingCampaignAdType();
marketingCampaignAdTypeService.Add( marketingCampaignAdType );
}
else
{
marketingCampaignAdType = marketingCampaignAdTypeService.Get( marketingCampaignAdTypeId );
}
marketingCampaignAdType.Name = tbName.Text;
marketingCampaignAdType.DateRangeType = (DateRangeTypeEnum)int.Parse( ddlDateRangeType.SelectedValue );
if ( !marketingCampaignAdType.IsValid )
{
// Controls will render the error messages
return;
}
RockTransactionScope.WrapTransaction( () =>
{
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
CategoryService categoryService = new CategoryService( rockContext );
rockContext.SaveChanges();
// get it back to make sure we have a good Id for it for the Attributes
marketingCampaignAdType = marketingCampaignAdTypeService.Get( marketingCampaignAdType.Guid );
var entityTypeId = EntityTypeCache.Read( typeof( MarketingCampaignAd ) ).Id;
string qualifierColumn = "MarketingCampaignAdTypeId";
string qualifierValue = marketingCampaignAdType.Id.ToString();
// Get the existing attributes for this entity type and qualifier value
var attributes = attributeService.Get( entityTypeId, qualifierColumn, qualifierValue );
// Delete any of those attributes that were removed in the UI
var selectedAttributeGuids = AttributesState.Select( a => a.Guid );
foreach ( var attr in attributes.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ) )
{
Rock.Web.Cache.AttributeCache.Flush( attr.Id );
attributeService.Delete( attr );
}
rockContext.SaveChanges();
// Update the Attributes that were assigned in the UI
foreach ( var attributeState in AttributesState )
{
Rock.Attribute.Helper.SaveAttributeEdits( attributeState, entityTypeId, qualifierColumn, qualifierValue, rockContext );
}
} );
NavigateToParentPage();
}
示例7: 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 )
{
BinaryFileType binaryFileType;
var rockContext = new RockContext();
BinaryFileTypeService binaryFileTypeService = new BinaryFileTypeService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
CategoryService categoryService = new CategoryService( rockContext );
int binaryFileTypeId = int.Parse( hfBinaryFileTypeId.Value );
if ( binaryFileTypeId == 0 )
{
binaryFileType = new BinaryFileType();
binaryFileTypeService.Add( binaryFileType );
}
else
{
binaryFileType = binaryFileTypeService.Get( binaryFileTypeId );
}
binaryFileType.Name = tbName.Text;
binaryFileType.Description = tbDescription.Text;
binaryFileType.IconCssClass = tbIconCssClass.Text;
binaryFileType.AllowCaching = cbAllowCaching.Checked;
binaryFileType.RequiresViewSecurity = cbRequiresViewSecurity.Checked;
binaryFileType.MaxWidth = nbMaxWidth.Text.AsInteger();
binaryFileType.MaxHeight = nbMaxHeight.Text.AsInteger();
binaryFileType.PreferredFormat = ddlPreferredFormat.SelectedValueAsEnum<Format>();
binaryFileType.PreferredResolution = ddlPreferredResolution.SelectedValueAsEnum<Resolution>();
binaryFileType.PreferredColorDepth = ddlPreferredColorDepth.SelectedValueAsEnum<ColorDepth>();
binaryFileType.PreferredRequired = cbPreferredRequired.Checked;
if ( !string.IsNullOrWhiteSpace( cpStorageType.SelectedValue ) )
{
var entityTypeService = new EntityTypeService( rockContext );
var storageEntityType = entityTypeService.Get( new Guid( cpStorageType.SelectedValue ) );
if ( storageEntityType != null )
{
binaryFileType.StorageEntityTypeId = storageEntityType.Id;
}
}
binaryFileType.LoadAttributes( rockContext );
Rock.Attribute.Helper.GetEditValues( phAttributes, binaryFileType );
if ( !binaryFileType.IsValid )
{
// Controls will render the error messages
return;
}
rockContext.WrapTransaction( () =>
{
rockContext.SaveChanges();
// get it back to make sure we have a good Id for it for the Attributes
binaryFileType = binaryFileTypeService.Get( binaryFileType.Guid );
/* Take care of Binary File Attributes */
var entityTypeId = Rock.Web.Cache.EntityTypeCache.Read( typeof( BinaryFile ) ).Id;
// delete BinaryFileAttributes that are no longer configured in the UI
var attributes = attributeService.Get( entityTypeId, "BinaryFileTypeId", binaryFileType.Id.ToString() );
var selectedAttributeGuids = BinaryFileAttributesState.Select( a => a.Guid );
foreach ( var attr in attributes.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ) )
{
Rock.Web.Cache.AttributeCache.Flush( attr.Id );
attributeService.Delete( attr );
}
rockContext.SaveChanges();
// add/update the BinaryFileAttributes that are assigned in the UI
foreach ( var attributeState in BinaryFileAttributesState )
{
Rock.Attribute.Helper.SaveAttributeEdits( attributeState, entityTypeId, "BinaryFileTypeId", binaryFileType.Id.ToString(), rockContext );
}
// SaveAttributeValues for the BinaryFileType
binaryFileType.SaveAttributeValues( rockContext );
} );
AttributeCache.FlushEntityAttributes();
NavigateToParentPage();
}
示例8: SaveAttributes
private void SaveAttributes( int entityTypeId, string qualifierColumn, string qualifierValue, ViewStateList<Attribute> viewStateAttributes,
AttributeService attributeService, AttributeQualifierService qualifierService, CategoryService categoryService )
{
// Get the existing attributes for this entity type and qualifier value
var attributes = attributeService.Get( entityTypeId, qualifierColumn, qualifierValue );
// Delete any of those attributes that were removed in the UI
var selectedAttributeGuids = viewStateAttributes.Select( a => a.Guid );
foreach ( var attr in attributes.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ) )
{
Rock.Web.Cache.AttributeCache.Flush( attr.Id );
attributeService.Delete( attr, CurrentPersonId );
attributeService.Save( attr, CurrentPersonId );
}
// Update the Attributes that were assigned in the UI
foreach ( var attributeState in viewStateAttributes )
{
Helper.SaveAttributeEdits( attributeState, attributeService, qualifierService, categoryService,
entityTypeId, qualifierColumn, qualifierValue, CurrentPersonId );
}
}
示例9: btnSave_Click
protected void btnSave_Click( object sender, EventArgs e )
{
hfAreaGroupClicked.Value = "true";
using ( var rockContext = new RockContext() )
{
var attributeService = new AttributeService( rockContext );
if ( checkinArea.Visible )
{
var groupTypeService = new GroupTypeService( rockContext );
var groupType = groupTypeService.Get( checkinArea.GroupTypeGuid );
if ( groupType != null )
{
checkinArea.GetGroupTypeValues( groupType );
if ( groupType.IsValid )
{
rockContext.SaveChanges();
groupType.SaveAttributeValues( rockContext );
bool AttributesUpdated = false;
// rebuild the CheckinLabel attributes from the UI (brute-force)
foreach ( var labelAttribute in CheckinArea.GetCheckinLabelAttributes( groupType.Attributes ) )
{
var attribute = attributeService.Get( labelAttribute.Value.Guid );
Rock.Web.Cache.AttributeCache.Flush( attribute.Id );
attributeService.Delete( attribute );
AttributesUpdated = true;
}
// Make sure default role is set
if ( !groupType.DefaultGroupRoleId.HasValue && groupType.Roles.Any() )
{
groupType.DefaultGroupRoleId = groupType.Roles.First().Id;
}
rockContext.SaveChanges();
int labelOrder = 0;
int binaryFileFieldTypeID = FieldTypeCache.Read( Rock.SystemGuid.FieldType.BINARY_FILE.AsGuid() ).Id;
foreach ( var checkinLabelAttributeInfo in checkinArea.CheckinLabels )
{
var attribute = new Rock.Model.Attribute();
attribute.AttributeQualifiers.Add( new AttributeQualifier { Key = "binaryFileType", Value = Rock.SystemGuid.BinaryFiletype.CHECKIN_LABEL } );
attribute.Guid = Guid.NewGuid();
attribute.FieldTypeId = binaryFileFieldTypeID;
attribute.EntityTypeId = EntityTypeCache.GetId( typeof( GroupType ) );
attribute.EntityTypeQualifierColumn = "Id";
attribute.EntityTypeQualifierValue = groupType.Id.ToString();
attribute.DefaultValue = checkinLabelAttributeInfo.BinaryFileGuid.ToString();
attribute.Key = checkinLabelAttributeInfo.AttributeKey;
attribute.Name = checkinLabelAttributeInfo.FileName;
attribute.Order = labelOrder++;
if ( !attribute.IsValid )
{
return;
}
attributeService.Add( attribute );
AttributesUpdated = true;
}
rockContext.SaveChanges();
GroupTypeCache.Flush( groupType.Id );
Rock.CheckIn.KioskDevice.FlushAll();
if ( AttributesUpdated )
{
AttributeCache.FlushEntityAttributes();
}
nbSaveSuccess.Visible = true;
BuildRows();
}
else
{
ShowInvalidResults( groupType.ValidationResults );
}
}
}
if ( checkinGroup.Visible )
{
var groupService = new GroupService( rockContext );
var groupLocationService = new GroupLocationService( rockContext );
var group = groupService.Get( checkinGroup.GroupGuid );
if ( group != null )
{
group.LoadAttributes( rockContext );
checkinGroup.GetGroupValues( group );
// populate groupLocations with whatever is currently in the grid, with just enough info to repopulate it and save it later
var newLocationIds = checkinGroup.Locations.Select( l => l.LocationId ).ToList();
foreach ( var groupLocation in group.GroupLocations.Where( l => !newLocationIds.Contains( l.LocationId ) ).ToList() )
//.........这里部分代码省略.........
示例10: 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 )
{
Group group;
bool wasSecurityRole = false;
bool triggersUpdated = false;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
GroupRequirementService groupRequirementService = new GroupRequirementService( rockContext );
GroupMemberWorkflowTriggerService groupMemberWorkflowTriggerService = new GroupMemberWorkflowTriggerService( rockContext );
ScheduleService scheduleService = new ScheduleService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
CategoryService categoryService = new CategoryService( rockContext );
var roleGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() );
int roleGroupTypeId = roleGroupType != null ? roleGroupType.Id : int.MinValue;
if ( CurrentGroupTypeId == 0 )
{
ddlGroupType.ShowErrorMessage( Rock.Constants.WarningMessage.CannotBeBlank( GroupType.FriendlyTypeName ) );
return;
}
int groupId = hfGroupId.Value.AsInteger();
if ( groupId == 0 )
{
group = new Group();
group.IsSystem = false;
group.Name = string.Empty;
}
else
{
group = groupService.Queryable( "Schedule,GroupLocations.Schedules" ).Where( g => g.Id == groupId ).FirstOrDefault();
wasSecurityRole = group.IsActive && ( group.IsSecurityRole || group.GroupTypeId == roleGroupTypeId );
// remove any locations that removed in the UI
var selectedLocations = GroupLocationsState.Select( l => l.Guid );
foreach ( var groupLocation in group.GroupLocations.Where( l => !selectedLocations.Contains( l.Guid ) ).ToList() )
{
group.GroupLocations.Remove( groupLocation );
groupLocationService.Delete( groupLocation );
}
// remove any group requirements that removed in the UI
var selectedGroupRequirements = GroupRequirementsState.Select( a => a.Guid );
foreach ( var groupRequirement in group.GroupRequirements.Where( a => !selectedGroupRequirements.Contains( a.Guid ) ).ToList() )
{
group.GroupRequirements.Remove( groupRequirement );
groupRequirementService.Delete( groupRequirement );
}
// Remove any triggers that were removed in the UI
var selectedTriggerGuids = MemberWorkflowTriggersState.Select( r => r.Guid );
foreach ( var trigger in group.GroupMemberWorkflowTriggers.Where( r => !selectedTriggerGuids.Contains( r.Guid ) ).ToList() )
{
group.GroupMemberWorkflowTriggers.Remove( trigger );
groupMemberWorkflowTriggerService.Delete( trigger );
triggersUpdated = true;
}
}
// add/update any group requirements that were added or changed in the UI (we already removed the ones that were removed above)
foreach ( var groupRequirementState in GroupRequirementsState )
{
GroupRequirement groupRequirement = group.GroupRequirements.Where( a => a.Guid == groupRequirementState.Guid ).FirstOrDefault();
if ( groupRequirement == null )
{
groupRequirement = new GroupRequirement();
group.GroupRequirements.Add( groupRequirement );
}
groupRequirement.CopyPropertiesFrom( groupRequirementState );
}
// add/update any group locations that were added or changed in the UI (we already removed the ones that were removed above)
foreach ( var groupLocationState in GroupLocationsState )
{
GroupLocation groupLocation = group.GroupLocations.Where( l => l.Guid == groupLocationState.Guid ).FirstOrDefault();
if ( groupLocation == null )
{
groupLocation = new GroupLocation();
group.GroupLocations.Add( groupLocation );
}
else
{
groupLocationState.Id = groupLocation.Id;
groupLocationState.Guid = groupLocation.Guid;
var selectedSchedules = groupLocationState.Schedules.Select( s => s.Guid ).ToList();
foreach ( var schedule in groupLocation.Schedules.Where( s => !selectedSchedules.Contains( s.Guid ) ).ToList() )
{
//.........这里部分代码省略.........
示例11: gWorkflowTypeAttributes_Delete
/// <summary>
/// Handles the Delete event of the gWorkflowTypeAttributes 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 gWorkflowTypeAttributes_Delete( object sender, RowEventArgs e )
{
Guid attributeGuid = (Guid)e.RowKeyValue;
AttributeService attributeService = new AttributeService();
Attribute attribute = attributeService.Get( attributeGuid );
if ( attribute != null )
{
string errorMessage;
if ( !attributeService.CanDelete( attribute, out errorMessage ) )
{
mdGridWarningAttributes.Show( errorMessage, ModalAlertType.Information );
return;
}
Rock.Web.Cache.AttributeCache.Flush( attribute.Id );
attributeService.Delete( attribute, CurrentPersonId );
attributeService.Save( attribute, CurrentPersonId );
}
// reload page so that other blocks respond to any data that was changed
var qryParams = new Dictionary<string, string>();
qryParams["workflowTypeId"] = hfWorkflowTypeId.Value;
NavigateToPage( RockPage.Guid, qryParams );
}
示例12: rGridAttribute_Delete
/// <summary>
/// Handles the Delete event of the rGridAttribute 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 rGridAttribute_Delete( object sender, RowEventArgs e )
{
var attributeService = new AttributeService();
Rock.Model.Attribute attribute = attributeService.Get( (int)rGridAttribute.DataKeys[e.RowIndex]["id"] );
if ( attribute != null )
{
attributeService.Delete( attribute, CurrentPersonId );
attributeService.Save( attribute, CurrentPersonId );
}
rGridAttribute_Bind( hfIdType.Value );
}
示例13: 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 attributeService = new Rock.Model.AttributeService( rockContext );
Rock.Model.Attribute attribute = attributeService.Get( (int)rGrid.DataKeys[e.RowIndex]["id"] );
if ( attribute != null )
{
Rock.Web.Cache.AttributeCache.Flush( attribute.Id );
attributeService.Delete( attribute );
rockContext.SaveChanges();
}
BindGrid();
}
示例14: 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 )
{
Group group;
bool wasSecurityRole = false;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
CategoryService categoryService = new CategoryService( rockContext );
if ( ( ddlGroupType.SelectedValueAsInt() ?? 0 ) == 0 )
{
ddlGroupType.ShowErrorMessage( Rock.Constants.WarningMessage.CannotBeBlank( GroupType.FriendlyTypeName ) );
return;
}
int groupId = int.Parse( hfGroupId.Value );
if ( groupId == 0 )
{
group = new Group();
group.IsSystem = false;
group.Name = string.Empty;
}
else
{
group = groupService.Get( groupId );
wasSecurityRole = group.IsSecurityRole;
var selectedLocations = GroupLocationsState.Select( l => l.Guid );
foreach ( var groupLocation in group.GroupLocations.Where( l => !selectedLocations.Contains( l.Guid ) ).ToList() )
{
group.GroupLocations.Remove( groupLocation );
groupLocationService.Delete( groupLocation );
}
}
foreach ( var groupLocationState in GroupLocationsState )
{
GroupLocation groupLocation = group.GroupLocations.Where( l => l.Guid == groupLocationState.Guid ).FirstOrDefault();
if ( groupLocation == null )
{
groupLocation = new GroupLocation();
group.GroupLocations.Add( groupLocation );
}
else
{
groupLocationState.Id = groupLocation.Id;
groupLocationState.Guid = groupLocation.Guid;
}
groupLocation.CopyPropertiesFrom( groupLocationState );
}
group.Name = tbName.Text;
group.Description = tbDescription.Text;
group.CampusId = ddlCampus.SelectedValue.Equals( None.IdValue ) ? (int?)null : int.Parse( ddlCampus.SelectedValue );
group.GroupTypeId = int.Parse( ddlGroupType.SelectedValue );
group.ParentGroupId = gpParentGroup.SelectedValue.Equals( None.IdValue ) ? (int?)null : int.Parse( gpParentGroup.SelectedValue );
group.IsSecurityRole = cbIsSecurityRole.Checked;
group.IsActive = cbIsActive.Checked;
if ( group.ParentGroupId == group.Id )
{
gpParentGroup.ShowErrorMessage( "Group cannot be a Parent Group of itself." );
return;
}
group.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phGroupAttributes, group );
if ( !Page.IsValid )
{
return;
}
if ( !group.IsValid )
{
// Controls will render the error messages
return;
}
// use WrapTransaction since SaveAttributeValues does it's own RockContext.SaveChanges()
RockTransactionScope.WrapTransaction( () =>
{
if ( group.Id.Equals( 0 ) )
{
groupService.Add( group );
}
rockContext.SaveChanges();
//.........这里部分代码省略.........
示例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 attributeService = new Rock.Model.AttributeService();
Rock.Model.Attribute attribute = attributeService.Get( (int)rGrid.DataKeys[e.RowIndex]["id"] );
if ( attribute != null )
{
Rock.Web.Cache.AttributeCache.Flush( attribute.Id );
attributeService.Delete( attribute, CurrentPersonId );
attributeService.Save( attribute, CurrentPersonId );
}
BindGrid();
}