π ActiveDirectoryUserDetails Documentation
ποΈ Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Model: ActiveDirectoryUserDetails
- UML Class Diagram
- Usage Example
- Sample Integration with Active Directory
- Error Handling & Validation
- Conclusion
1. Overview & Purpose
ActiveDirectoryUserDetails is a simple C# model class designed to encapsulate essential user attributes fetched from Microsoft Active Directory. It lives in the IrbyImaging.Models namespace and is part of the IrbyImaging.UI assembly.
Why this class exists:
-
π― Centralized Data Contract
Provides a single, consistent object to represent an employeeβs Common Attributes from AD (phone, title, department). -
π§© Separation of Concerns
Keeps UI logic clean by offloading AD attribute storage into a dedicated model. -
π Reusable
Can be used across multiple services, endpoints, or UI components that need basic AD user details.
2. Dependencies & Technologies
| Category | Details |
|---|---|
| Language | C# (.NET Framework / .NET Core) |
| Assembly | IrbyImaging.UI |
| Namespace | IrbyImaging.Models |
| AD Integration | (Optional) System.DirectoryServices or Microsoft.Graph |
| UML Diagram | MermaidJS (for documentation) |
| IDE | Visual Studio 2019 / Visual Studio 2022 |
3. Key Functional Areas
This model serves three core purposes:
-
Data Transfer
- Acts as a DTO (Data Transfer Object) carrying AD attributes between layers.
-
View Model Support
- Provides strongly-typed properties for data-binding in UI frameworks (e.g., ASP.NET MVC, WPF).
-
Extensibility
- Easily extendable to include more AD attributes (e.g.,
Email,OfficeLocation,Manager).
- Easily extendable to include more AD attributes (e.g.,
4. Data Model: ActiveDirectoryUserDetails
// File: ActiveDirectoryUserDetails.cs
namespace IrbyImaging.Models
{
/// <summary>
/// Class ActiveDirectoryUserDetails.
/// </summary>
public class ActiveDirectoryUserDetails
{
/// <summary>
/// Gets or sets the phone number.
/// </summary>
public string PhoneNumber { get; set; }
/// <summary>
/// Gets or sets the title.
/// </summary>
public string Title { get; set; }
/// <summary>
/// Gets or sets the department.
/// </summary>
public string Department { get; set; }
}
}
| Property | Type | Description |
|---|---|---|
| PhoneNumber | string | The userβs telephone number. |
| Title | string | The job title or position of the user. |
| Department | string | The department or organizational unit. |
5. UML Class Diagram
classDiagram
class ActiveDirectoryUserDetails {
- PhoneNumber : string
- Title : string
- Department : string
}
6. Usage Example
Below is a simple ASP.NET MVC snippet showing how you might use ActiveDirectoryUserDetails in a controller and pass it to a view.
using IrbyImaging.Models;
using System.Web.Mvc;
public class EmployeeController : Controller
{
public ActionResult Profile()
{
// Imagine we fetched these from AD
var adDetails = new ActiveDirectoryUserDetails
{
PhoneNumber = "+1-555-1234",
Title = "Senior Engineer",
Department = "Imaging Services"
};
return View(adDetails);
}
}
@model IrbyImaging.Models.ActiveDirectoryUserDetails
<h2>Employee Profile</h2>
<ul>
<li><strong>Phone:</strong> @Model.PhoneNumber</li>
<li><strong>Title:</strong> @Model.Title</li>
<li><strong>Department:</strong> @Model.Department</li>
</ul>
7. Sample Integration with Active Directory
Below is a console app example demonstrating how you might populate ActiveDirectoryUserDetails using System.DirectoryServices.
using System;
using System.DirectoryServices;
using IrbyImaging.Models;
class Program
{
static void Main(string[] args)
{
string ldapPath = "LDAP://DC=yourdomain,DC=com";
string userSamAccountName = "jdoe";
var details = GetUserDetailsFromAD(ldapPath, userSamAccountName);
Console.WriteLine($"Phone: {details.PhoneNumber}");
Console.WriteLine($"Title: {details.Title}");
Console.WriteLine($"Department: {details.Department}");
}
static ActiveDirectoryUserDetails GetUserDetailsFromAD(string ldapPath, string samAccountName)
{
var adUser = new ActiveDirectoryUserDetails();
using (var entry = new DirectoryEntry(ldapPath))
using (var searcher = new DirectorySearcher(entry))
{
searcher.Filter = $"(sAMAccountName={samAccountName})";
searcher.PropertiesToLoad.Add("telephoneNumber");
searcher.PropertiesToLoad.Add("title");
searcher.PropertiesToLoad.Add("department");
var result = searcher.FindOne();
if (result != null)
{
adUser.PhoneNumber = result.Properties["telephoneNumber"]?.Count > 0
? result.Properties["telephoneNumber"][0].ToString() : string.Empty;
adUser.Title = result.Properties["title"]?.Count > 0
? result.Properties["title"][0].ToString() : string.Empty;
adUser.Department = result.Properties["department"]?.Count > 0
? result.Properties["department"][0].ToString() : string.Empty;
}
}
return adUser;
}
}
8. Error Handling & Validation
-
π Null Checks
Always verify that the AD search result is notnullbefore accessing properties. -
π‘οΈ Empty Values
Use the null-coalescing operator (?? string.Empty) when reading AD properties to avoidNullReferenceException. -
π¨ Exceptions
Wrap Directory calls intry-catchto gracefully handle network/permission errors.
9. Conclusion
πΉ ActiveDirectoryUserDetails is a lightweight, reusable model for carrying key Active Directory user attributes throughout your application.
πΉ Its simplicity makes it easy to extend and integrate with various UI frameworks or backend services.
πΉ By adhering to Single Responsibility and DTO patterns, your code remains clean, maintainable, and testable.
Happy Coding! π
For further questions or enhancement requests, please refer to the IrbyImaging.UI project repository or contact the library maintainers.