Rock.Model.HistoryService.AddChanges C# (CSharp) Method

AddChanges() public static method

Adds the changes.
public static AddChanges ( RockContext rockContext, Type modelType, System.Guid categoryGuid, int entityId, List changes, string caption, Type relatedModelType, int relatedEntityId, int modifiedByPersonAliasId = null ) : void
rockContext Rock.Data.RockContext The rock context.
modelType System.Type Type of the model.
categoryGuid System.Guid The category unique identifier.
entityId int The entity identifier.
changes List The changes.
caption string The caption.
relatedModelType System.Type Type of the related model.
relatedEntityId int The related entity identifier.
modifiedByPersonAliasId int The modified by person alias identifier.
return void
        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 );
                }
            }
        }

Same methods

HistoryService::AddChanges ( RockContext rockContext, Type modelType, System.Guid categoryGuid, int entityId, List changes, int modifiedByPersonAliasId = null ) : void