🏠 HomeController Documentation

File: IrbyImaging/Controllers/HomeController.cs
Assembly: IrbyImaging.UI
Author: kvamshi
Created: 01-11-2022
Last Modified: 05-17-2022


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. MVC Models (View & Data Models)
  5. Controller Actions (Endpoints)
  6. Helper Methods & Utilities
  7. Error Handling & Return Types
  8. Third-party Integrations
  9. UML Class Diagram
  10. Sample Code Snippets & Usage Examples
  11. 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 (SendEmail actions)
  • Centralized error handling via an Error action

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 RoleId and 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 – _secretManager injected but not directly used in this controller (reserved for secret retrieval).

βš™οΈ 7. Error Handling & Return Types

  • Error(): decorated with
    [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
    
    to prevent caching.
  • Returns IActionResult with ErrorViewModel carrying the current RequestId or TraceIdentifier.

🌐 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.