π¦ Asset.cs Documentation
Assembly: IrbyImaging.DomainClasses
Namespace:IrbyImaging.DomainClasses
Author: kvamshi
Created: 03β31β2022
Last Modified: 03β31β2022
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- UML Class Diagram
- Asset Class β Properties
- Data Annotations & Validations
- Key Functional Areas
- Usage Examples
- Conclusion
π§ Overview & Purpose
The Asset class represents a tangible or intangible resource tracked by Irby Imaging. Think of laptops, cameras, software licenses, or any equipment owned, assigned, or managed by the company. This domain model is mapped to the database table irby.Asset and supports:
- π― Asset Lifecycle Tracking (purchase, status, compliance)
- π Ownership & Location (assigned to an employee or field office)
- π Reporting & Auditing (serial numbers, review flags, check-in timestamps)
π§ Dependencies & Technologies
| Dependency | Purpose |
|---|---|
System |
Base .NET types (e.g., Guid, DateTimeOffset). |
System.ComponentModel.DataAnnotations |
Declarative validation & metadata (e.g., [Key], [Required]). |
System.ComponentModel.DataAnnotations.Schema |
ORM mapping attributes (e.g., [Table(...)]). |
IrbyImaging.Utility |
Projectβwide utilities (e.g., AssetCategory, AssetStatus enums). |
| Entity Framework Core (implied) | ORM to map the class to a relational database. |
π UML Class Diagram
classDiagram
class Asset {
+Guid Id
+AssetCategory Category
+DateTimeOffset PurchaseDate
+AssetStatus Status
+int ModelId
+AssetModel Model
+Guid? OwnerId
+Employee Owner
+Guid? FieldOfficeId
+FieldOffice FieldOffice
+string SerialNumber
+string Notes
+bool NeedsReview
+string ComplianceStatus
+DateTime LastCheckIn
+string PrimaryUPN
}
Asset --> AssetModel : Model
Asset --> Employee : Owner
Asset --> FieldOffice: FieldOffice
π·οΈ Asset Class β Properties
| Property | Type | Annotations | Description |
|---|---|---|---|
| Id | Guid |
[Key] |
π Unique identifier for this asset. |
| Category | AssetCategory |
[Required] |
ποΈ Category (e.g., Hardware, Software). |
| PurchaseDate | DateTimeOffset |
[Required], [DataType(Date)] |
π When the asset was acquired. |
| Status | AssetStatus |
[Required] |
π Current state (e.g., Active, Retired). |
| ModelId | int |
[Required] |
π FK to the AssetModel table. |
| Model | AssetModel |
β | π Navigation property for the asset model. |
| OwnerId | Guid? |
β | π Optional FK to an Employee. |
| Owner | Employee |
β | π€ Navigation property to the employee. |
| FieldOfficeId | Guid? |
β | π’ Optional FK to a FieldOffice. |
| FieldOffice | FieldOffice |
β | π Navigation property to the field office. |
| SerialNumber | string |
β | π’ Manufacturer serial number or asset tag. |
| Notes | string |
β | π Freeβtext remarks or internal comments. |
| NeedsReview | bool |
β | β οΈ Flag to signal compliance or audit review. |
| ComplianceStatus | string |
β | βοΈ Current compliance outcome (e.g., βPassβ). |
| LastCheckIn | DateTime |
β | β±οΈ Last heartbeat / location check timestamp. |
| PrimaryUPN | string |
β | π§ User Principal Name when assigned. |
β Data Annotations & Validations
[Table("Asset", Schema = "irby")]
Maps this class to theirby.Assettable.[Key]
MarksIdas the primary key.[Required]
Ensures non-nullability in the database and at runtime for: Category, PurchaseDate, Status, ModelId.[DataType(DataType.Date)]
Restricts PurchaseDate to a date-only format (no time).
π Key Functional Areas
- Lifecycle Management
PurchaseDate&Statustrack the assetβs journey.
- Ownership & Location
Ownervs.FieldOfficeallow flexible assignment.
- Compliance & Auditing
NeedsReview,ComplianceStatus,LastCheckInsupport periodic checks.
- Integration
- Works seamlessly with
AssetModel,Employee, andFieldOfficeentities.
- Works seamlessly with
- Extendability
- Add more properties (e.g., warranty, depreciation) without impacting core mapping.
π‘ Usage Examples
1. Creating a New Asset
var newAsset = new Asset
{
Id = Guid.NewGuid(),
Category = AssetCategory.Hardware,
PurchaseDate = DateTimeOffset.UtcNow,
Status = AssetStatus.Active,
ModelId = 123, // Must match an existing AssetModel
SerialNumber = "SN-ABC-001",
Notes = "Issued to new hire",
NeedsReview = false,
ComplianceStatus= "Pending",
LastCheckIn = DateTime.UtcNow,
PrimaryUPN = "[email protected]"
};
// Using EF Core DbContext:
using(var context = new IrbyImagingContext())
{
context.Assets.Add(newAsset);
context.SaveChanges();
}
2. Querying & Updating
using(var context = new IrbyImagingContext())
{
// Fetch all active hardware assets
var assets = context.Assets
.Where(a => a.Status == AssetStatus.Active
&& a.Category == AssetCategory.Hardware)
.Include(a => a.Owner)
.Include(a => a.Model)
.ToList();
// Mark one for review
var asset = assets.First();
asset.NeedsReview = true;
asset.ComplianceStatus = "Scheduled";
context.SaveChanges();
}
3. Navigation & Relationships
// Eagerβload relationships
var assetWithRelations = context.Assets
.Include(a => a.Owner)
.Include(a => a.FieldOffice)
.Include(a => a.Model)
.FirstOrDefault(a => a.Id == someGuid);
π Conclusion
The Asset domain class is a cornerstone of the Irby Imaging asset-management solution. By leveraging Entity Framework Core conventions, rich annotations, and clear navigation properties, it:
- π Promotes consistency in how assets are stored and retrieved.
- π Eases extension for future properties (e.g., warranty, depreciation).
- π Streams data seamlessly between the database and your application.
With this documentation, you now have a comprehensive understanding of what the Asset class is for, how itβs wired up, and how to use it in your codebase. Happy coding! π