本文整理汇总了C#中Rock.Data.RockContext.WrapTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# RockContext.WrapTransaction方法的具体用法?C# RockContext.WrapTransaction怎么用?C# RockContext.WrapTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Data.RockContext
的用法示例。
在下文中一共展示了RockContext.WrapTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePersonAndFamily
public HttpResponseMessage CreatePersonAndFamily( [FromBody]PersonParameters personParameters )
{
var rockContext = new RockContext();
var response = new HttpResponseMessage( HttpStatusCode.Created );
try
{
rockContext.WrapTransaction( () =>
{
var person = CreatePerson(personParameters, null, rockContext, false);
response.Content = new StringContent( person.Id.ToString() );
} );
}
catch ( HttpResponseException exception )
{
return exception.Response;
}
catch ( Exception exception )
{
var errorResponse = new HttpResponseMessage( HttpStatusCode.InternalServerError );
errorResponse.Content = new StringContent( exception.Message );
return errorResponse;
}
return response;
}
示例2: Execute
/// <summary>
/// Executes the specified workflow.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="action">The action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
public override bool Execute( RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages )
{
errorMessages = new List<string>();
var workflow = action.Activity.Workflow;
workflow.IsPersisted = true;
if ( GetAttributeValue( action, "PersistImmediately" ).AsBoolean( false ) )
{
var service = new WorkflowService( rockContext );
if ( workflow.Id == 0 )
{
service.Add( workflow );
}
rockContext.WrapTransaction( () =>
{
rockContext.SaveChanges();
workflow.SaveAttributeValues( rockContext );
foreach ( var activity in workflow.Activities )
{
activity.SaveAttributeValues( rockContext );
}
} );
}
action.AddLogEntry( "Updated workflow to be persisted!" );
return true;
}
示例3: SaveCommunication
/// <summary>
/// Saves the communication.
/// </summary>
/// <param name="newNumberList">The new number list.</param>
/// <param name="updatedPersonList">The updated person list.</param>
private static void SaveCommunication( List<PhoneNumber> newNumberList, List<Person> updatedPersonList )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.PhoneNumbers.AddRange( newNumberList );
rockContext.SaveChanges( DisableAudit );
var newAttributeValues = new List<AttributeValue>();
foreach ( var updatedPerson in updatedPersonList.Where( p => p.Attributes.Any() ) )
{
foreach ( var attributeCache in updatedPerson.Attributes.Select( a => a.Value ) )
{
var newValue = updatedPerson.AttributeValues[attributeCache.Key];
if ( newValue != null )
{
newValue.EntityId = updatedPerson.Id;
newAttributeValues.Add( newValue );
}
}
}
rockContext.AttributeValues.AddRange( newAttributeValues );
rockContext.SaveChanges( DisableAudit );
} );
}
示例4: SaveFamilyAddress
/// <summary>
/// Saves the family address.
/// </summary>
/// <param name="newGroupLocations">The new group locations.</param>
private static void SaveFamilyAddress( List<GroupLocation> newGroupLocations )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.GroupLocations.AddRange( newGroupLocations );
rockContext.SaveChanges( DisableAuditing );
} );
}
示例5: SaveAttendance
/// <summary>
/// Saves the attendance.
/// </summary>
/// <param name="attendance">The attendance.</param>
private static void SaveAttendance( Rock.Model.Attendance attendance )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.Attendances.Add( attendance );
rockContext.SaveChanges( DisableAudit );
} );
}
示例6: SaveNotes
/// <summary>
/// Saves the notes.
/// </summary>
/// <param name="noteList">The note list.</param>
private static void SaveNotes( List<Note> noteList )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.Notes.AddRange( noteList );
rockContext.SaveChanges( DisableAudit );
} );
}
示例7: SaveFinancialBatches
/// <summary>
/// Saves the financial batches.
/// </summary>
/// <param name="newBatches">The new batches.</param>
private static void SaveFinancialBatches( List<FinancialBatch> newBatches )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.FinancialBatches.AddRange( newBatches );
rockContext.SaveChanges( DisableAudit );
} );
}
示例8: 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();
var service = new WorkflowService( rockContext );
ParseControls( rockContext, true );
Workflow dbWorkflow = null;
if ( Workflow != null )
{
dbWorkflow = service.Get( Workflow.Id );
if ( dbWorkflow != null )
{
if ( !dbWorkflow.CompletedDateTime.HasValue && Workflow.CompletedDateTime.HasValue )
{
dbWorkflow.AddLogEntry( "Workflow Manually Completed." );
dbWorkflow.CompletedDateTime = Workflow.CompletedDateTime;
}
else if ( dbWorkflow.CompletedDateTime.HasValue && !Workflow.CompletedDateTime.HasValue )
{
dbWorkflow.AddLogEntry( "Workflow Manually Re-Activated." );
dbWorkflow.CompletedDateTime = null;
}
if ( dbWorkflow.Name.Trim() != Workflow.Name.Trim() )
{
dbWorkflow.AddLogEntry( string.Format( "Workflow name manually changed from '{0}' to '{0}'.", dbWorkflow.Name, tbName.Text ) );
dbWorkflow.Name = Workflow.Name;
}
if ( dbWorkflow.Status.Trim() != Workflow.Status.Trim() )
{
dbWorkflow.AddLogEntry( string.Format( "Workflow status manually changed from '{0}' to '{0}'.", dbWorkflow.Status, tbStatus.Text ) );
dbWorkflow.Status = Workflow.Status;
}
if ( !dbWorkflow.InitiatorPersonAliasId.Equals(Workflow.InitiatorPersonAliasId))
{
dbWorkflow.AddLogEntry( string.Format( "Workflow status manually changed from '{0}' to '{0}'.",
dbWorkflow.InitiatorPersonAlias != null ? dbWorkflow.InitiatorPersonAlias.Person.FullName : "",
Workflow.InitiatorPersonAlias != null ? Workflow.InitiatorPersonAlias.Person.FullName : "" ) );
dbWorkflow.InitiatorPersonAlias = Workflow.InitiatorPersonAlias;
dbWorkflow.InitiatorPersonAliasId = Workflow.InitiatorPersonAliasId;
}
if ( !Page.IsValid || !dbWorkflow.IsValid )
{
return;
}
foreach ( var activity in Workflow.Activities )
{
if ( !activity.IsValid )
{
return;
}
foreach ( var action in activity.Actions )
{
if ( !action.IsValid )
{
return;
}
}
}
rockContext.WrapTransaction( () =>
{
rockContext.SaveChanges();
dbWorkflow.LoadAttributes( rockContext );
foreach ( var attributeValue in Workflow.AttributeValues )
{
dbWorkflow.SetAttributeValue( attributeValue.Key, Workflow.GetAttributeValue( attributeValue.Key ) );
}
dbWorkflow.SaveAttributeValues( rockContext );
WorkflowActivityService workflowActivityService = new WorkflowActivityService( rockContext );
WorkflowActionService workflowActionService = new WorkflowActionService( rockContext );
var activitiesInUi = new List<Guid>();
var actionsInUI = new List<Guid>();
foreach ( var activity in Workflow.Activities )
{
activitiesInUi.Add( activity.Guid );
foreach ( var action in activity.Actions )
{
actionsInUI.Add( action.Guid );
}
}
// delete WorkflowActions that were removed in the UI
foreach ( var action in workflowActionService.Queryable()
.Where( a =>
//.........这里部分代码省略.........
示例9: lbSave_Click
/// <summary>
/// Handles the Click event of the lbSave 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 lbSave_Click( object sender, EventArgs e )
{
var rockContext = new RockContext();
var batchService = new FinancialBatchService( rockContext );
FinancialBatch batch = null;
var changes = new List<string>();
int batchId = hfBatchId.Value.AsInteger();
if ( batchId == 0 )
{
batch = new FinancialBatch();
batchService.Add( batch );
changes.Add( "Created the batch" );
}
else
{
batch = batchService.Get( batchId );
}
if ( batch != null )
{
History.EvaluateChange( changes, "Batch Name", batch.Name, tbName.Text );
batch.Name = tbName.Text;
BatchStatus batchStatus = (BatchStatus)ddlStatus.SelectedIndex;
History.EvaluateChange( changes, "Status", batch.Status, batchStatus );
batch.Status = batchStatus;
CampusCache oldCampus = null;
if ( batch.CampusId.HasValue )
{
oldCampus = CampusCache.Read( batch.CampusId.Value );
}
CampusCache newCampus = null;
if ( campCampus.SelectedCampusId.HasValue )
{
newCampus = CampusCache.Read( campCampus.SelectedCampusId.Value );
}
History.EvaluateChange( changes, "Campus", oldCampus != null ? oldCampus.Name : "None", newCampus != null ? newCampus.Name : "None" );
batch.CampusId = campCampus.SelectedCampusId;
DateTime? startDateTime = dtpStart.SelectedDateTimeIsBlank ? null : dtpStart.SelectedDateTime;
History.EvaluateChange( changes, "Start Date/Time", batch.BatchStartDateTime, startDateTime );
batch.BatchStartDateTime = startDateTime;
DateTime? endDateTime;
if ( dtpEnd.SelectedDateTimeIsBlank && batch.BatchStartDateTime.HasValue )
{
endDateTime = batch.BatchStartDateTime.Value.AddDays( 1 );
}
else
{
endDateTime = dtpEnd.SelectedDateTimeIsBlank ? null : dtpEnd.SelectedDateTime;
}
History.EvaluateChange( changes, "End Date/Time", batch.BatchEndDateTime, endDateTime );
batch.BatchEndDateTime = endDateTime;
decimal controlAmount = tbControlAmount.Text.AsDecimal();
History.EvaluateChange( changes, "Control Amount", batch.ControlAmount.FormatAsCurrency(), controlAmount.FormatAsCurrency() );
batch.ControlAmount = controlAmount;
History.EvaluateChange( changes, "Accounting System Code", batch.AccountingSystemCode, tbAccountingCode.Text );
batch.AccountingSystemCode = tbAccountingCode.Text;
History.EvaluateChange( changes, "Notes", batch.Note, tbNote.Text );
batch.Note = tbNote.Text;
cvBatch.IsValid = batch.IsValid;
if ( !Page.IsValid || !batch.IsValid )
{
cvBatch.ErrorMessage = batch.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" );
return;
}
rockContext.WrapTransaction( () =>
{
if ( rockContext.SaveChanges() > 0 )
{
if ( changes.Any() )
{
HistoryService.SaveChanges(
rockContext,
typeof( FinancialBatch ),
Rock.SystemGuid.Category.HISTORY_FINANCIAL_BATCH.AsGuid(),
batch.Id,
changes );
}
}
} );
if ( batchId == 0 )
//.........这里部分代码省略.........
示例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 )
{
Location location;
var rockContext = new RockContext();
LocationService locationService = new LocationService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
int locationId = int.Parse( hfLocationId.Value );
if ( locationId == 0 )
{
location = new Location();
location.Name = string.Empty;
}
else
{
location = locationService.Get( locationId );
FlushCampus( locationId );
}
int? orphanedImageId = null;
if ( location.ImageId != imgImage.BinaryFileId )
{
orphanedImageId = location.ImageId;
location.ImageId = imgImage.BinaryFileId;
}
location.Name = tbName.Text;
location.IsActive = cbIsActive.Checked;
location.LocationTypeValueId = ddlLocationType.SelectedValueAsId();
if ( gpParentLocation != null && gpParentLocation.Location != null )
{
location.ParentLocationId = gpParentLocation.Location.Id;
}
else
{
location.ParentLocationId = null;
}
location.PrinterDeviceId = ddlPrinter.SelectedValueAsInt();
acAddress.GetValues(location);
location.GeoPoint = geopPoint.SelectedValue;
if ( geopPoint.SelectedValue != null )
{
location.IsGeoPointLocked = true;
}
location.GeoFence = geopFence.SelectedValue;
location.IsGeoPointLocked = cbGeoPointLocked.Checked;
location.LoadAttributes( rockContext );
Rock.Attribute.Helper.GetEditValues( phAttributeEdits, location );
if ( !Page.IsValid )
{
return;
}
if ( !location.IsValid )
{
// Controls will render the error messages
return;
}
rockContext.WrapTransaction( () =>
{
if ( location.Id.Equals( 0 ) )
{
locationService.Add( location );
}
rockContext.SaveChanges();
if (orphanedImageId.HasValue)
{
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
var binaryFile = binaryFileService.Get( orphanedImageId.Value );
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
rockContext.SaveChanges();
}
}
location.SaveAttributeValues( rockContext );
} );
var qryParams = new Dictionary<string, string>();
qryParams["LocationId"] = location.Id.ToString();
qryParams["ExpandedIds"] = PageParameter( "ExpandedIds" );
//.........这里部分代码省略.........
示例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 )
{
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();
}
示例12: 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 )
{
Location location = null;
var rockContext = new RockContext();
LocationService locationService = new LocationService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
AttributeQualifierService attributeQualifierService = new AttributeQualifierService( rockContext );
int locationId = int.Parse( hfLocationId.Value );
if ( locationId != 0 )
{
location = locationService.Get( locationId );
FlushCampus( locationId );
}
if ( location == null )
{
location = new Location();
location.Name = string.Empty;
}
string previousName = location.Name;
int? orphanedImageId = null;
if ( location.ImageId != imgImage.BinaryFileId )
{
orphanedImageId = location.ImageId;
location.ImageId = imgImage.BinaryFileId;
}
location.Name = tbName.Text;
location.IsActive = cbIsActive.Checked;
location.LocationTypeValueId = ddlLocationType.SelectedValueAsId();
if ( gpParentLocation != null && gpParentLocation.Location != null )
{
location.ParentLocationId = gpParentLocation.Location.Id;
}
else
{
location.ParentLocationId = null;
}
location.PrinterDeviceId = ddlPrinter.SelectedValueAsInt();
acAddress.GetValues(location);
location.GeoPoint = geopPoint.SelectedValue;
if ( geopPoint.SelectedValue != null )
{
location.IsGeoPointLocked = true;
}
location.GeoFence = geopFence.SelectedValue;
location.IsGeoPointLocked = cbGeoPointLocked.Checked;
location.SoftRoomThreshold = nbSoftThreshold.Text.AsIntegerOrNull();
location.FirmRoomThreshold = nbFirmThreshold.Text.AsIntegerOrNull();
location.LoadAttributes( rockContext );
Rock.Attribute.Helper.GetEditValues( phAttributeEdits, location );
if ( !Page.IsValid )
{
return;
}
// if the location IsValid is false, and the UI controls didn't report any errors, it is probably because the custom rules of location didn't pass.
// So, make sure a message is displayed in the validation summary
cvLocation.IsValid = location.IsValid;
if ( !cvLocation.IsValid )
{
cvLocation.ErrorMessage = location.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" );
return;
}
rockContext.WrapTransaction( () =>
{
if ( location.Id.Equals( 0 ) )
{
locationService.Add( location );
}
rockContext.SaveChanges();
if (orphanedImageId.HasValue)
{
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
var binaryFile = binaryFileService.Get( orphanedImageId.Value );
if ( binaryFile != null )
{
// marked the old images as IsTemporary so they will get cleaned up later
binaryFile.IsTemporary = true;
rockContext.SaveChanges();
//.........这里部分代码省略.........
示例13: 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 )
{
BinaryFile binaryFile;
var rockContext = new RockContext();
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
AttributeService attributeService = new AttributeService( rockContext );
int? prevBinaryFileTypeId = null;
int binaryFileId = int.Parse( hfBinaryFileId.Value );
if ( binaryFileId == 0 )
{
binaryFile = new BinaryFile();
binaryFileService.Add( binaryFile );
}
else
{
binaryFile = binaryFileService.Get( binaryFileId );
prevBinaryFileTypeId = binaryFile != null ? binaryFile.BinaryFileTypeId : (int?)null;
}
// if a new file was uploaded, copy the uploaded file to this binaryFile (uploaded files are always new temporary binaryFiles)
if ( fsFile.BinaryFileId != binaryFile.Id)
{
var uploadedBinaryFile = binaryFileService.Get(fsFile.BinaryFileId ?? 0);
if (uploadedBinaryFile != null)
{
binaryFile.BinaryFileTypeId = uploadedBinaryFile.BinaryFileTypeId;
binaryFile.ContentStream = uploadedBinaryFile.ContentStream;
}
}
binaryFile.IsTemporary = false;
binaryFile.FileName = tbName.Text;
binaryFile.Description = tbDescription.Text;
binaryFile.MimeType = tbMimeType.Text;
binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();
binaryFile.LoadAttributes( rockContext );
Rock.Attribute.Helper.GetEditValues( phAttributes, binaryFile );
if ( !Page.IsValid )
{
return;
}
if ( !binaryFile.IsValid )
{
// Controls will render the error messages
return;
}
rockContext.WrapTransaction( () =>
{
foreach ( var id in OrphanedBinaryFileIdList )
{
var tempBinaryFile = binaryFileService.Get( id );
if ( tempBinaryFile != null && tempBinaryFile.IsTemporary )
{
binaryFileService.Delete( tempBinaryFile );
}
}
rockContext.SaveChanges();
binaryFile.SaveAttributeValues( rockContext );
} );
Rock.CheckIn.KioskLabel.Flush( binaryFile.Guid );
if ( !prevBinaryFileTypeId.Equals( binaryFile.BinaryFileTypeId ) )
{
var checkInBinaryFileType = new BinaryFileTypeService( rockContext )
.Get( Rock.SystemGuid.BinaryFiletype.CHECKIN_LABEL.AsGuid() );
if ( checkInBinaryFileType != null && (
( prevBinaryFileTypeId.HasValue && prevBinaryFileTypeId.Value == checkInBinaryFileType.Id ) ||
( binaryFile.BinaryFileTypeId.HasValue && binaryFile.BinaryFileTypeId.Value == checkInBinaryFileType.Id ) ) )
{
Rock.CheckIn.KioskDevice.FlushAll();
}
}
NavigateToParentPage();
}
示例14: btnSave_Click
//.........这里部分代码省略.........
groupType.LocationSelectionMode = locationSelectionMode;
groupType.GroupTypePurposeValueId = ddlGroupTypePurpose.SelectedValueAsInt();
groupType.AllowMultipleLocations = cbAllowMultipleLocations.Checked;
groupType.InheritedGroupTypeId = gtpInheritedGroupType.SelectedGroupTypeId;
groupType.EnableLocationSchedules = cbEnableLocationSchedules.Checked;
groupType.ChildGroupTypes = new List<GroupType>();
groupType.ChildGroupTypes.Clear();
foreach ( var item in ChildGroupTypesDictionary )
{
var childGroupType = groupTypeService.Get( item.Key );
if ( childGroupType != null )
{
groupType.ChildGroupTypes.Add( childGroupType );
}
}
// Delete any removed exclusions
foreach ( var exclusion in groupType.GroupScheduleExclusions.Where( s => !ScheduleExclusionDictionary.Keys.Contains( s.Guid ) ).ToList() )
{
groupType.GroupScheduleExclusions.Remove( exclusion );
scheduleExclusionService.Delete( exclusion );
}
// Update exclusions
foreach( var keyVal in ScheduleExclusionDictionary )
{
var scheduleExclusion = groupType.GroupScheduleExclusions
.FirstOrDefault( s => s.Guid.Equals( keyVal.Key));
if ( scheduleExclusion == null )
{
scheduleExclusion = new GroupScheduleExclusion();
groupType.GroupScheduleExclusions.Add( scheduleExclusion);
}
scheduleExclusion.StartDate = keyVal.Value.Start;
scheduleExclusion.EndDate = keyVal.Value.End;
}
DefinedValueService definedValueService = new DefinedValueService( rockContext );
groupType.LocationTypes = new List<GroupTypeLocationType>();
groupType.LocationTypes.Clear();
foreach ( var item in LocationTypesDictionary )
{
var locationType = definedValueService.Get( item.Key );
if ( locationType != null )
{
groupType.LocationTypes.Add( new GroupTypeLocationType { LocationTypeValueId = locationType.Id } );
}
}
if ( !groupType.IsValid )
{
// Controls will render the error messages
return;
}
// need WrapTransaction due to Attribute saves
rockContext.WrapTransaction( () =>
{
rockContext.SaveChanges();
/* Save Attributes */
string qualifierValue = groupType.Id.ToString();
SaveAttributes( new GroupType().TypeId, "Id", qualifierValue, GroupTypeAttributesState, rockContext );
SaveAttributes( new Group().TypeId, "GroupTypeId", qualifierValue, GroupAttributesState, rockContext );
SaveAttributes( new GroupMember().TypeId, "GroupTypeId", qualifierValue, GroupMemberAttributesState, rockContext );
// Reload to save default role
groupType = groupTypeService.Get( groupType.Id );
groupType.DefaultGroupRole = groupType.Roles.FirstOrDefault( r => r.Guid.Equals( DefaultRoleGuid ) );
if ( groupType.DefaultGroupRole == null )
{
groupType.DefaultGroupRole = groupType.Roles.FirstOrDefault();
}
rockContext.SaveChanges();
// Reload the roles and apply their attribute values
foreach ( var role in groupTypeRoleService.GetByGroupTypeId( groupType.Id ).ToList() )
{
role.LoadAttributes( rockContext );
var roleState = GroupTypeRolesState.Where( r => r.Guid.Equals( role.Guid ) ).FirstOrDefault();
if ( roleState != null && roleState.AttributeValues != null )
{
foreach ( var attributeValue in roleState.AttributeValues )
{
role.SetAttributeValue( attributeValue.Key, roleState.GetAttributeValue( attributeValue.Key ) );
}
role.SaveAttributeValues( rockContext );
}
}
} );
GroupTypeCache.Flush( groupType.Id );
NavigateToParentPage();
}
示例15: lbSave_Click
/// <summary>
/// Handles the Click event of the lbSave 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 lbSave_Click( object sender, EventArgs e )
{
if ( Page.IsValid )
{
RockContext rockContext = new RockContext();
BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService( rockContext );
BenevolenceResultService benevolenceResultService = new BenevolenceResultService( rockContext );
BenevolenceRequest benevolenceRequest = null;
int benevolenceRequestId = PageParameter( "BenevolenceRequestId" ).AsInteger();
if ( !benevolenceRequestId.Equals( 0 ) )
{
benevolenceRequest = benevolenceRequestService.Get( benevolenceRequestId );
}
if ( benevolenceRequest == null )
{
benevolenceRequest = new BenevolenceRequest { Id = 0 };
}
benevolenceRequest.FirstName = dtbFirstName.Text;
benevolenceRequest.LastName = dtbLastName.Text;
benevolenceRequest.Email = ebEmail.Text;
benevolenceRequest.RequestText = dtbRequestText.Text;
benevolenceRequest.ResultSummary = dtbSummary.Text;
benevolenceRequest.CampusId = cpCampus.SelectedCampusId;
benevolenceRequest.ProvidedNextSteps = dtbProvidedNextSteps.Text;
benevolenceRequest.GovernmentId = dtbGovernmentId.Text;
if ( lapAddress.Location != null )
{
benevolenceRequest.LocationId = lapAddress.Location.Id;
}
benevolenceRequest.RequestedByPersonAliasId = ppPerson.PersonAliasId;
benevolenceRequest.CaseWorkerPersonAliasId = ddlCaseWorker.SelectedValue.AsIntegerOrNull();
benevolenceRequest.RequestStatusValueId = ddlRequestStatus.SelectedValue.AsIntegerOrNull();
benevolenceRequest.ConnectionStatusValueId = ddlConnectionStatus.SelectedValue.AsIntegerOrNull();
if ( dpRequestDate.SelectedDate.HasValue )
{
benevolenceRequest.RequestDateTime = dpRequestDate.SelectedDate.Value;
}
benevolenceRequest.HomePhoneNumber = pnbHomePhone.Number;
benevolenceRequest.CellPhoneNumber = pnbCellPhone.Number;
benevolenceRequest.WorkPhoneNumber = pnbWorkPhone.Number;
List<BenevolenceResultInfo> resultListUI = BenevolenceResultsState;
var resultListDB = benevolenceRequest.BenevolenceResults.ToList();
// remove any Benevolence Results that were removed in the UI
foreach ( BenevolenceResult resultDB in resultListDB )
{
if ( !resultListUI.Any( r => r.ResultId == resultDB.Id ) )
{
benevolenceRequest.BenevolenceResults.Remove( resultDB );
benevolenceResultService.Delete( resultDB );
}
}
// add any Benevolence Results that were added in the UI
foreach ( BenevolenceResultInfo resultUI in resultListUI )
{
var resultDB = resultListDB.FirstOrDefault( r => r.Guid == resultUI.TempGuid );
if ( resultDB == null )
{
resultDB = new BenevolenceResult();
resultDB.BenevolenceRequestId = benevolenceRequest.Id;
resultDB.Guid = resultUI.TempGuid;
benevolenceRequest.BenevolenceResults.Add( resultDB );
}
resultDB.Amount = resultUI.Amount;
resultDB.ResultSummary = resultUI.ResultSummary;
resultDB.ResultTypeValueId = resultUI.ResultTypeValueId;
}
if ( benevolenceRequest.IsValid )
{
if ( benevolenceRequest.Id.Equals( 0 ) )
{
benevolenceRequestService.Add( benevolenceRequest );
}
// get attributes
benevolenceRequest.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, benevolenceRequest );
rockContext.WrapTransaction( () =>
{
rockContext.SaveChanges();
benevolenceRequest.SaveAttributeValues( rockContext );
} );
//.........这里部分代码省略.........