π HomeController Documentation
File:
IrbyImaging/Controllers/HomeController.cs
Assembly:IrbyImaging.UI
Author: kvamshi
Created: 01-11-2022
Last Modified: 05-17-2022
π Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- MVC Models (View & Data Models)
- Controller Actions (Endpoints)
- Helper Methods & Utilities
- Error Handling & Return Types
- Third-party Integrations
- UML Class Diagram
- Sample Code Snippets & Usage Examples
- Conclusion
π 1. Overview & Purpose
The HomeController is the primary ASP.NET Core MVC controller in the IrbyImaging.UI project. It inherits from a shared BaseController and orchestrates:
- Rendering of static pages (Privacy, ContactUs, ComingSoon, etc.)
- The secured Index dashboard where user roles, claims, and other AD attributes are loaded
- An e-mail sending UI and backend (
SendEmailactions) - Centralized error handling via an
Erroraction
This controller is decorated with application-wide filters (e.g., AuditFilterAttribute) inherited from the base.
π 2. Key Functional Areas
| Area | Description |
|---|---|
| Dashboard (Index) | Loads user claims, fetches AD details, roles, and populates ViewBag for view rendering. |
| Email Utility | Displays a form and processes e-mails with attachments using MailService. |
| Static Pages | Serves Privacy, Contact Us, Coming Soon, Downtime, Timeout, and SignIn views. |
| Error Handling | Centralized Error action with response caching disabled. |
π οΈ 3. Dependencies & Technologies
- ASP.NET Core MVC
- Entity Framework Core (
IrbyContext) - Azure AD & Microsoft Graph (via
AzureADRead) - Azure Key Vault (via
IKeyVaultManager) - Microsoft.Extensions.Configuration for secrets & app settings
- Microsoft.AspNetCore.Http for file uploads
- Microsoft.Extensions.Logging
- Custom Services:
MailService,AuditFilterAttribute,BaseController
π¦ 4. MVC Models (View & Data Models)
Data Models (Entity Framework)
- Employee β holds user employee data (e.g.,
EmployeeId,WorkEmail). - LinkUserRoles β junction between employees and roles (
EmployeeId,RoleId). - Role β defines roles with
RoleIdand metadata.
View Models
- ErrorViewModel
public class ErrorViewModel { public string RequestId { get; set; } public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); }
π‘ 5. Controller Actions (Endpoints)
| HTTP | Route/Action | Parameters | Description |
|---|---|---|---|
| GET | /Home/Index |
β | Main dashboard; loads user & roles, renders view. |
| GET | /Home/SendEmail |
β | Renders the e-mail form. |
| POST | /Home/SendEmail |
IEnumerable<IFormFile> file, string email, string subject, string body, string copyemail |
Processes e-mail sending. |
| GET | /Home/Privacy |
β | Renders Privacy page. |
| GET | /Home/ContactUs |
β | Renders Contact Us page. |
| GET | /Home/ComingSoon |
β | Renders Coming Soon page. |
| GET | /Home/SignIn |
β | Renders Sign In page. |
| GET | /Home/ContactUs1 |
β | Alternate Contact Us page. |
| GET | /Home/ComingSoon1 |
β | Alternate Coming Soon page. |
| GET | /Home/Downtime |
β | Renders Downtime page. |
| GET | /Home/Timeout |
β | Renders Timeout page. |
| GET | /Home/Error |
β | Renders Error view with ErrorViewModel. |
π§ 6. Helper Methods & Utilities
- AzureADRead
var ad = new AzureADRead(_context, _configuration); var user = ad.GetUserADList(email); // Fetches AD user attributes - MailService
var emailRequest = new MailService(); var isSent = emailRequest.SendEmail( to: email, subject: subject, body: body, attachments: file, isBodyHtml: true, cc: copyemail, clientId: clientId, tenantId: tenantId, clientSecret: clientSecret ); - Key Vault β
_secretManagerinjected but not directly used in this controller (reserved for secret retrieval).
βοΈ 7. Error Handling & Return Types
Error(): decorated with
to prevent caching.[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]- Returns
IActionResultwithErrorViewModelcarrying the currentRequestIdorTraceIdentifier.
π 8. Thirdβparty Integrations
| Integration | Usage |
|---|---|
| Azure AD / Microsoft Graph | AzureADRead utility reads department, title, display name using Graph. |
| Azure Key Vault | IKeyVaultManager for future secret retrieval. |
| Office 365 SMTP/Mail | MailService uses application credentials (clientId, clientSecret, tenantId) to send e-mails. |
π 9. UML Class Diagram
classDiagram
BaseController <|-- HomeController
HomeController : +ILogger<HomeController> _logger
HomeController : +IHttpContextAccessor _httpContextAccessor
HomeController : +IrbyContext _context
HomeController : +IKeyVaultManager _secretManager
HomeController : +IConfiguration _configuration
HomeController : +Task<IActionResult> Index()
HomeController : +IActionResult SendEmail()
HomeController : +IActionResult SendEmail(IEnumerable<IFormFile>,string,string,string,string)
HomeController : +IActionResult Privacy()
HomeController : +IActionResult ContactUs()
HomeController : +IActionResult ComingSoon()
HomeController : +IActionResult SignIn()
HomeController : +IActionResult ContactUs1()
HomeController : +IActionResult ComingSoon1()
HomeController : +IActionResult Downtime()
HomeController : +IActionResult Timeout()
HomeController : +IActionResult Error()
π 10. Sample Code Snippets & Usage Examples
1. Calling the Index Action in Razor
@* Link to Dashboard *@
<a asp-controller="Home" asp-action="Index" class="btn btn-primary">
<i class="fas fa-home"></i> Dashboard
</a>
2. Email Form (Razor View)
<form asp-action="SendEmail" method="post" enctype="multipart/form-data">
<input type="email" name="email" placeholder="Recipient Email" required />
<input type="text" name="subject" placeholder="Subject" required />
<textarea name="body" placeholder="Message body"></textarea>
<input type="file" name="file" multiple />
<input type="email" name="copyemail" placeholder="CC Email (optional)" />
<button type="submit">Send π¬</button>
</form>
3. Logging Inside Controller
_logger.LogInformation("User {User} accessed the Index page at {Time}.", User.Identity.Name, DateTime.UtcNow);
4. Fetching Secrets from Configuration
var clientId = _configuration["HelpDeskEmailClientId"];
var tenantId = _configuration["Tenant"];
var clientSecret = _configuration["HelpDeskEmailClientSecret"];
π 11. Conclusion
The HomeController serves as the central navigational and utility hub for the IrbyImaging UI. It demonstrates:
- Secure AD-based user context loading
- Email dispatching with attachment support
- Static content rendering (Privacy, Contact pages)
- Robust error handling with traceability
π With clear dependency injection and modular utilities, this controller can be extended to incorporate more features (e.g., secrets retrieval via Key Vault) or new endpoints as the application evolves.