/// <summary> /// Initializes a new instance of the <see cref="ContextItem" /> class. /// </summary> /// <param name="entity">The entity.</param> /// <param name="dbEntityEntry">The database entity entry.</param> /// <param name="enableAuditing">if set to <c>true</c> [enable auditing].</param> public ContextItem(IEntity entity, DbEntityEntry dbEntityEntry, bool enableAuditing) { Entity = entity; DbEntityEntry = dbEntityEntry; if (enableAuditing) { Audit = new Audit(); switch (dbEntityEntry.State) { case EntityState.Added: { Audit.AuditType = AuditType.Add; break; } case EntityState.Deleted: { Audit.AuditType = AuditType.Delete; break; } case EntityState.Modified: { Audit.AuditType = AuditType.Modify; break; } } } PreSaveState = dbEntityEntry.State; if (dbEntityEntry.State == EntityState.Modified) { var triggers = WorkflowTriggersCache.Triggers(entity.TypeName) .Where(t => t.WorkflowTriggerType == WorkflowTriggerType.ImmediatePostSave || t.WorkflowTriggerType == WorkflowTriggerType.PostSave); if (triggers.Any()) { OriginalValues = new Dictionary <string, object>(); foreach (var p in DbEntityEntry.OriginalValues.PropertyNames) { OriginalValues.Add(p, DbEntityEntry.OriginalValues[p]); } } } }
/// <summary> /// Instantiates a new DTO object from the entity /// </summary> /// <param name="audit"></param> public AuditDto(Audit audit) { CopyFromModel(audit); }
/// <summary> /// To the dto. /// </summary> /// <param name="value">The value.</param> /// <returns></returns> public static AuditDto ToDto(this Audit value) { return(new AuditDto(value)); }