πŸ“– ActiveDirectoryUserDetails Documentation


πŸ—‚οΈ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Model: ActiveDirectoryUserDetails
  5. UML Class Diagram
  6. Usage Example
  7. Sample Integration with Active Directory
  8. Error Handling & Validation
  9. 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:

  1. Data Transfer

    • Acts as a DTO (Data Transfer Object) carrying AD attributes between layers.
  2. View Model Support

    • Provides strongly-typed properties for data-binding in UI frameworks (e.g., ASP.NET MVC, WPF).
  3. Extensibility

    • Easily extendable to include more AD attributes (e.g., Email, OfficeLocation, Manager).

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 not null before accessing properties.

  • πŸ›‘οΈ Empty Values
    Use the null-coalescing operator (?? string.Empty) when reading AD properties to avoid NullReferenceException.

  • 🚨 Exceptions
    Wrap Directory calls in try-catch to 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.