πŸ†˜ HelpDeskHomeController Documentation

Welcome to the HelpDeskHomeController documentation! This controller powers the Help Desk dashboard in the IrbyImaging UI, surfacing ticket statistics and user information from Azure AD via Microsoft Graph.


πŸ“‹ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Controller Inheritance
  4. Constructor & Dependencies
  5. Key Actions & Endpoints
    5.1 Index()
    5.2 GetTicketsData()
    5.3 GetAllTicketsData()
  6. Data Retrieval & Grouping
  7. Azure AD & Microsoft Graph Integration
  8. ViewBag Keys & Meanings
  9. Response Schemas & Examples
  10. UML Class Diagram
  11. Usage Examples
  12. Conclusion

πŸ” Overview & Purpose

HelpDeskHomeController is an MVC controller responsible for:

  • Displaying real-time ticket metrics (total, requests vs incidents, status breakdown).
  • Fetching Azure AD user details (display name, department, job title).
  • Providing JSON endpoints for rendering charts (last 12 months of ticket trends).

It serves as the landing page (Index) for the Help Desk dashboard and supplies data for frontend visualizations.


πŸ› οΈ Dependencies & Technologies

Technology / Package Purpose
ASP.NET Core MVC Web framework
Entity Framework Core Data access (IrbyContext β‡’ Tickets table)
Azure.Identity Acquire client credentials for Graph API
Microsoft.Graph Query Azure AD for user information
Newtonsoft.Json JSON (de)serialization
Utility (IrbyImaging) TicketType & TicketStatus enums/constants

πŸ›οΈ Controller Inheritance

public class HelpDeskHomeController : BaseController
  • BaseController provides shared context & configuration.
  • Inherits common properties/methods (e.g., access to _context & _configuration).

🧩 Constructor & Dependencies

public HelpDeskHomeController(IrbyContext context, IConfiguration configuration)
    : base(context, configuration)
{
    _context = context;
    _configuration = configuration;
}
  • IrbyContext (_context): EF Core DB context for Tickets.
  • IConfiguration (_configuration): App settings (Graph AppId, Secret, Tenant).

πŸ”‘ Key Actions & Endpoints

1. Index()

Signature:

public async Task<IActionResult> Index()

Purpose:

  • Gathers user info from Azure AD and JWT claims.
  • Computes ticket counts & trends.
  • Populates ViewBag for Razor view.

High-level Steps:

  1. Retrieve user email/name from User.Claims.
  2. Build GraphServiceClient using ClientSecretCredential.
  3. Fetch user’s signInActivity, Department, JobTitle.
  4. Query _context.Tickets for counts (Total, Open, In-Progress, Closed).
  5. Group last 12 months of tickets by Year Month.
  6. Compute differences between latest two months.
  7. Pass all metrics via ViewBag to Index.cshtml.

2. GetTicketsData()

[HttpPost]
public JsonResult GetTicketsData()

Purpose:
Returns JSON for charting:

  • all: Last 12 months total tickets
  • requests: Monthly request ticket counts
  • incidents: Monthly incident ticket counts
  • labels: Month names (e.g., Jan 2022)

Response Schema:

{
  "success": true,
  "all": [12, 10, …],
  "requests": [5, 4, …],
  "incidents": [7, 6, …],
  "labels": ["Jun 2021", "Jul 2021", …]
}

3. GetAllTicketsData()

[HttpPost]
public JsonResult GetAllTicketsData()

Purpose:
Similar to GetTicketsData, but returns only:

  • all: Total tickets last 12 months
  • labels: Month names
  • Updates ViewBag with month-over-month diff for the overview panel.

Response Schema:

{
  "success": true,
  "all": [12, 10, …],
  "labels": ["Jun 2021", "Jul 2021", …]
}

πŸ“Š Data Retrieval & Grouping

All ticket queries follow this pattern:

var tickets = _context.Tickets
    .Select(t => new {
        t.TicketNumber,
        t.Type,
        t.Status,
        t.CreatedOn,
        YearMonth = t.CreatedOn.Year + " " + t.CreatedOn.Month
    })
    .OrderByDescending(t => t.CreatedOn)
    .ToList();

