AuditArgs pArgs, AuditChangeType pChangeType, AuditConfig.AuditConfigProperty pAuditProperty)
{
//Check that the passed in EntityManager from the AuditEntity has the changes requested.
//This does return the one change.
System.Collections.Generic.List<IdeaBlade.EntityModel.Entity> aList = new List<IdeaBlade.EntityModel.Entity>();
aList.AddRange(pArgs.AuditableEntity.EntityAspect.EntityManager.FindEntities<IdeaBlade.EntityModel.Entity>(IbEm.EntityState.Modified));
aList.AddRange(pArgs.AuditableEntity.EntityAspect.EntityManager.FindEntities<IdeaBlade.EntityModel.Entity>(IbEm.EntityState.Added));
AuditValue newAudit = pArgs.AuditableEntity.EntityAspect.EntityManager.CreateEntity<AuditValue>();
// Must Generate an Id.
newAudit.EntityAspect[AuditValue.EntityPropertyNames.Id] = GetNextAuditId();
newAudit.EntityAspect.AddToManager();
newAudit.EntityPropertyId = pAuditProperty.Id;
newAudit.EntityPrimaryKey = pArgs.PrimaryKeyString;
newAudit.ModTs = pArgs.AuditTs;
newAudit.ModUserId = (int)pArgs.UserId;
//Added for Audit tracking
newAudit.Approved = pArgs.IsApproved;
// Remember: DataSet's DataColumn name is same as AuditProperty.PropertyName
string columnName = pAuditProperty.PropertyName;
switch (pChangeType)
{
case AuditChangeType.Added:
newAudit.Operation = "A";
newAudit.NewValue = pArgs.AuditableEntity.EntityAspect[columnName].ToString();
break;
case AuditChangeType.Deleted:
newAudit.Operation = "D";
newAudit.OldValue = pArgs.AuditableEntity.EntityAspect[columnName, IbEm.EntityVersion.Original].ToString();
break;
case AuditChangeType.Modified:
newAudit.Operation = "M";
newAudit.NewValue = pArgs.AuditableEntity.EntityAspect[columnName].ToString();
newAudit.OldValue = pArgs.AuditableEntity.EntityAspect[columnName, IbEm.EntityVersion.Original].ToString();
break;
default:
throw new InvalidOperationException("Unexpected change type creating Audit");
}
//reject new change if submitted change is not approved.
if (!newAudit.Approved && pChangeType != AuditChangeType.Added)
{
pArgs.AuditableEntity.EntityAspect[columnName] = pArgs.AuditableEntity.EntityAspect[columnName, IbEm.EntityVersion.Original];
}
//Verify that the one addition has been added to the AuditEntity EntityManager.
//Successfully does.
aList = new List<IdeaBlade.EntityModel.Entity>();
aList.AddRange(pArgs.AuditableEntity.EntityAspect.EntityManager.FindEntities<IdeaBlade.EntityModel.Entity>(IbEm.EntityState.Modified));
aList.AddRange(pArgs.AuditableEntity.EntityAspect.EntityManager.FindEntities<IdeaBlade.EntityModel.Entity>(IbEm.EntityState.Added));
return newAudit;
}