示例#1
0
 /// <summary>
 /// Set the SourceOfChange property for the entries in a HistoryChangeList.
 /// </summary>
 /// <param name="changes"></param>
 /// <param name="newSourceOfChange"></param>
 /// <param name="overrideExisting"></param>
 private static void SetHistoryEntriesSourceOfChange(History.HistoryChangeList changes, string newSourceOfChange, bool overrideExisting)
 {
     // Set the SourceOfChange property for any entries that do not have an existing value, or for all entries if the override flag is set.
     changes.Where(x => x.SourceOfChange == null || overrideExisting)
     .ToList()
     .ForEach(a => a.SourceOfChange = newSourceOfChange);
 }
示例#2
0
        /// <summary>
        /// Gets the changes.
        /// </summary>
        /// <param name="modelType">Type of the model.</param>
        /// <param name="categoryGuid">The category unique identifier.</param>
        /// <param name="entityId">The entity identifier.</param>
        /// <param name="changes">The changes.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="relatedModelType">Type of the related model.</param>
        /// <param name="relatedEntityId">The related entity identifier.</param>
        /// <param name="modifiedByPersonAliasId">The modified by person alias identifier.</param>
        /// <param name="sourceOfChange">The source of change.</param>
        /// <returns></returns>
        internal static List <History> GetChanges(Type modelType, Guid categoryGuid, int entityId, History.HistoryChangeList changes, string caption, Type relatedModelType, int?relatedEntityId, int?modifiedByPersonAliasId, string sourceOfChange = null)
        {
            SetHistoryEntriesSourceOfChange(changes, sourceOfChange, sourceOfChange != null);

            var entityType   = EntityTypeCache.Get(modelType);
            var category     = CategoryCache.Get(categoryGuid);
            var creationDate = RockDateTime.Now;

            int?relatedEntityTypeId = null;

            if (relatedModelType != null)
            {
                var relatedEntityType = EntityTypeCache.Get(relatedModelType);
                if (relatedModelType != null)
                {
                    relatedEntityTypeId = relatedEntityType.Id;
                }
            }

            List <History> historyRecordsToInsert = new List <History>();

            if (entityType != null && category != null)
            {
                foreach (var historyChange in changes.Where(m => m != null))
                {
                    var history = new History();
                    history.EntityTypeId        = entityType.Id;
                    history.CategoryId          = category.Id;
                    history.EntityId            = entityId;
                    history.Caption             = caption.Truncate(200);
                    history.RelatedEntityTypeId = relatedEntityTypeId;
                    history.RelatedEntityId     = relatedEntityId;

                    historyChange.CopyToHistory(history);

                    if (modifiedByPersonAliasId.HasValue)
                    {
                        history.CreatedByPersonAliasId = modifiedByPersonAliasId;
                    }

                    // If not specified, manually set the creation date on these history items so that they will be grouped together.
                    if (historyChange.ChangedDateTime == null)
                    {
                        history.CreatedDateTime = creationDate;
                    }

                    historyRecordsToInsert.Add(history);
                }
            }

            return(historyRecordsToInsert);
        }
示例#3
0
        /// <summary>
        /// Adds the changes.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="modelType">Type of the model.</param>
        /// <param name="categoryGuid">The category unique identifier.</param>
        /// <param name="entityId">The entity identifier.</param>
        /// <param name="changes">The changes.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="relatedModelType">Type of the related model.</param>
        /// <param name="relatedEntityId">The related entity identifier.</param>
        /// <param name="modifiedByPersonAliasId">The modified by person alias identifier.</param>
        public static void AddChanges(RockContext rockContext, Type modelType, Guid categoryGuid, int entityId, History.HistoryChangeList changes, string caption, Type relatedModelType, int?relatedEntityId, int?modifiedByPersonAliasId = null)
        {
            var entityType   = EntityTypeCache.Get(modelType);
            var category     = CategoryCache.Get(categoryGuid);
            var creationDate = RockDateTime.Now;

            int?relatedEntityTypeId = null;

            if (relatedModelType != null)
            {
                var relatedEntityType = EntityTypeCache.Get(relatedModelType);
                if (relatedModelType != null)
                {
                    relatedEntityTypeId = relatedEntityType.Id;
                }
            }

            if (entityType != null && category != null)
            {
                var historyService = new HistoryService(rockContext);

                foreach (var historyChange in changes.Where(m => m != null))
                {
                    var history = new History();
                    history.EntityTypeId        = entityType.Id;
                    history.CategoryId          = category.Id;
                    history.EntityId            = entityId;
                    history.Caption             = caption.Truncate(200);
                    history.RelatedEntityTypeId = relatedEntityTypeId;
                    history.RelatedEntityId     = relatedEntityId;

                    historyChange.CopyToHistory(history);

                    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);
                }
            }
        }