Grouping Logic (Last 12 Months):

  1. Filter: .Where(t => t.CreatedOn >= DateTime.Now.AddMonths(-12))
  2. Group by YearMonth.
  3. Select { YMetric = key, Count = group.Count() }.
  4. Take(12) to ensure exactly twelve periods.
  5. Reverse/order to feed chart labels & values.

πŸ›‘οΈ Azure AD & Microsoft Graph Integration

  1. Credentials from appsettings.json:
    • IrbySystemsAppId
    • IrbySystemsGraphSecret
    • Tenant
  2. ClientSecretCredential acquires token.
  3. GraphServiceClient calls /users/{email}:
    • Retrieves displayName, signInActivity, Department, JobTitle.
    • Populates ViewBag.DisplayName, ViewBag.Department, ViewBag.Role.
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var user = await graphClient.Users[email].GetAsync();

πŸ“ˆ ViewBag Keys & Meanings

Key Description
ViewBag.DisplayName User full name from Azure AD
ViewBag.Department User’s department
ViewBag.Role User’s job title
ViewBag.TotalCount Total tickets
ViewBag.RequestCount Total Request tickets
ViewBag.IncidentCount Total Incident tickets
ViewBag.TotalOpenCount Tickets Open
ViewBag.RequestOpenCount Open Request tickets
ViewBag.IncidentOpenCount Open Incident tickets
ViewBag.TotalInProgressCount Tickets In Progress
ViewBag.TotalClosedCount Tickets Closed
ViewBag.TotalDiffCount Change in total tickets (this vs last month)
ViewBag.TotalLastCount Last month total tickets
ViewBag.TotalThisCount This month total tickets

πŸ“¦ Response Schemas & Examples

GetTicketsData Response

{
  "success": true,
  "all":    [ 8,  10, 12, … ],     // Total tickets
  "requests":[ 3,   4,  5, … ],     // Request tickets
  "incidents":[ 5,   6,  7, … ],    // Incident tickets
  "labels": ["Jun 21","Jul 21","Aug 21", …]
}

GetAllTicketsData Response

{
  "success": true,
  "all":   [ 8,  10, 12, … ],       // Total tickets
  "labels":["Jun 21","Jul 21","Aug 21", …]
}

πŸ“ UML Class Diagram

classDiagram
    BaseController <|-- HelpDeskHomeController
    HelpDeskHomeController : -IrbyContext _context
    HelpDeskHomeController : -IConfiguration _configuration
    HelpDeskHomeController : +Index() : Task<IActionResult>
    HelpDeskHomeController : +GetTicketsData() : JsonResult
    HelpDeskHomeController : +GetAllTicketsData() : JsonResult

πŸš€ Usage Examples

Razor View (Index.cshtml)

<h1>Help Desk Dashboard</h1>
<p>Welcome @ViewBag.DisplayName (@ViewBag.Role)</p>

<div>
  <strong>Total Tickets:</strong> @ViewBag.TotalCount<br/>
  <strong>Requests:</strong> @ViewBag.RequestCount<br/>
  <strong>Incidents:</strong> @ViewBag.IncidentCount
</div>

<script>
  // Fetch chart data
  $.post('@Url.Action("GetTicketsData")', function(response) {
    if(response.success) {
      const ctx = document.getElementById('chart').getContext('2d');
      new Chart(ctx, {
        type: 'line',
        data: {
          labels: response.labels,
          datasets: [
            { label: 'All',    data: response.all,    borderColor: 'blue'   },
            { label: 'Requests',data: response.requests, borderColor: 'green' },
            { label: 'Incidents',data: response.incidents, borderColor: 'red'   }
          ]
        }
      });
    }
  });
</script>

cURL Example

curl -X POST https://yourdomain.com/HelpDeskHome/GetTicketsData \
     -H "Content-Type: application/json"

🎯 Conclusion

The HelpDeskHomeController centralizes dashboard logic for:

  • User context (via Azure AD/Graph)
  • Ticket analytics (via EF Core & LINQ)
  • Data provisioning (via ViewBag & JSON endpoints)

This modular design ensures the Help Desk UI always shows up‑to‑date metrics with minimal frontend logic.

Feel free to extend or refactor grouping logic into services, add caching for Graph calls, or introduce pagination for large ticket volumes. Happy coding! πŸš€