π 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
- Overview & Purpose
- Dependencies & Technologies
- Controller Inheritance
- Constructor & Dependencies
- Key Actions & Endpoints
5.1 Index()
5.2 GetTicketsData()
5.3 GetAllTicketsData() - Data Retrieval & Grouping
- Azure AD & Microsoft Graph Integration
- ViewBag Keys & Meanings
- Response Schemas & Examples
- UML Class Diagram
- Usage Examples
- 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 forTickets. - 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:
- Retrieve user email/name from
User.Claims. - Build
GraphServiceClientusingClientSecretCredential. - Fetch userβs
signInActivity,Department,JobTitle. - Query
_context.Ticketsfor counts (Total, Open, In-Progress, Closed). - Group last 12 months of tickets by
Year Month. - Compute differences between latest two months.
- Pass all metrics via
ViewBagtoIndex.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
ViewBagwith 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):
- Filter:
.Where(t => t.CreatedOn >= DateTime.Now.AddMonths(-12)) - Group by
YearMonth. - Select
{ YMetric = key, Count = group.Count() }. Take(12)to ensure exactly twelve periods.- Reverse/order to feed chart labels & values.
π‘οΈ Azure AD & Microsoft Graph Integration
- Credentials from
appsettings.json:IrbySystemsAppIdIrbySystemsGraphSecretTenant
- ClientSecretCredential acquires token.
- GraphServiceClient calls
/users/{email}:- Retrieves
displayName,signInActivity,Department,JobTitle. - Populates
ViewBag.DisplayName,ViewBag.Department,ViewBag.Role.
- Retrieves
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! π