Ejemplo n.º 1
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Rock.Data.DbContext dbContext, EntityState state)
        {
            if (_logEntries != null)
            {
                if (_logEntries.Any())
                {
                    if (dbContext is RockContext)
                    {
                        var workflowLogService = new WorkflowLogService((dbContext as RockContext));
                        foreach (var logEntry in _logEntries)
                        {
                            workflowLogService.Add(new WorkflowLog {
                                LogDateTime = logEntry.LogDateTime, LogText = logEntry.LogText, WorkflowId = this.Id
                            });
                        }

                        _logEntries.Clear();
                    }
                }
            }

            // Set the workflow number
            if (state == EntityState.Added)
            {
                int maxNumber = new WorkflowService(dbContext as RockContext)
                                .Queryable().AsNoTracking()
                                .Where(w => w.WorkflowTypeId == this.WorkflowTypeId)
                                .Max(w => (int?)w.WorkflowIdNumber) ?? 0;
                this.WorkflowIdNumber = maxNumber + 1;
            }

            base.PreSaveChanges(dbContext, state);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
        {
            if (_logEntries != null)
            {
                if (_logEntries.Any())
                {
                    if (dbContext is RockContext)
                    {
                        var workflowLogService = new WorkflowLogService((dbContext as RockContext));
                        foreach (var logEntry in _logEntries)
                        {
                            workflowLogService.Add(new WorkflowLog {
                                LogDateTime = logEntry.LogDateTime, LogText = logEntry.LogText, WorkflowId = this.Id
                            });
                        }

                        _logEntries.Clear();
                    }
                }
            }

            base.PreSaveChanges(dbContext, state);
        }