📑 AuditReport (IrbyImaging.DomainClasses)
Welcome to the detailed documentation for the AuditReport class in the IrbyImaging.DomainClasses project. This class represents a keyless Entity Framework Core data model used for exposing audit log information (often from a database view or stored procedure).
📋 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Model
4.1. UML Class Diagram
4.2. Properties Reference Table - Usage Examples
5.1. EF Core Configuration
5.2. Querying Audit Reports - Sample Code Snippets
- Conclusion
1. Overview & Purpose
💡 AuditReport is a plain-old CLR object (POCO) that models a single audit log entry.
- It is decorated with the
[Keyless]attribute to indicate that it has no primary key—typical when mapping to a database view or the result set of a stored procedure. - It surfaces user activities such as page accessed, login status, and timestamps.
Intended Use
- Generating reports of user activities
- Feeding audit dashboards
- Exporting or analyzing security logs
2. Dependencies & Technologies
| Technology / Package | Purpose |
|---|---|
| Microsoft.EntityFrameworkCore | ORM for mapping the class to a database query |
| .NET Standard / .NET Core | Target runtime framework |
| C# 8.0+ | Language features (auto-properties, attributes) |
3. Key Functional Areas
- Data Modeling
Defines the shape of an audit log record for EF Core. - Keyless Entity Mapping
Uses EF Core’s[Keyless]attribute to signal “no primary key.” - Read-Only Reporting
Ideal for queries returning aggregated or computed data.
4. Data Model
4.1. UML Class Diagram
classDiagram
class AuditReport {
<<Keyless>>
+string JdeNumber
+string FirstName
+string LastName
+string Role
+string Department
+string Controller
+string Action
+string IpAddress
+string ActivityDate
+string LoginStatus
+string PageAccessed
+string DocumentImageId
+string LastNonInteractiveSignInDateTime
+string LastSignInDateTime
+string EmployeeEmail
}
4.2. Properties Reference Table
| Property | Type | Description |
|---|---|---|
JdeNumber |
string | JDE (ERP) employee number |
FirstName |
string | User’s first name |
LastName |
string | User’s last name |
Role |
string | Application role (e.g., Admin, User) |
Department |
string | User’s department or business unit |
Controller |
string | MVC Controller name or API area |
Action |
string | Action name (e.g., Login, ViewDocument) |
IpAddress |
string | Source IP address |
ActivityDate |
string | Timestamp of the activity (string for formatted output) |
LoginStatus |
string | Success / Failure / LockedOut, etc. |
PageAccessed |
string | URL or view name accessed |
DocumentImageId |
string | Identifier of the document or image involved |
LastNonInteractiveSignInDateTime |
string | Last background sign-in timestamp |
LastSignInDateTime |
string | Last user-initiated sign-in timestamp |
EmployeeEmail |
string | User’s corporate email address |
5. Usage Examples
5.1. EF Core Configuration
🔧 Registering the keyless entity in your DbContext:
public class AppDbContext : DbContext
{
public DbSet<AuditReport> AuditReports { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<AuditReport>()
.HasNoKey() // Mark as keyless
.ToView("vw_AuditReportLogs"); // Map to a database view
}
}
5.2. Querying Audit Reports
✅ Simple LINQ Query:
using(var ctx = new AppDbContext())
{
var recentFailures = ctx.AuditReports
.Where(a => a.LoginStatus == "Failure" &&
DateTime.Parse(a.ActivityDate) >= DateTime.Today.AddDays(-7))
.OrderByDescending(a => a.ActivityDate)
.ToList();
}
🔧 Raw SQL / Stored Procedure:
var param = new SqlParameter("@Department", "Finance");
var logs = ctx.AuditReports
.FromSqlRaw("EXEC dbo.usp_GetAuditLogsByDept @Department", param)
.ToList();
6. Sample Code Snippets
// 1. Print a summary of audit logs by user
var summary = ctx.AuditReports
.GroupBy(a => a.EmployeeEmail)
.Select(g => new {
Email = g.Key,
TotalActions = g.Count(),
LastSeen = g.Max(a => a.LastSignInDateTime)
})
.ToList();
foreach(var item in summary)
{
Console.WriteLine($"{item.Email} performed {item.TotalActions} actions; Last sign-in: {item.LastSeen}");
}
7. Conclusion
🎯 The AuditReport class is a read-only, keyless EF Core entity designed to surface detailed audit information for security, compliance, and reporting needs. By mapping to a database view or stored procedure, it allows developers to:
- Quickly query and analyze user activity
- Integrate audit data into dashboards & exports
- Keep domain models separate from underlying storage
Feel free to extend this model with additional properties or computed fields as requirements evolve. Happy auditing! 🚀
End of AuditReport documentation.