📦 IAssetManager Interface Documentation


📑 Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
    1. Asset Creation & Upload
    2. Asset Update & History
    3. Asset Retrieval by Category
    4. Asset History Retrieval
    5. Helper Methods & Utilities
  3. Dependencies & Technologies
  4. Domain Models & Data Structures
  5. Return Types & Error Handling
  6. Sample Usage & Code Snippets
  7. UML Class Diagram
  8. Conclusion

🧐 Overview & Purpose

The IAssetManager interface defines a contract for managing various IT and office assets within the IrbyImaging application. It resides in the IrbyImaging.Services namespace and supports:

  • CRUD operations (Create, Read, Update) with history tracking
  • Asynchronous programming via Task-based methods
  • Type-safe handling of different asset categories (computers, printers, docks, etc.)
  • Utility methods for lookup data (models, operating systems, owners, field offices)

Intended Use:
Inject IAssetManager into your UI or API services to handle asset management workflows—adding new equipment, updating records, retrieving inventory lists, and tracking historical changes.


⭐ Key Functional Areas

1. Asset Creation & Upload

Method Description
AddNewAssetWithHistory_Async<T>(T asset, string user) Create a single asset + track initial history
Upload<T>(IEnumerable<T> assets, string user) Bulk-upload multiple assets and record a bulk operation
// Example signature
Task<(Responses, string)> AddNewAssetWithHistory_Async<T>(
    T asset,
    string username
) where T : Asset;

2. Asset Update & History

Method Description
UpdateAssetAndHistory_Async<T>(T asset, string user, string reason) Update existing asset + append history record
// Update with a reason for the change
var (response, message) = await assetManager
    .UpdateAssetAndHistory_Async(computer, "jdoe", "Upgraded RAM");

3. Asset Retrieval by Category

Fetch lists or single instances for different asset types. All methods are asynchronous:

Category List Retrieval Single by ID
Computers GetComputers_Async(string term) GetComputerById_Async(Guid? id)
Safety Equipment GetSafetyEquipments_Async(string term) GetSafetyEquipmentById_Async(Guid? id)
Desk Phones GetDeskPhones_Async(string term) GetDeskPhoneById_Async(Guid? id)
Docks GetDocks_Async(string term) GetDockById_Async(Guid? id)
Mobile Devices GetMobileDevices_Async(string term) GetMobileDeviceById_Async(Guid? id)
Telogis Devices GetTelogisDevices_Async(string term) No single-ID method (device treated as mobile)
Monitors GetMonitors_Async(string term) GetMonitorById_Async(Guid? id)
Network Equip. GetNetworkEquipments_Async(string term) GetNetworkEquipmentById_Async(Guid? id)
Office Printers GetOfficePrinters_Async(string term) GetOfficePrinterById_Async(Guid? id)
Printers GetPrinters_Async(string term) GetPrinterById_Async(Guid? id)

4. Asset History Retrieval

Track the lifecycle of an asset:

Task<IEnumerable<AssetHistory>> GetHistoryByAssetId_Async(Guid? assetId);
  • Retrieves all AssetHistory entries associated with a specific assetId.

5. Helper Methods & Utilities

Utilities for populating drop‑downs and lookups:

Method Purpose
GetModelIdByName_Async(string modelName) Fetch numeric ID for a model name
GetOperatingSystemIdByName_Async(string name) Fetch numeric ID for an OS name
GetModelsFor(AssetCategory category) List models in a given asset category
GetModelsFor(DeviceType deviceType) List models for a specific device type
GetOperatingSystems() List all supported operating systems
GetOwners() List all possible asset owners
GetFieldOffices() List all field offices (locations)

🏗️ Dependencies & Technologies

  • .NET Standard / .NET Core (async/await, Task)
  • IrbyImaging.DomainClasses – Domain Entities (Asset, Computer, AssetHistory, etc.)
  • IrbyImaging.Utility – Common enums and helpers (e.g. Responses enum)
  • C# Generics – Type constraints (where T : Asset)
  • Dependency Injection – Typical registration in Startup/Program file
