๐Ÿ“š AssetHistory.cs Documentation


๐Ÿ—‚๏ธ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. Data Model: AssetHistory
    4.1. Class Diagram (UML)
    4.2. Property Details
  5. Usage Examples
    5.1. Creating a History Record
    5.2. Querying Asset History
  6. Integration with Entity Framework Core
  7. Conclusion
  8. Appendix: UML Diagram Source

๐Ÿ” Overview & Purpose

The AssetHistory class represents a historical audit log entry for digital assets managed by IrbyImaging. Whenever an assetโ€™s state changesโ€”such as ownership transfers, status updates, or metadata modificationsโ€”a new AssetHistory record is created. This ensures a full chronological trail for debugging, compliance, or simply understanding asset lifecycle events.

  • Assembly: IrbyImaging.DomainClasses
  • Schema: irby.AssetHistory
  • Created/Modified: March 31st, 2022 by kvamshi

๐Ÿ”‘ Key Functional Areas

  • Audit Logging: Captures who did what and when for each asset.
  • Versioning: Stores serialized snapshots of asset properties.
  • Traceability: Provides complete change history for compliance.

๐Ÿ“ฆ Dependencies & Technologies

Technology Purpose
.NET System namespace Fundamental types (e.g., Guid, DateTimeOffset)
System.ComponentModel.DataAnnotations Data validation & display attributes
System.ComponentModel.DataAnnotations.Schema EF Core schema mapping
Entity Framework Core ORM for database operations

๐Ÿ“Š Data Model: AssetHistory

Class Definition

[Table("AssetHistory", Schema = "irby")]
public class AssetHistory
{
    [Key]
    public Guid Id { get; set; }
    public Guid AssetId { get; set; }
    public DateTimeOffset Timestamp { get; set; }
    public string Status { get; set; }
    public Guid OwnerId { get; set; }
    public string Owner { get; set; }
    public string Action { get; set; }
    public string Reason { get; set; }
    [Display(Name = "Modified By")]
    public string ModifiedBy { get; set; }
    public string SerializedProperties { get; set; }
}

4.1 Class Diagram (UML) ๐ŸŽจ

@startuml
class AssetHistory {
  +Guid Id
  +Guid AssetId
  +DateTimeOffset Timestamp
  +string Status
  +Guid OwnerId
  +string Owner
  +string Action
  +string Reason
  +string ModifiedBy
  +string SerializedProperties
}
@enduml

Figure: Simple UML representation of the AssetHistory entity.

4.2 Property Details

Property Type Description
Id ๐Ÿ”‘ Guid Primary key โ€” unique history record identifier.
AssetId Guid Foreign key โ€” identifies the associated asset.
Timestamp โฐ DateTimeOffset When the event occurred (UTC-aware).
Status ๐Ÿ“ˆ string New status of the asset (e.g., โ€œCheckedInโ€, โ€œArchivedโ€).
OwnerId ๐Ÿ‘ค Guid ID of the new asset owner.
Owner ๐Ÿ‘ฅ string Name or descriptor of the owner.
Action โš™๏ธ string Type of operation performed (e.g., โ€œUpdateโ€, โ€œTransferโ€).
Reason ๐Ÿ“ string Optional rationale for the change.
ModifiedBy โœ๏ธ string Username or ID of the actor who performed the action.
SerializedProperties ๐Ÿ“ฆ string JSON/XML snapshot of assetโ€™s properties before or after.

๐Ÿ› ๏ธ Usage Examples

5.1 Creating a History Record

// 1. Prepare a new audit entry
var historyEntry = new AssetHistory {
    Id = Guid.NewGuid(),
    AssetId = existingAsset.Id,
    Timestamp = DateTimeOffset.UtcNow,
    Status = "CheckedOut",
    OwnerId = user.Id,
    Owner = user.FullName,
    Action = "Checkout",
    Reason = "Routine maintenance",
    ModifiedBy = user.Username,
    SerializedProperties = JsonConvert.SerializeObject(existingAsset)
};

// 2. Save via EF Core DbContext
dbContext.AssetHistories.Add(historyEntry);
await dbContext.SaveChangesAsync();

Tip: Use JsonConvert.SerializeObject(...) (Newtonsoft.Json) to capture a full snapshot.


5.2 Querying Asset History

// Retrieve the last 10 history events for a given asset
var logs = await dbContext.AssetHistories
    .Where(h => h.AssetId == targetAssetId)
    .OrderByDescending(h => h.Timestamp)
    .Take(10)
    .ToListAsync();

foreach(var log in logs) {
    Console.WriteLine($"{log.Timestamp:u} | {log.Action} by {log.ModifiedBy}");
}

๐Ÿ› ๏ธ Integration with Entity Framework Core

  1. DbContext Registration

    public class ImagingContext : DbContext
    {
        public DbSet<AssetHistory> AssetHistories { get; set; }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<AssetHistory>()
                .ToTable("AssetHistory", schema: "irby");
            base.OnModelCreating(modelBuilder);
        }
    }
    
  2. Migrations

    dotnet ef migrations add AddAssetHistoryTable
    dotnet ef database update
    

๐Ÿ Conclusion

The AssetHistory entity is a critical component for tracing the lifecycle of imaging assets within the IrbyImaging platform. By capturing who, what, when, and why, it enables:

  • Full audit trails for regulatory compliance.
  • Debugging of state transitions.
  • Analytical reporting on asset usage patterns.

Implement this class as part of your DbContext and start tracking every meaningful change!


๐Ÿ“Ž Appendix: UML Diagram Source

@startuml
class AssetHistory {
  +Guid Id
  +Guid AssetId
  +DateTimeOffset Timestamp
  +string Status
  +Guid OwnerId
  +string Owner
  +string Action
  +string Reason
  +string ModifiedBy
  +string SerializedProperties
}
@enduml

Feel free to copy, modify, and embed this PlantUML snippet into your documentation tooling!