本文整理汇总了C#中Rock.Model.ScheduleService.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# ScheduleService.Delete方法的具体用法?C# ScheduleService.Delete怎么用?C# ScheduleService.Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.ScheduleService
的用法示例。
在下文中一共展示了ScheduleService.Delete方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: gSchedules_Delete
/// <summary>
/// Handles the Delete event of the gSchedules 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 gSchedules_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
ScheduleService scheduleService = new ScheduleService( rockContext );
Schedule schedule = scheduleService.Get( e.RowKeyId );
if ( schedule != null )
{
string errorMessage;
if ( !scheduleService.CanDelete( schedule, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
scheduleService.Delete( schedule );
rockContext.SaveChanges();
}
BindGrid();
}
示例2: 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 )
{
EventItemOccurrence eventItemOccurrence = null;
using ( var rockContext = new RockContext() )
{
bool newItem = false;
var eventItemOccurrenceService = new EventItemOccurrenceService( rockContext );
var eventItemOccurrenceGroupMapService = new EventItemOccurrenceGroupMapService( rockContext );
var registrationInstanceService = new RegistrationInstanceService( rockContext );
var scheduleService = new ScheduleService( rockContext );
int eventItemOccurrenceId = hfEventItemOccurrenceId.ValueAsInt();
if ( eventItemOccurrenceId != 0 )
{
eventItemOccurrence = eventItemOccurrenceService
.Queryable( "Linkages" )
.Where( i => i.Id == eventItemOccurrenceId )
.FirstOrDefault();
}
if ( eventItemOccurrence == null )
{
newItem = true;
eventItemOccurrence = new EventItemOccurrence{ EventItemId = PageParameter("EventItemId").AsInteger() };
eventItemOccurrenceService.Add( eventItemOccurrence );
}
int? newCampusId = ddlCampus.SelectedValueAsInt();
if ( eventItemOccurrence.CampusId != newCampusId )
{
eventItemOccurrence.CampusId = newCampusId;
if ( newCampusId.HasValue )
{
var campus = new CampusService( rockContext ).Get( newCampusId.Value );
eventItemOccurrence.Campus = campus;
}
else
{
eventItemOccurrence.Campus = null;
}
}
eventItemOccurrence.Location = tbLocation.Text;
string iCalendarContent = sbSchedule.iCalendarContent;
var calEvent = ScheduleICalHelper.GetCalenderEvent( iCalendarContent );
if ( calEvent != null && calEvent.DTStart != null )
{
if ( eventItemOccurrence.Schedule == null )
{
eventItemOccurrence.Schedule = new Schedule();
}
eventItemOccurrence.Schedule.iCalendarContent = iCalendarContent;
}
else
{
if ( eventItemOccurrence.ScheduleId.HasValue )
{
var oldSchedule = scheduleService.Get( eventItemOccurrence.ScheduleId.Value );
if ( oldSchedule != null )
{
scheduleService.Delete( oldSchedule );
}
}
}
if ( !eventItemOccurrence.ContactPersonAliasId.Equals( ppContact.PersonAliasId ))
{
PersonAlias personAlias = null;
eventItemOccurrence.ContactPersonAliasId = ppContact.PersonAliasId;
if ( eventItemOccurrence.ContactPersonAliasId.HasValue )
{
personAlias = new PersonAliasService( rockContext ).Get( eventItemOccurrence.ContactPersonAliasId.Value );
}
if ( personAlias != null )
{
eventItemOccurrence.ContactPersonAlias = personAlias;
}
}
eventItemOccurrence.ContactPhone = PhoneNumber.FormattedNumber( PhoneNumber.DefaultCountryCode(), pnPhone.Number );
eventItemOccurrence.ContactEmail = tbEmail.Text;
eventItemOccurrence.Note = htmlOccurrenceNote.Text;
// Remove any linkage no longer in UI
Guid uiLinkageGuid = LinkageState != null ? LinkageState.Guid : Guid.Empty;
foreach( var linkage in eventItemOccurrence.Linkages.Where( l => !l.Guid.Equals(uiLinkageGuid)).ToList())
{
eventItemOccurrence.Linkages.Remove( linkage );
eventItemOccurrenceGroupMapService.Delete( linkage );
}
// Add/Update linkage in UI
//.........这里部分代码省略.........
示例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 )
{
Metric metric;
var rockContext = new RockContext();
MetricService metricService = new MetricService( rockContext );
MetricCategoryService metricCategoryService = new MetricCategoryService( rockContext );
MetricValueService metricValueService = new MetricValueService( rockContext );
MetricPartitionService metricPartitionService = new MetricPartitionService( rockContext );
int metricId = hfMetricId.Value.AsInteger();
if ( metricId == 0 )
{
metric = new Metric();
}
else
{
metric = metricService.Get( metricId );
// remove any metricPartitions that were removed in the UI
var selectedMetricPartitionGuids = MetricPartitionsState.Select( r => r.Guid );
foreach ( var item in metric.MetricPartitions.Where( r => !selectedMetricPartitionGuids.Contains( r.Guid ) ).ToList() )
{
metric.MetricPartitions.Remove( item );
metricPartitionService.Delete( item );
}
}
metric.MetricPartitions = metric.MetricPartitions ?? new List<MetricPartition>();
if ( MetricPartitionsState.Count() > 1 && MetricPartitionsState.Any(a => !a.EntityTypeId.HasValue ))
{
mdMetricPartitionsEntityTypeWarning.Text = "If multiple partitions are defined for a metric, all the partitions must have an EntityType assigned";
mdMetricPartitionsEntityTypeWarning.Visible = true;
pwMetricPartitions.Expanded = true;
return;
}
mdMetricPartitionsEntityTypeWarning.Visible = false;
foreach ( var metricPartitionState in MetricPartitionsState )
{
MetricPartition metricPartition = metric.MetricPartitions.Where( r => r.Guid == metricPartitionState.Guid ).FirstOrDefault();
if ( metricPartition == null )
{
metricPartition = new MetricPartition();
metric.MetricPartitions.Add( metricPartition );
}
else
{
metricPartitionState.Id = metricPartition.Id;
metricPartitionState.Guid = metricPartition.Guid;
}
metricPartition.CopyPropertiesFrom( metricPartitionState );
}
// ensure there is at least one partition
if ( !metric.MetricPartitions.Any() )
{
var metricPartition = new MetricPartition();
metricPartition.EntityTypeId = null;
metricPartition.IsRequired = true;
metricPartition.Order = 0;
metric.MetricPartitions.Add( metricPartition );
}
metric.Title = tbTitle.Text;
metric.Subtitle = tbSubtitle.Text;
metric.Description = tbDescription.Text;
metric.IconCssClass = tbIconCssClass.Text;
metric.SourceValueTypeId = ddlSourceType.SelectedValueAsId();
metric.YAxisLabel = tbYAxisLabel.Text;
metric.IsCumulative = cbIsCumulative.Checked;
int sourceTypeDataView = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.METRIC_SOURCE_VALUE_TYPE_DATAVIEW.AsGuid() ).Id;
int sourceTypeSQL = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.METRIC_SOURCE_VALUE_TYPE_SQL.AsGuid() ).Id;
var personService = new PersonService( rockContext );
var metricChampionPerson = personService.Get( ppMetricChampionPerson.SelectedValue ?? 0 );
metric.MetricChampionPersonAliasId = metricChampionPerson != null ? metricChampionPerson.PrimaryAliasId : null;
var adminPerson = personService.Get( ppAdminPerson.SelectedValue ?? 0 );
metric.AdminPersonAliasId = adminPerson != null ? adminPerson.PrimaryAliasId : null;
if ( metric.SourceValueTypeId == sourceTypeSQL )
{
metric.SourceSql = ceSourceSql.Text;
}
else
{
metric.SourceSql = string.Empty;
}
if ( metric.SourceValueTypeId == sourceTypeDataView )
//.........这里部分代码省略.........
示例4: 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? categoryId = null;
var rockContext = new RockContext();
var service = new ScheduleService( rockContext );
var item = service.Get( int.Parse( hfScheduleId.Value ) );
if ( item != null )
{
string errorMessage;
if ( !service.CanDelete( item, out errorMessage ) )
{
ShowReadonlyDetails( item );
mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
}
else
{
categoryId = item.CategoryId;
service.Delete( item );
rockContext.SaveChanges();
// reload page, selecting the deleted data view's parent
var qryParams = new Dictionary<string, string>();
if ( categoryId != null )
{
qryParams["CategoryId"] = categoryId.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 )
{
Metric metric;
var rockContext = new RockContext();
MetricService metricService = new MetricService( rockContext );
MetricCategoryService metricCategoryService = new MetricCategoryService( rockContext );
MetricValueService metricValueService = new MetricValueService( rockContext );
bool deleteValuesOnSave = sender == btnDeleteValuesAndSave;
int metricId = hfMetricId.Value.AsInteger();
if ( metricId == 0 )
{
metric = new Metric();
}
else
{
metric = metricService.Get( metricId );
}
metric.Title = tbTitle.Text;
metric.Subtitle = tbSubtitle.Text;
metric.Description = tbDescription.Text;
metric.IconCssClass = tbIconCssClass.Text;
metric.SourceValueTypeId = ddlSourceType.SelectedValueAsId();
metric.XAxisLabel = tbXAxisLabel.Text;
metric.YAxisLabel = tbYAxisLabel.Text;
metric.IsCumulative = cbIsCumulative.Checked;
var origEntityType = metric.EntityTypeId.HasValue ? EntityTypeCache.Read( metric.EntityTypeId.Value ) : null;
var newEntityType = etpEntityType.SelectedEntityTypeId.HasValue ? EntityTypeCache.Read( etpEntityType.SelectedEntityTypeId.Value ) : null;
if ( origEntityType != null && !deleteValuesOnSave )
{
if ( newEntityType == null || newEntityType.Id != origEntityType.Id )
{
// if the EntityTypeId of this metric has changed to NULL or to another EntityType, warn about the EntityId values being wrong
bool hasEntityValues = metricValueService.Queryable().Any( a => a.MetricId == metric.Id && a.EntityId.HasValue );
if ( hasEntityValues )
{
nbEntityTypeChanged.Text = string.Format(
"Warning: You can't change the series partition to {0} when there are values associated with {1}. Do you want to delete existing values?",
newEntityType != null ? newEntityType.FriendlyName : "<none>",
origEntityType.FriendlyName );
mdEntityTypeChanged.Show();
nbEntityTypeChanged.Visible = true;
return;
}
}
}
metric.EntityTypeId = etpEntityType.SelectedEntityTypeId;
int sourceTypeDataView = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.METRIC_SOURCE_VALUE_TYPE_DATAVIEW.AsGuid() ).Id;
int sourceTypeSQL = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.METRIC_SOURCE_VALUE_TYPE_SQL.AsGuid() ).Id;
var personService = new PersonService( rockContext );
var metricChampionPerson = personService.Get( ppMetricChampionPerson.SelectedValue ?? 0 );
metric.MetricChampionPersonAliasId = metricChampionPerson != null ? metricChampionPerson.PrimaryAliasId : null;
var adminPerson = personService.Get( ppAdminPerson.SelectedValue ?? 0 );
metric.AdminPersonAliasId = adminPerson != null ? adminPerson.PrimaryAliasId : null;
if ( metric.SourceValueTypeId == sourceTypeSQL )
{
metric.SourceSql = ceSourceSql.Text;
}
else
{
metric.SourceSql = string.Empty;
}
if ( metric.SourceValueTypeId == sourceTypeDataView )
{
metric.DataViewId = ddlDataView.SelectedValueAsId();
}
else
{
metric.DataViewId = null;
}
var scheduleSelectionType = rblScheduleSelect.SelectedValueAsEnum<ScheduleSelectionType>();
if ( scheduleSelectionType == ScheduleSelectionType.NamedSchedule )
{
metric.ScheduleId = ddlSchedule.SelectedValueAsId();
}
else
{
metric.ScheduleId = hfUniqueScheduleId.ValueAsInt();
}
if ( !Page.IsValid )
{
return;
}
//.........这里部分代码省略.........
示例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 )
{
Group group;
bool wasSecurityRole = false;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
ScheduleService scheduleService = new ScheduleService( 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.Queryable( "Schedule,GroupLocations.Schedules" ).Where( g => g.Id == groupId ).FirstOrDefault();
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;
var selectedSchedules = groupLocationState.Schedules.Select( s => s.Guid ).ToList();
foreach( var schedule in groupLocation.Schedules.Where( s => !selectedSchedules.Contains( s.Guid)).ToList())
{
groupLocation.Schedules.Remove( schedule );
}
}
groupLocation.CopyPropertiesFrom( groupLocationState );
var existingSchedules = groupLocation.Schedules.Select( s => s.Guid ).ToList();
foreach ( var scheduleState in groupLocationState.Schedules.Where( s => !existingSchedules.Contains( s.Guid )).ToList())
{
var schedule = scheduleService.Get( scheduleState.Guid );
if ( schedule != null )
{
groupLocation.Schedules.Add( schedule );
}
}
}
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;
string iCalendarContent = string.Empty;
// If unique schedule option was selected, but a schedule was not defined, set option to 'None'
var scheduleType = rblScheduleSelect.SelectedValueAsEnum<ScheduleType>( ScheduleType.None );
if ( scheduleType == ScheduleType.Custom )
{
iCalendarContent = sbSchedule.iCalendarContent;
var calEvent = ScheduleICalHelper.GetCalenderEvent( iCalendarContent );
if ( calEvent == null || calEvent.DTStart == null )
{
scheduleType = ScheduleType.None;
}
}
//.........这里部分代码省略.........
示例7: 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? parentGroupId = null;
RockContext rockContext = new RockContext();
GroupService groupService = new GroupService( rockContext );
AuthService authService = new AuthService( rockContext );
Group group = groupService.Get( int.Parse( hfGroupId.Value ) );
if ( group != null )
{
if ( !group.IsAuthorized( Authorization.EDIT, this.CurrentPerson ) )
{
mdDeleteWarning.Show( "You are not authorized to delete this group.", ModalAlertType.Information );
return;
}
parentGroupId = group.ParentGroupId;
string errorMessage;
if ( !groupService.CanDelete( group, out errorMessage ) )
{
mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
bool isSecurityRoleGroup = group.IsSecurityRole || group.GroupType.Guid.Equals( Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid() );
if ( isSecurityRoleGroup )
{
Rock.Security.Role.Flush( group.Id );
foreach ( var auth in authService.Queryable().Where( a => a.GroupId == group.Id ).ToList() )
{
authService.Delete( auth );
}
}
// If group has a non-named schedule, delete the schedule record.
if ( group.ScheduleId.HasValue )
{
var scheduleService = new ScheduleService( rockContext );
var schedule = scheduleService.Get( group.ScheduleId.Value );
if ( schedule != null && schedule.ScheduleType != ScheduleType.Named )
{
scheduleService.Delete(schedule);
}
}
groupService.Delete( group );
rockContext.SaveChanges();
if ( isSecurityRoleGroup )
{
Rock.Security.Authorization.Flush();
}
}
// reload page, selecting the deleted group's parent
var qryParams = new Dictionary<string, string>();
if ( parentGroupId != null )
{
qryParams["GroupId"] = parentGroupId.ToString();
}
qryParams["ExpandedIds"] = PageParameter( "ExpandedIds" );
NavigateToPage( RockPage.Guid, qryParams );
}
示例8: btnSave_Click
//.........这里部分代码省略.........
if ( !metric.IsValid )
{
// Controls will render the error messages
return;
}
if ( !cpMetricCategories.SelectedValuesAsInt().Any() )
{
cpMetricCategories.ShowErrorMessage( "Must select at least one category" );
return;
}
// do a WrapTransaction since we are doing multiple SaveChanges()
RockTransactionScope.WrapTransaction( () =>
{
var scheduleService = new ScheduleService( rockContext );
var schedule = scheduleService.Get( metric.ScheduleId ?? 0 );
int metricScheduleCategoryId = new CategoryService( rockContext ).Get( Rock.SystemGuid.Category.SCHEDULE_METRICS.AsGuid() ).Id;
if ( schedule == null )
{
schedule = new Schedule();
// make it an "Unnamed" metrics schedule
schedule.Name = string.Empty;
schedule.CategoryId = metricScheduleCategoryId;
}
schedule.iCalendarContent = sbSchedule.iCalendarContent;
if ( schedule.Id == 0 )
{
scheduleService.Add( schedule );
// save to make sure we have a scheduleId
rockContext.SaveChanges();
}
metric.ScheduleId = schedule.Id;
if ( metric.Id == 0 )
{
metricService.Add( metric );
// save to make sure we have a metricId
rockContext.SaveChanges();
}
// update MetricCategories for Metric
metric.MetricCategories = metric.MetricCategories ?? new List<MetricCategory>();
var selectedCategoryIds = cpMetricCategories.SelectedValuesAsInt();
// delete any categories that were removed
foreach ( var metricCategory in metric.MetricCategories )
{
if ( !selectedCategoryIds.Contains( metricCategory.CategoryId ) )
{
metricCategoryService.Delete( metricCategory );
}
}
// add any categories that were added
foreach ( int categoryId in selectedCategoryIds )
{
if ( !metric.MetricCategories.Any( a => a.CategoryId == categoryId ) )
{
metricCategoryService.Add( new MetricCategory { CategoryId = categoryId, MetricId = metric.Id } );
}
}
rockContext.SaveChanges();
// delete any orphaned Unnamed metric schedules
var metricIdSchedulesQry = metricService.Queryable().Select( a => a.ScheduleId );
var orphanedSchedules = scheduleService.Queryable()
.Where( a => a.CategoryId == metricScheduleCategoryId && a.Name == string.Empty && a.Id != schedule.Id )
.Where( s => !metricIdSchedulesQry.Any( m => m == s.Id ) );
foreach ( var item in orphanedSchedules )
{
scheduleService.Delete( item );
}
if ( orphanedSchedules.Any() )
{
rockContext.SaveChanges();
}
} );
var qryParams = new Dictionary<string, string>();
qryParams["MetricId"] = metric.Id.ToString();
if ( hfMetricCategoryId.ValueAsInt() == 0 )
{
int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsInteger();
int? metricCategoryId = new MetricCategoryService( new RockContext() ).Queryable().Where( a => a.MetricId == metric.Id && a.CategoryId == parentCategoryId ).Select( a => a.Id ).FirstOrDefault();
hfMetricCategoryId.Value = metricCategoryId.ToString();
}
qryParams["MetricCategoryId"] = hfMetricCategoryId.Value;
NavigateToPage( RockPage.Guid, qryParams );
}
示例9: 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() )
{
//.........这里部分代码省略.........
示例10: gSchedules_Delete
/// <summary>
/// Handles the Delete event of the gSchedules 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 gSchedules_Delete( object sender, RowEventArgs e )
{
RockTransactionScope.WrapTransaction( () =>
{
ScheduleService scheduleService = new ScheduleService();
Schedule schedule = scheduleService.Get( (int)e.RowKeyValue );
if ( schedule != null )
{
string errorMessage;
if ( !scheduleService.CanDelete( schedule, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
scheduleService.Delete( schedule, CurrentPersonId );
scheduleService.Save( schedule, CurrentPersonId );
}
} );
BindGrid();
}