📝 AuditDetail Class Documentation

Welcome to the comprehensive documentation for the AuditDetail domain class from the IrbyImaging.DomainClasses assembly. This file defines an Entity Framework–mapped entity used to capture detailed audit (tracking) information for user activities.


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Schema & Class Mapping
  4. Key Functional Areas
  5. Properties & Navigation
  6. UML Class Diagram
  7. Usage Examples
  8. Error Handling & Validation
  9. Third-Party Integrations
  10. Conclusion

🔎 Overview & Purpose

AuditDetail is a domain entity that represents a single audit record of user interactions within the Irby Imaging system. It is designed to:

  • Track who did what, when and where.
  • Log critical context such as area, controller, action, IP address, session details, and more.
  • Support security, compliance, diagnostics, and usage analytics.

📦 Dependencies & Technologies

  • .NET Framework / .NET Core
  • Entity Framework (Code First)
    • System.ComponentModel.DataAnnotations
    • System.ComponentModel.DataAnnotations.Schema
  • C# 7.0+
  • SQL Server (via EF schema mapping)

🏗 Schema & Class Mapping

namespace IrbyImaging.DomainClasses
{
    [Table("AuditDetail", Schema = "irby")]
    public class AuditDetail
    {
        // ...
    }
}
  • Table: irby.AuditDetail
  • Primary Key: AuditDetailId (no database generation)
  • Mapping Attributes:
    • [Table] — maps the class to a database table
    • [Key], [DatabaseGenerated] — configures PK behavior
    • [ForeignKey] — links to Employee and Role

🧩 Key Functional Areas

  1. Identification
    • AuditDetailId uniquely identifies each audit record.
  2. Routing Context
    • Area, ControllerName, ActionName, Namespace
  3. Authentication Context
    • UserId, EmployeeId, RoleId, navigation to Employee & Role
  4. Localization & Session
    • LangId, SessionId, IsFirstLogin
  5. Network Context
    • IpAddress, UrlReferrer, PageAccessed
  6. Timing
    • ActivityDate, LastSignInDateTime, LastNonInteractiveSignInDateTime
  7. Status & Metadata
    • LoginStatus, DocumentImageId, EmployeeEmail

🔍 Properties & Navigation

Property Type Nullable Description
AuditDetailId 🔑 Guid No Primary key, must be provided by application.
Area string Yes MVC Area where action was executed.
ControllerName string Yes MVC Controller name.
ActionName string Yes MVC Action method name.
Namespace string Yes CLR namespace of the controller.
UserId Guid No ID of the authenticated user.
EmployeeId Guid No FK to the Employee table.
RoleId Guid? Yes FK to the Role table (nullable).
User  (navigation) Employee — Navigation to the employee record.
Role  (navigation) Role — Navigation to the role record.
LangId string Yes Language/culture code (e.g., en-US).
IpAddress string Yes Source IP of the request.
IsFirstLogin string Yes Flag (“true”/“false”) if this is the user’s first login.
ActivityDate DateTime No Exact timestamp of the action.
LoginStatus string Yes Status of the login attempt (e.g., Success, Fail).
PageAccessed string Yes URL or view name accessed.
SessionId string Yes ASP.NET Session ID.
UrlReferrer string Yes Referrer URL of the request.
DocumentImageId Guid? Yes Optional FK to a captured document image.
LastSignInDateTime DateTime? Yes Last interactive sign-in timestamp.
LastNonInteractiveSignInDateTime DateTime? Yes Last background/token sign-in timestamp.
EmployeeEmail string Yes Cached user email address.

📐 UML Class Diagram

classDiagram
    IrbyImaging.DomainClasses.AuditDetail <|-- IrbyImaging.DomainClasses.Employee : EmployeeId
    IrbyImaging.DomainClasses.AuditDetail <|-- IrbyImaging.DomainClasses.Role     : RoleId

    class IrbyImaging.DomainClasses.AuditDetail {
        +Guid AuditDetailId
        +string Area
        +string ControllerName
        +string ActionName
        +string Namespace
        +Guid UserId
        +Guid EmployeeId
        +Guid? RoleId
        +string LangId
        +string IpAddress
        +string IsFirstLogin
        +DateTime ActivityDate
        +string LoginStatus
        +string PageAccessed
        +string SessionId
        +string UrlReferrer
        +Guid? DocumentImageId
        +DateTime? LastSignInDateTime
        +DateTime? LastNonInteractiveSignInDateTime
        +string EmployeeEmail
    }

🚀 Usage Examples

1. Adding a New Audit Record

using (var context = new IrbyDbContext())
{
    var audit = new AuditDetail
    {
        AuditDetailId = Guid.NewGuid(),
        Area = "Admin",
        ControllerName = "Patient",
        ActionName = "Upload",
        Namespace = "IrbyImaging.Controllers.Admin",
        UserId = currentUserId,
        EmployeeId = currentEmployeeId,
        RoleId = currentRoleId,
        LangId = "en-US",
        IpAddress = httpContext.Connection.RemoteIpAddress.ToString(),
        IsFirstLogin = "false",
        ActivityDate = DateTime.UtcNow,
        LoginStatus = "Success",
        PageAccessed = "/Admin/Patient/Upload",
        SessionId = httpContext.Session.Id,
        UrlReferrer = httpContext.Request.Headers["Referer"].ToString(),
        DocumentImageId = uploadedImageId,
        LastSignInDateTime = lastSignIn,
        EmployeeEmail = currentUserEmail
    };

    context.AuditDetails.Add(audit);
    context.SaveChanges();
}

2. Querying Audit Details by User

var logs = context.AuditDetails
                  .Where(a => a.EmployeeId == currentEmployeeId)
                  .OrderByDescending(a => a.ActivityDate)
                  .Take(50)
                  .ToList();

⚠️ Error Handling & Validation

  • Required Fields: AuditDetailId, UserId, EmployeeId, and ActivityDate must always be provided.
  • Foreign Keys:
    • EmployeeId must correspond to an existing Employee.
    • RoleId (if set) must correspond to an existing Role.
  • Transaction Handling: Wrap Add/SaveChanges in try/catch to log DB exceptions.
try
{
    context.SaveChanges();
}
catch (DbUpdateException ex)
{
    // Log exception details, possibly retry or escalate
    throw;
}

🔗 Third-Party Integrations

  • No direct 3rd-party libraries in this class. However, the entity may be consumed by:
    • Logging frameworks (e.g., Serilog)
    • Analytics tools
    • Custom audit services

🏁 Conclusion

The AuditDetail class is a robust, EF‑mapped entity for capturing detailed user activity in the Irby Imaging system. By leveraging its comprehensive properties—ranging from routing context to network metadata—you can build powerful auditing, monitoring, and compliance features.

Whether you’re debugging an issue, analyzing user behavior, or ensuring regulatory compliance, AuditDetail offers the schema and flexibility needed to store and retrieve a rich audit trail. Feel free to extend this class with additional properties (e.g., device info, geolocation) or integrate it with your preferred logging/analytics stack.

Happy auditing! 🚀