π‘οΈ SafetyEquipment.cs Documentation
Assembly: IrbyImaging.DomainClasses
Namespace: IrbyImaging.DomainClasses
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- UML Class Diagram
- Key Functional Areas
- Data Model: Properties
- Constructor
- View Models & Data Models
- Helper Methods / Utilities
- Error Handling & Return Types
- API Endpoints Overview
- Third-Party Integrations
- Sample Code Blocks
- Usage Examples
- Conclusion
1. Overview & Purpose
π SafetyEquipment is a domain model representing safety-related assets within the Irby Imaging system.
It inherits from the base class Asset to leverage common properties (e.g., Id, Name, PurchaseDate) while adding safety-specific fields:
- Categorization: Automatically tagged as
AssetCategory.SafetyEquipment - Identification: Tracks operating system reference, asset/unit/CPS numbers
This class is intended to be used in:
- Entity Framework or any ORM for persistence
- Business logic that needs specialized safety-asset behaviors
- UI layers for displaying or editing safety equipment details
2. Dependencies & Technologies
| Technology / Library | Purpose |
|---|---|
| C# (.NET Standard or .NET 6+) | Core language and runtime |
IrbyImaging.DomainClasses |
Domain assembly |
IrbyImaging.Utility |
Defines AssetCategory enum |
| Entity Framework (optional) | ORM for database mapping |
Note: The
OperatingSystemnavigation property typically ties into another domain class or lookup table.
3. UML Class Diagram
classDiagram
class Asset {
<<abstract>>
+int Id
+string Name
+DateTime PurchaseDate
+AssetCategory Category
+... // Other common asset props
}
class SafetyEquipment {
+int OperatingSystemId
+OperatingSystem OperatingSystem
+string AssetNumber
+string UnitNumber
+string CpsNumber
+SafetyEquipment()
}
class OperatingSystem {
+int Id
+string Name
+string Version
+... // Additional OS fields
}
Asset <|-- SafetyEquipment
OperatingSystem "1" <-- "0..*" SafetyEquipment
4. Key Functional Areas
- Domain Modeling: Defines a strong-typed representation of safety equipment in the system.
- Category Assignment: Automatically sets
Category = AssetCategory.SafetyEquipmentupon instantiation. - Data Relationships: Links to an
OperatingSystementity via foreign key (OperatingSystemId). - Unique Identifiers:
AssetNumberβ System-wide unique asset tagUnitNumberβ Manufacturer or internal unit codeCpsNumberβ Certification or safety compliance ID
5. Data Model: Properties
| Property | Type | Description |
|---|---|---|
OperatingSystemId |
int |
Foreign key to the associated operating system. |
OperatingSystem |
OperatingSystem |
Navigation property for ORM relationships. |
AssetNumber |
string |
Unique identifier assigned by asset management. |
UnitNumber |
string |
Manufacturer or site unit code. |
CpsNumber |
string |
Certification or Safety Compliance number. |
6. Constructor
/// <summary>
/// Initializes a new instance of the <see cref="SafetyEquipment"/> class.
/// Automatically sets the asset category to SafetyEquipment.
/// </summary>
public SafetyEquipment()
{
Category = IrbyImaging.Utility.AssetCategory.SafetyEquipment;
}
- What it does:
- Calls base
Assetconstructor (implicitly). - Sets Category to
SafetyEquipment, ensuring consistency across all safety assets.
- Calls base
7. View Models & Data Models
- View Models
- Typically you would map
SafetyEquipmentto aSafetyEquipmentViewModelfor UI concerns (e.g., with AutoMapper).
- Typically you would map
- Data Models
- This class is the data model for EF or other ORMs.
- Tables:
Assets(base)SafetyEquipments(derived)
8. Helper Methods / Utilities
π§ Note: This class does not define custom helper methods beyond the constructor. All logic resides in the base
Assetor in service layers.
9. Error Handling & Return Types
- Error Handling:
- None within this POCO.
- Validation and exceptions should be handled in service or application layers (e.g., null checks, required fields).
- Return Types:
- All members are simple propertiesβno methods returning values.
10. API Endpoints Overview
β οΈ This is a domain class and does not define API endpoints.
API controllers that exposeSafetyEquipmentmay provide endpoints such as:
GET /api/safetyequipment/{id}POST /api/safetyequipmentPUT /api/safetyequipment/{id}DELETE /api/safetyequipment/{id}
11. Third-Party Integrations
- Entity Framework Core (or EF6) for object-relational mapping.
- FluentValidation or DataAnnotations (not shown) may be used to validate properties at the service or API level.
12. Sample Code Blocks
12.1. Defining the DbContext
public class ImagingDbContext : DbContext
{
public DbSet<Asset> Assets { get; set; }
public DbSet<SafetyEquipment> SafetyEquipments { get; set; }
public DbSet<OperatingSystem> OperatingSystems { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SafetyEquipment>()
.HasOne(se => se.OperatingSystem)
.WithMany(os => os.SafetyEquipments)
.HasForeignKey(se => se.OperatingSystemId);
base.OnModelCreating(modelBuilder);
}
}
12.2. Migration Example
dotnet ef migrations add AddSafetyEquipmentTable
dotnet ef database update
13. Usage Examples
13.1. Creating a New Safety Equipment
var os = new OperatingSystem { Name = "Windows", Version = "10 Pro" };
context.OperatingSystems.Add(os);
context.SaveChanges();
var helmet = new SafetyEquipment
{
OperatingSystemId = os.Id,
AssetNumber = "SE-2023-0001",
UnitNumber = "HN-XL-42",
CpsNumber = "CPS-889977"
};
context.SafetyEquipments.Add(helmet);
context.SaveChanges();
13.2. Querying Safety Equipment
var allSafetyDevices = context.SafetyEquipments
.Include(se => se.OperatingSystem)
.Where(se => se.OperatingSystem.Name == "Windows")
.ToList();
14. Conclusion
π οΈ SafetyEquipment.cs provides a clean, extendable domain model for managing safety-related assets. By inheriting from the common Asset class and assigning a specific category, it simplifies tracking, validation, and persistence. Use it in combination with EF Core and your service/API layers to deliver robust safety equipment management in your application.
π Happy coding and stay safe with well-modelled assets!