Audit

Posts   
 
    
kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 07-Nov-2024 05:39:10   

I am using VS2022, v5.11.1.llblgenproj and net core 8

I have followed link https://www.llblgen.com/Documentation/5.9/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_auditing.htm

I have InkEmployee and InkEmployeeAudit table

namespace INK.TPS.Layers.BLL.Audit
{
    [DependencyInjectionInfo(typeof(InkEmployeeAuditEntity), "AuditorToUse")]
    [Serializable]

How I can do Audit?

 /// <summary>
 /// Audits the successful update of an existing entity in the database
 /// </summary>
 /// <param name="entity">The entity updated successfully in the database.</param>
 public override void AuditUpdateOfExistingEntity(IEntityCore entity)
 {
     var auditInfo = new INK.TPS.Layers.DAL.EntityClasses.InkEmployeeAuditEntity();

     auditInfo.EmaEmployeeId = entity.EmaEmployeeId; //CAST ISSUE 
...

     //auditInfo.AffectedEntityName = entity.LLBLGenProEntityName;
     //auditInfo.ActionDateTime = DateTime.Now;
     //auditInfo.ActionType = (int)AuditType.UpdateOfExistingEntity;
     _auditInfoEntities.Add(auditInfo);
 }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 07-Nov-2024 08:03:46   

The audit entity isn't necessarily the same as the entity it audits, you have to design it in such a way that it can contain the information you want to audit. Here you seem to want to store the ID of the entity that is updated, so you want to have the EmaEmployeeId of the auditinfo to have the same type as the entity that's updated. You say there's a cast issue, which is likely coming from the fact that entity is of type IEntityCore. So cast it first to the entity type it has, e.g. InkEmployeeEntity and then read the value, like:

auditInfo.EmaEmployeeId = ((InkEmployeeEntity)entity).EmaEmployeeId; 
Frans Bouma | Lead developer LLBLGen Pro
kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 08-Nov-2024 14:43:53   

Hi Frans,

I understand auditInfo.EmaEmployeeId = ((InkEmployeeEntity)entity).EmaEmployeeId but...

What I need to do in DI (please give .net core 8 code example)...

As I need to audit from scratch - what can I read and how to setup 1.2.3. from beginning would like to read so send me info.

My Audit table is...

CREATE TABLE [dbo].[inkEmployeeAudit]( [emaEmployeeAuditId] [INT] IDENTITY(1,1) NOT NULL, [emaEmployeeId] [INT] NOT NULL, [emaDateTime] [DATETIME] NOT NULL, [emaOperationGUID] [UNIQUEIDENTIFIER] NOT NULL, [emaAuditByFullName] VARCHAR NOT NULL, [emaAuditTypeId] [INT] NOT NULL, [emaEntityName] VARCHAR NOT NULL, [emaFieldName] VARCHAR NOT NULL, [emaData] VARCHAR NOT NULL, [emaAuditIsDeleted] [BIT] NOT NULL,

Also emaAuditByFullName is email address which is in UI how I will get from UI to entity?

kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 09-Nov-2024 03:54:52   

Also need to Audit particular table (and not all table). What should be done?

Below line is correct? [DependencyInjectionInfo(typeof(InkEmployeeAuditEntity), "AuditorToUse")]

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 09-Nov-2024 08:11:29   

I guess you've read https://www.llblgen.com/Documentation/5.11/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_auditing.htm#auditor-example ? The idea is that you fill additional entities inside the auditor object which are then persisted within the same transaction. You can also log data instead of creating entities, that's up to you. We also have an example on github: https://github.com/SolutionsDesign/LLBLGenProExamples_5.x/tree/master/Example_Auditing which shows this.

If you need to store information in your audit entity that's not available in the entity that's audited, you have to provide that yourself. E.g. if a user performs some action, the userid the user logged in with might not be available at the auditor level, so you have to store that somewhere e.g. in thread local storage, or other means which are reachable by the auditor.

Frans Bouma | Lead developer LLBLGen Pro
kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 12-Nov-2024 01:25:17   

Hi Otis,

OK.