/// <summary> /// Commits one action of the transaction. /// </summary> /// <param name="userContext">The user context.</param> /// <param name="transac">The transac.</param> /// <param name="index">The index.</param> /// <param name="action">The action.</param> protected override void CommitAction(IUserContext userContext, TransacInfo transac, int index, TransacActionInfo action) { object referenceObject = null; if (action.Type == TransacActionType.Insert) { referenceObject = action.TargetInstance; } else { referenceObject = action.SourceInstance; } IMetamodelEntity metamodelEntity = IoC.Get <ISecurityManager>().MetamodelManager.GetEntity(referenceObject.GetType()); if (metamodelEntity != null) { if (metamodelEntity.AuditType == AuditType.Simple) { AuditTransacAction actionEntity = new AuditTransacAction(); actionEntity.AuditTransacId = Convert.ToInt32(transac.TransacId); actionEntity.AuditTransacActionIx = index + 1; actionEntity.EntityId = metamodelEntity.EntId; actionEntity.PrimaryKey = metamodelEntity.GetStringKey(referenceObject); userContext.Context.Add(actionEntity); } } }
/// <summary> /// Closes the current transaction. /// </summary> public void Close() { if (this.Context != null) { this.Context.Dispose(); this.Context = null; this.Transaction = null; } }
/// <summary> /// Commits the transaction information. /// </summary> /// <param name="userContext">The user context.</param> /// <param name="transac">The transaction information.</param> protected override void CommitTransac(IUserContext userContext, TransacInfo transac) { if (transac.Actions.Count > 0) { AuditTransac transacEntity = new AuditTransac(); transacEntity.UserId = Convert.ToInt32(transac.UserId); transacEntity.StartDttm = transac.StartDateTime; transacEntity.EndDttm = transac.EndDateTime; userContext.Context.Add(transacEntity); userContext.Context.FlushChanges(); transac.TransacId = transacEntity.AuditTransacId; } }
/// <summary> /// Opens a new transaction. /// </summary> public void Open() { this.Close(); this.Context = (OpenAccessContext)Activator.CreateInstance(IoC.Get <ISecurityManager>().ContextType); this.Transaction = IoC.Get <IAuditManager>().StartTransaction(this); }
/// <summary> /// Initializes a new instance of the <see cref="UserContext"/> class. /// </summary> /// <param name="user">The user.</param> public UserContext(IUserDto user) { this.Context = null; this.Transaction = null; this.User = user; }