/// <summary> /// Called before the save operation is executed. /// </summary> protected override void PreSave() { var auth = this.Entity as Auth; var rockContext = this.RockContext; if (rockContext != null && (State == EntityContextState.Added || State == EntityContextState.Modified || State == EntityContextState.Deleted)) { var authAuditLogService = new AuthAuditLogService(rockContext); var authAuditLog = new AuthAuditLog(); authAuditLog.EntityTypeId = auth.EntityTypeId; authAuditLog.EntityId = auth.EntityId; authAuditLog.Action = auth.Action; authAuditLog.ChangeDateTime = RockDateTime.Now; authAuditLog.SpecialRole = auth.SpecialRole; var currentPersonAlias = rockContext.GetCurrentPersonAlias(); if (currentPersonAlias != null) { authAuditLog.ChangeByPersonAliasId = currentPersonAlias.Id; } authAuditLogService.Add(authAuditLog); if (State == EntityContextState.Added) { authAuditLog.GroupId = auth.GroupId; authAuditLog.PersonAliasId = auth.PersonAliasId; authAuditLog.ChangeType = ChangeType.Add; } else if (State == EntityContextState.Modified) { authAuditLog.GroupId = auth.GroupId; authAuditLog.PersonAliasId = auth.PersonAliasId; authAuditLog.ChangeType = ChangeType.Modify; } else { authAuditLog.GroupId = this.Entry.OriginalValues[nameof(Auth.GroupId)] as int?; authAuditLog.PersonAliasId = this.Entry.OriginalValues[nameof(Auth.PersonAliasId)] as int?; authAuditLog.ChangeType = ChangeType.Delete; } if (State == EntityContextState.Added || State == EntityContextState.Modified) { authAuditLog.PostAllowOrDeny = auth.AllowOrDeny; authAuditLog.PostOrder = auth.Order; } if (State == EntityContextState.Modified || State == EntityContextState.Deleted) { authAuditLog.PreAllowOrDeny = this.Entry.OriginalValues[nameof(Auth.AllowOrDeny)] as string; authAuditLog.PreOrder = this.Entry.OriginalValues[nameof(Auth.Order)] as int?; } } base.PreSave(); }
/// <summary> /// Clones this AuthAuditLog object to a new AuthAuditLog object /// </summary> /// <param name="source">The source.</param> /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param> /// <returns></returns> public static AuthAuditLog Clone(this AuthAuditLog source, bool deepCopy) { if (deepCopy) { return(source.Clone() as AuthAuditLog); } else { var target = new AuthAuditLog(); target.CopyPropertiesFrom(source); return(target); } }
/// <summary> /// Clones this AuthAuditLog object to a new AuthAuditLog object with default values for the properties in the Entity and Model base classes. /// </summary> /// <param name="source">The source.</param> /// <returns></returns> public static AuthAuditLog CloneWithoutIdentity(this AuthAuditLog source) { var target = new AuthAuditLog(); target.CopyPropertiesFrom(source); target.Id = 0; target.Guid = Guid.NewGuid(); target.ForeignKey = null; target.ForeignId = null; target.ForeignGuid = null; return(target); }
/// <summary> /// Copies the properties from another AuthAuditLog object to this AuthAuditLog object /// </summary> /// <param name="target">The target.</param> /// <param name="source">The source.</param> public static void CopyPropertiesFrom(this AuthAuditLog target, AuthAuditLog source) { target.Id = source.Id; target.Action = source.Action; target.ChangeByPersonAliasId = source.ChangeByPersonAliasId; target.ChangeDateTime = source.ChangeDateTime; target.ChangeType = source.ChangeType; target.EntityId = source.EntityId; target.EntityTypeId = source.EntityTypeId; target.ForeignGuid = source.ForeignGuid; target.ForeignKey = source.ForeignKey; target.GroupId = source.GroupId; target.PersonAliasId = source.PersonAliasId; target.PostAllowOrDeny = source.PostAllowOrDeny; target.PostOrder = source.PostOrder; target.PreAllowOrDeny = source.PreAllowOrDeny; target.PreOrder = source.PreOrder; target.SpecialRole = source.SpecialRole; target.Guid = source.Guid; target.ForeignId = source.ForeignId; }