public static void AddChanges( RockContext rockContext, Type modelType, Guid categoryGuid, int entityId, List<string> changes, string caption, Type relatedModelType, int? relatedEntityId, int? modifiedByPersonAliasId = null )
{
var entityType = EntityTypeCache.Read( modelType );
var category = CategoryCache.Read( categoryGuid );
var creationDate = RockDateTime.Now;
int? relatedEntityTypeId = null;
if ( relatedModelType != null )
{
var relatedEntityType = EntityTypeCache.Read( relatedModelType );
if ( relatedModelType != null )
{
relatedEntityTypeId = relatedEntityType.Id;
}
}
if ( entityType != null && category != null )
{
var historyService = new HistoryService( rockContext );
foreach ( string message in changes.Where( m => m != null && m != "" ) )
{
var history = new History();
history.EntityTypeId = entityType.Id;
history.CategoryId = category.Id;
history.EntityId = entityId;
history.Caption = caption.Truncate(200);
history.Summary = message;
history.RelatedEntityTypeId = relatedEntityTypeId;
history.RelatedEntityId = relatedEntityId;
if ( modifiedByPersonAliasId.HasValue )
{
history.CreatedByPersonAliasId = modifiedByPersonAliasId;
}
// Manually set creation date on these history items so that they will be grouped together
history.CreatedDateTime = creationDate;
historyService.Add( history );
}
}
}