public void SetEntityStageId(Entity entity, object stageId, string action, IDictionary <string, object> inputValues, TransitionLogHandler onLog) { entity.SetValue(StagePropertyGuid, stageId, true, true); if (HistoryConfiguration != null) { EntitySet historySet = entity.Connection.GetEntitySet(HistoryConfiguration.EntitySetGuid)?.CreateEntitySet(); if (historySet != null) { Entity historyItem = HistoryConfiguration.EntityTypeGuid == Guid.Empty ? historySet.CreateEntity(entity.Transaction) : historySet.CreateEntity(entity.Transaction, HistoryConfiguration.EntityTypeGuid); historyItem[HistoryConfiguration.StagePropertyGuid] = stageId; historyItem.Name = action; if (HistoryConfiguration.DateTimePropertyGuid != Guid.Empty) { historyItem[HistoryConfiguration.DateTimePropertyGuid] = DateTime.Now; } if (HistoryConfiguration.CommentPropertyGuid != Guid.Empty && inputValues.TryGetValue("Comment", out object comment)) { historyItem[HistoryConfiguration.CommentPropertyGuid] = comment?.ToString().Trim() ?? string.Empty; } if (HistoryConfiguration.ResponsibleLinkGuid != Guid.Empty) { historyItem.SetLinkedEntity(HistoryConfiguration.ResponsibleLinkGuid, entity.Connection.Workspace.GetUser(), entity.Transaction); } historyItem.SetLinkedEntity(HistoryConfiguration.OwnerLinkGuid, entity, entity.Transaction); onLog?.Invoke(entity, historyItem, inputValues); } } }
public IEntityWorkflowTransition OnLog(TransitionLogHandler handler) { _onLog = handler; return(this); }