π GLTypeController Documentation
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Architecture & Key Functional Areas
- API Endpoints Overview
- Error Handling & Return Types
- Sample Code Blocks
- Usage Examples
- UML Diagram
- Conclusion
1. Overview & Purpose
GLTypeController is an ASP.NET Core MVC Controller in the IrbyImaging.UI project. It provides CRUD (Create, Read, Update) functionality for General Ledger Types within the Irby Imaging application.
- π Namespace:
IrbyImaging.UI.Controllers - π Responsibility:
- List all GL Types
- Create a new GL Type
- Edit an existing GL Type
- Ensure data consistency via Entity Framework Core
- Audit who created/modified a record and when
2. Dependencies & Technologies
| Technology / Package | Purpose |
|---|---|
| Microsoft.AspNetCore.Mvc | MVC Controller, Actions, Routing |
| Microsoft.EntityFrameworkCore | Database access, LINQ queries, DbContext |
| Microsoft.AspNetCore.Authorization | (Prepared for) securing actions with policies |
| Microsoft.AspNetCore.Http | IHttpContextAccessor for user context |
| Microsoft.Extensions.Configuration | App configuration settings |
| IrbyImaging.DbContext (IrbyContext) | EF Core DbContext for Irby Imaging data models |
| IrbyImaging.DomainClasses | Domain entities: GeneralLedger, GLTypeDetail |
3. Architecture & Key Functional Areas
3.1 Controller Actions
| Action | HTTP Verb | Route | Description |
|---|---|---|---|
| Index | GET | /GLType/Index |
Lists all General Ledger Types |
| Create (View) | GET | /GLType/Create |
Renders form to add a new GL Type |
| Create (Submit) | POST | /GLType/Create |
Persists a new GL Type to the database |
| Edit (View) | GET | /GLType/Edit/{id} |
Renders form to update an existing GL Type |
| Edit (Submit) | POST | /GLType/Edit/{id} |
Updates the GL Type in the database |
3.2 View Models & Data Models
GeneralLedger (Domain Model)
public class GeneralLedger
{
public Guid Id { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public bool IsInactive { get; set; }
public DateTime AddedDate { get; set; }
public DateTime ModifiedDate { get; set; }
public string AddedBy { get; set; }
public string ModifiedBy { get; set; }
// Navigation for Index view
public List<GLTypeDetail> GLTypeDetail { get; set; }
}
GLTypeDetail (View Model)
public class GLTypeDetail
{
public Guid Id { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public bool IsInactive { get; set; }
}
3.3 Helper Methods / Utilities
- GLExists(Guid id)
Checks if aGeneralLedgerwith the given Id exists in the database.private bool GLExists(Guid id) => _context.GeneralLedgers.Any(e => e.Id == id); - User Identity Extraction
Grabs the current userβs full name from claims for audit fields (AddedBy/ModifiedBy). Defaults to"System"if unavailable.
4. API Endpoints Overview
Although this is a classic MVC controller (View-based), you can call its actions programmatically:
| Controller.Action | URL | Method | Request Body / Query |
|---|---|---|---|
| GLTypeController.Index | /GLType or /GLType/Index |
GET | β |
| GLTypeController.Create | /GLType/Create |
GET | β |
| GLTypeController.Create | /GLType/Create |
POST | { Code, Description, IsInactive } |
| GLTypeController.Edit | /GLType/Edit/{id} |
GET | β |
| GLTypeController.Edit | /GLType/Edit/{id} |
POST | { Id, Code, Description, IsInactive } |
5. Error Handling & Return Types
- Model Validation
IfModelStateis invalid, the action redisplays the same view with validation errors. - 404 Not Found
- Edit GET/POST returns
NotFound()whenidis null or missing in the DB.
- Edit GET/POST returns
- Concurrency Exception
InEdit, catchesDbUpdateConcurrencyException. If the record no longer exists, returns 404, otherwise rethrows.
6. Sample Code Blocks
Index Action
public async Task<IActionResult> Index()
{
// Fetch all ledger types ordered by Code
var allLedgers = _context.GeneralLedgers
.OrderBy(g => g.Code)
.ToList();
// Prepare view model
var model = new GeneralLedger {
GLTypeDetail = allLedgers.Select(rec => new GLTypeDetail {
Id = rec.Id,
Code = rec.Code,
Description = rec.Description,
IsInactive = rec.IsInactive
}).ToList()
};
return View(model);
}
Create (POST) Action
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Code,Description,IsInactive")] GeneralLedger gl)
{
if (ModelState.IsValid)
{
// Audit Info
var userName = GetCurrentUserName() ?? "System";
gl.Id = Guid.NewGuid();
gl.AddedDate = DateTime.Now;
gl.ModifiedDate = DateTime.Now;
gl.AddedBy = userName;
gl.ModifiedBy = userName;
gl.IsInactive = false;
_context.Add(gl);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
// If invalid, re-populate dropdown and return view
ViewData["GL"] = new SelectList(_context.GeneralLedgers, "Id", "Code");
return View(gl);
}
7. Usage Examples
-
List GL Types
Navigate tohttps://<your-domain>/GLType/Index. -
Add a New GL Type
- GET
/GLType/Createβ displays form - POST
/GLType/Createwith payload:{ "Code": "REV", "Description": "Revenue Accounts", "IsInactive": false }
- GET
-
Edit an Existing GL Type
- GET
/GLType/Edit/3f29a4c0-...-d4f19b7e3f4fβ displays populated form - POST
/GLType/Edit/3f29a4c0-...-d4f19b7e3f4fwith updated fields
- GET
8. UML Diagram
classDiagram
class GLTypeController {
- IrbyContext _context
- IHttpContextAccessor _httpContextAccessor
- IConfiguration _configuration
+ Task<IActionResult> Index()
+ IActionResult Create()
+ Task<IActionResult> Create(GeneralLedger)
+ Task<IActionResult> Edit(Guid)
+ Task<IActionResult> Edit(Guid, GeneralLedger)
- bool GLExists(Guid)
}
class GeneralLedger {
+ Guid Id
+ string Code
+ string Description
+ bool IsInactive
+ List~GLTypeDetail~ GLTypeDetail
+ DateTime AddedDate
+ DateTime ModifiedDate
+ string AddedBy
+ string ModifiedBy
}
class GLTypeDetail {
+ Guid Id
+ string Code
+ string Description
+ bool IsInactive
}
GLTypeController --> GeneralLedger : uses
GeneralLedger --> GLTypeDetail : contains
9. Conclusion
β GLTypeController encapsulates all presentation-layer logic for managing General Ledger Types in the Irby Imaging system.
- Follows standard ASP.NET Core MVC patterns
- Leverages Entity Framework Core for data operations
- Implements basic auditing, validation, and error handling
With this documentation, you now have a complete picture of how GLTypeController is structured, how to extend it if needed, and how to integrate it into your MVC application. Happy coding! π