public void AddToHistory(IProcessExecutionContext executionContext, IWorkSession session, IProcessStep processStep, bool isExecuted)
        {
            if (executionContext is null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (session is null)
            {
                throw new ArgumentNullException("workSession");
            }
            if (processStep is null)
            {
                throw new ArgumentNullException("processStep");
            }

            var lastHistory        = this.Records.LastOrDefault();
            var lastCurrentHistory = this.Records.Where(r => r.StepStatus == eProcessStepHistoryStatusEnum.Current).LastOrDefault();

            //create a new history record for the passed in process step and
            //link it back to last current history step in the list.
            var newHistory = DataConnector.CreateStepHistoryRecord(
                executionContext.DataService,
                this.Transaction,
                processStep,
                lastCurrentHistory);

            this.Records.Add(new StepHistory(newHistory));

            // Update the starting history in the database.
            if (lastHistory != null)
            {
                //Update local copy.
                lastHistory.NextStepId    = newHistory;
                lastHistory.CompletedById = isExecuted ? session.Agent : null;
                lastHistory.CompletedAtId = isExecuted ? session.Location : null;

                //update database.
                DataConnector.UpdateStepHistoryRecord(
                    executionContext.DataService,
                    lastHistory,
                    newHistory,
                    isExecuted ? session.Agent : null,
                    isExecuted ? session.Location : null,
                    isExecuted ? (DateTime?)DateTime.Now : null);
            }
        }