services.AddScoped<IAssetManager, AssetManager>();

📐 Domain Models & Data Structures

All methods operate on domain classes under IrbyImaging.DomainClasses:

  • Asset (base class)
  • Computer, SafetyEquipment, DeskPhone, Dock, Monitor, Printer, NetworkEquipment, MobileDevice, OfficePrinter
  • AssetHistory (tracks ownership, location, status changes)
public abstract class Asset
{
    public Guid Id { get; set; }
    public string SerialNumber { get; set; }
    public AssetCategory Category { get; set; }
    // ... common properties
}

public class Computer : Asset { /* CPU, RAM, OS, etc. */ }
public class AssetHistory { /* Date, ChangedBy, Reason, etc. */ }

⚙️ Return Types & Error Handling

  • All operations return a Task (asynchronous).
  • CRUD methods return (Responses, string) where:
    • Responses is an enum (e.g., Success, NotFound, Error, Duplicate)
    • string provides a human-readable message or error detail.
  • Retrieval methods return either:
    • Task<IEnumerable<T>> for list queries
    • Task<T> for single-entity fetch

Example:

var (resp, msg) = await assetManager.AddNewAssetWithHistory_Async(newPrinter, "asmith");
if (resp == Responses.Success)
{
    Console.WriteLine("Printer added successfully!");
}
else
{
    Console.Error.WriteLine($"Error: {msg}");
}

📋 Sample Usage & Code Snippets

1. Registering in DI

public void ConfigureServices(IServiceCollection services)
{
    services.AddScoped<IAssetManager, AssetManager>();
}

2. Adding a New Computer Asset

var computer = new Computer
{
    Id = Guid.NewGuid(),
    SerialNumber = "CNTR-12345",
    Category = AssetCategory.Computer,
    // other properties...
};

var (result, message) = await _assetManager
    .AddNewAssetWithHistory_Async(computer, User.Identity.Name);

if (result == Responses.Success) 
    Console.WriteLine("✅ Computer created.");
else 
    Console.WriteLine($"❌ {message}");

3. Retrieving All Monitors Matching “Dell”

var monitors = await _assetManager.GetMonitors_Async("Dell");
foreach (var m in monitors)
{
    Console.WriteLine($"{m.Id}: {m.Model} - {m.Resolution}");
}

4. Populating a Model Drop‐down

// In a Razor view model
public async Task PopulateModelList()
{
    var models = _assetManager.GetModelsFor(AssetCategory.Printer);
    MyPrinterModels = new SelectList(models, "Id", "Name");
}

📊 UML Class Diagram

@startuml
interface IAssetManager {
  +Task<(Responses,string)> AddNewAssetWithHistory_Async<T>(T, string)
  +Task<(Responses,string)> Upload<T>(IEnumerable<T>, string)
  +Task<(Responses,string)> UpdateAssetAndHistory_Async<T>(T, string, string)
  +Task<IEnumerable<Computer>> GetComputers_Async(string)
  +Task<Computer> GetComputerById_Async(Guid?)
  ... // other methods omitted for brevity
  +IEnumerable<object> GetFieldOffices()
}
class Asset { +Guid Id; +string SerialNumber; }
class Computer
class AssetHistory
IAssetManager ..> Asset
IAssetManager ..> Computer
IAssetManager ..> AssetHistory
@enduml

Paste the above into any PlantUML‐enabled editor for a visual diagram.


🏁 Conclusion

The IAssetManager interface centralizes all asset‐related operations in a strongly‐typed, asynchronous manner. By implementing this contract in your service layer, you gain:

  • 📦 Uniform API for asset CRUD and retrieval
  • ⏱ Scalable async methods for high‑volume scenarios
  • 🔄 Built‑in history tracking for auditability
  • 🛠 Helpers for populating lookup data

With this documentation as your guide, you can confidently integrate, extend, and maintain the asset management functionality across your UI and API layers.

Happy coding! 🚀