本文整理汇总了C#中Rock.Data.RockContext.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# RockContext.SaveChanges方法的具体用法?C# RockContext.SaveChanges怎么用?C# RockContext.SaveChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Data.RockContext
的用法示例。
在下文中一共展示了RockContext.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 );
} );
}
示例2: Get
/// <summary>
/// Gets the specified <see cref="Rock.Model.EntityType"/> by the object type. If a match is not found, it can optionally create a new <see cref="Rock.Model.EntityType"/> for the object.
/// </summary>
/// <param name="type">The <see cref="System.Type"/> to search for.</param>
/// <param name="createIfNotFound">A <see cref="System.Boolean"/> value that indicates if a new <see cref="Rock.Model.EntityType"/> should be created if a match is not found. This value
/// will be <c>true</c> if a new <see cref="Rock.Model.EntityType"/> should be created if there is not a match; otherwise <c>false</c>/</param>
/// <param name="personAlias">A <see cref="Rock.Model.PersonAlias"/> representing the alias of the <see cref="Rock.Model.Person"/> who is searching for and possibly creating a new EntityType. This value can be
/// null if the logged in person is not known (i.e. an anonymous user).</param>
/// <returns>A <see cref="Rock.Model.EntityType"/> matching the provided type. If a match is not found and createIfNotFound is false this value will be null.</returns>
public EntityType Get( Type type, bool createIfNotFound, PersonAlias personAlias )
{
var entityType = Get( type.FullName );
if ( entityType != null )
{
return entityType;
}
if ( createIfNotFound )
{
// Create a new context so type can be saved independing of current context
using ( var rockContext = new RockContext() )
{
var EntityTypeService = new EntityTypeService( rockContext );
entityType = new EntityType();
entityType.Name = type.FullName;
entityType.FriendlyName = type.Name.SplitCase();
entityType.AssemblyName = type.AssemblyQualifiedName;
EntityTypeService.Add( entityType );
rockContext.SaveChanges();
}
// Read type using current context
return this.Get( entityType.Id );
}
return null;
}
示例3: gGroupType_Delete
/// <summary>
/// Handles the Delete event of the gGroupType 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 gGroupType_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
GroupTypeService groupTypeService = new GroupTypeService( rockContext );
GroupType groupType = groupTypeService.Get( e.RowKeyId );
if ( groupType != null )
{
int groupTypeId = groupType.Id;
if ( !groupType.IsAuthorized( "Administrate", CurrentPerson ) )
{
mdGridWarning.Show( "Sorry, you're not authorized to delete this group type.", ModalAlertType.Alert );
return;
}
string errorMessage;
if ( !groupTypeService.CanDelete( groupType, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Alert );
return;
}
groupTypeService.Delete( groupType );
rockContext.SaveChanges();
GroupTypeCache.Flush( groupTypeId );
}
BindGrid();
}
示例4: 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;
}
示例5: mdEdit_SaveClick
/// <summary>
/// Handles the SaveClick event of the mdEdit 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 mdEdit_SaveClick( object sender, EventArgs e )
{
var rockContext = new RockContext();
EntityTypeService entityTypeService = new EntityTypeService( rockContext );
EntityType entityType = entityTypeService.Get( int.Parse( hfEntityTypeId.Value ) );
if ( entityType == null )
{
entityType = new EntityType();
entityType.IsEntity = true;
entityType.IsSecured = true;
entityTypeService.Add( entityType );
}
entityType.Name = tbName.Text;
entityType.FriendlyName = tbFriendlyName.Text;
entityType.IsCommon = cbCommon.Checked;
rockContext.SaveChanges();
EntityTypeCache.Flush( entityType.Id );
hfEntityTypeId.Value = string.Empty;
HideDialog();
BindGrid();
}
示例6: gCommunication_Delete
/// <summary>
/// Handles the Delete event of the gCommunication control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs"/> instance containing the event data.</param>
protected void gCommunication_Delete( object sender, Rock.Web.UI.Controls.RowEventArgs e )
{
var rockContext = new RockContext();
var service = new CommunicationTemplateService( rockContext );
var template = service.Get( e.RowKeyId );
if ( template != null )
{
if ( !template.IsAuthorized( Authorization.EDIT, this.CurrentPerson ) )
{
maGridWarning.Show( "You are not authorized to delete this template", ModalAlertType.Information );
return;
}
string errorMessage;
if ( !service.CanDelete( template, out errorMessage ) )
{
maGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
service.Delete( template );
rockContext.SaveChanges();
}
BindGrid();
}
示例7: bbtnDelete_Click
protected void bbtnDelete_Click( object sender, EventArgs e )
{
BootstrapButton bbtnDelete = (BootstrapButton)sender;
RepeaterItem riItem = (RepeaterItem)bbtnDelete.NamingContainer;
HiddenField hfScheduledTransactionId = (HiddenField)riItem.FindControl( "hfScheduledTransactionId" );
Literal content = (Literal)riItem.FindControl( "lLiquidContent" );
Button btnEdit = (Button)riItem.FindControl( "btnEdit" );
var rockContext = new Rock.Data.RockContext();
FinancialScheduledTransactionService fstService = new FinancialScheduledTransactionService( rockContext );
var currentTransaction = fstService.Get( Int32.Parse(hfScheduledTransactionId.Value) );
string errorMessage = string.Empty;
if ( fstService.Cancel( currentTransaction, out errorMessage ) )
{
rockContext.SaveChanges();
content.Text = String.Format( "<div class='alert alert-success'>Your recurring {0} has been deleted.</div>", GetAttributeValue( "TransactionLabel" ).ToLower() );
}
else
{
content.Text = String.Format( "<div class='alert alert-danger'>An error occured while deleting your scheduled transation. Message: {0}</div>", errorMessage );
}
bbtnDelete.Visible = false;
btnEdit.Visible = false;
}
示例8: CopyPage
/// <summary>
/// Copies the page.
/// </summary>
/// <param name="pageId">The page identifier.</param>
/// <param name="currentPersonAliasId">The current person alias identifier.</param>
public Guid? CopyPage( int pageId, int? currentPersonAliasId = null )
{
var rockContext = new RockContext();
var pageService = new PageService( rockContext );
Guid? newPageGuid = null;
var page = pageService.Get( pageId );
if ( page != null )
{
Dictionary<Guid, Guid> pageGuidDictionary = new Dictionary<Guid, Guid>();
Dictionary<Guid, Guid> blockGuidDictionary = new Dictionary<Guid, Guid>();
var newPage = GeneratePageCopy( page, pageGuidDictionary, blockGuidDictionary, currentPersonAliasId );
pageService.Add( newPage );
rockContext.SaveChanges();
if ( newPage.ParentPageId.HasValue )
{
PageCache.Flush( newPage.ParentPageId.Value );
}
newPageGuid= newPage.Guid;
GenerateBlockAttributeValues( pageGuidDictionary, blockGuidDictionary, rockContext, currentPersonAliasId );
GeneratePageBlockAuths( pageGuidDictionary, blockGuidDictionary, rockContext, currentPersonAliasId );
CloneHtmlContent( blockGuidDictionary, rockContext, currentPersonAliasId );
}
return newPageGuid;
}
示例9: gCampuses_Delete
/// <summary>
/// Handles the Delete event of the gCampuses 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 gCampuses_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
CampusService campusService = new CampusService( rockContext );
Campus campus = campusService.Get( e.RowKeyId );
if ( campus != null )
{
// Don't allow deleting the last campus
if ( !campusService.Queryable().Where( c => c.Id != campus.Id ).Any() )
{
mdGridWarning.Show( campus.Name + " is the only campus and cannot be deleted (Rock requires at least one campus).", ModalAlertType.Information );
return;
}
string errorMessage;
if ( !campusService.CanDelete( campus, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
CampusCache.Flush( campus.Id );
campusService.Delete( campus );
rockContext.SaveChanges();
}
BindGrid();
}
示例10: Execute
public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages)
{
errorMessages = new List<string>();
EntityTypeCache cachedEntityType = EntityTypeCache.Read(GetAttributeValue(action, "EntityType").AsGuid());
var propertyValues = GetAttributeValue(action, "EntityProperties").Replace(" ! ", " | ").ResolveMergeFields(GetMergeFields(action)).TrimEnd('|').Split('|').Select(p => p.Split('^')).Select(p => new { Name = p[0], Value = p[1] });
if (cachedEntityType != null)
{
Type entityType = cachedEntityType.GetEntityType();
IEntity newEntity = (IEntity)Activator.CreateInstance(entityType);
foreach (var prop in propertyValues)
{
PropertyInfo propInf = entityType.GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance);
if (null != propInf && propInf.CanWrite)
{
if (!(GetAttributeValue(action, "EmptyValueHandling") == "IGNORE" && String.IsNullOrWhiteSpace(prop.Value)))
{
try
{
propInf.SetValue(newEntity, ObjectConverter.ConvertObject(prop.Value, propInf.PropertyType, GetAttributeValue(action, "EmptyValueHandling") == "NULL"), null);
}
catch (Exception ex) when (ex is InvalidCastException || ex is FormatException || ex is OverflowException)
{
errorMessages.Add("Invalid Property Value: " + prop.Name + ": " + ex.Message);
}
}
}
else
{
errorMessages.Add("Invalid Property: " + prop.Name);
}
}
rockContext.Set(entityType).Add(newEntity);
rockContext.SaveChanges();
// If request attribute was specified, requery the request and set the attribute's value
Guid? entityAttributeGuid = GetAttributeValue(action, "EntityAttribute").AsGuidOrNull();
if (entityAttributeGuid.HasValue)
{
newEntity = (IEntity)rockContext.Set(entityType).Find(new object[] { newEntity.Id });
if (newEntity != null)
{
SetWorkflowAttributeValue(action, entityAttributeGuid.Value, newEntity.Guid.ToString());
}
}
return true;
}
else
{
errorMessages.Add("Invalid Entity Type");
}
return false;
}
示例11: SaveBankAccounts
/// <summary>
/// Saves the bank accounts.
/// </summary>
/// <param name="newBankAccounts">The new bank accounts.</param>
private static void SaveBankAccounts( List<FinancialPersonBankAccount> newBankAccounts )
{
using ( var rockContext = new RockContext() )
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.FinancialPersonBankAccounts.AddRange( newBankAccounts );
rockContext.SaveChanges( DisableAuditing );
}
}
示例12: SaveFinancialBatches
/// <summary>
/// Saves the financial batches.
/// </summary>
/// <param name="newBatches">The new batches.</param>
private static void SaveFinancialBatches( List<FinancialBatch> newBatches )
{
using ( var rockContext = new RockContext() )
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.FinancialBatches.AddRange( newBatches );
rockContext.SaveChanges( DisableAuditing );
}
}
示例13: SaveContributions
/// <summary>
/// Saves the contributions.
/// </summary>
/// <param name="newTransactions">The new transactions.</param>
private static void SaveContributions( List<FinancialTransaction> newTransactions )
{
using ( var rockContext = new RockContext() )
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.FinancialTransactions.AddRange( newTransactions );
rockContext.SaveChanges( DisableAuditing );
}
}
示例14: 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 );
} );
}
示例15: 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 );
} );
}