๐ AssetHistory.cs Documentation
๐๏ธ Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- Data Model: AssetHistory
4.1. Class Diagram (UML)
4.2. Property Details - Usage Examples
5.1. Creating a History Record
5.2. Querying Asset History - Integration with Entity Framework Core
- Conclusion
- 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
AssetHistoryentity.
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
-
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); } } -
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!