📚 IssuesController Documentation
Welcome to the comprehensive documentation for the IrbyImaging/UI/Controllers/IssuesController.cs file. This controller is part of an ASP.NET Core MVC application that manages CRUD operations for Issue entities. Below you’ll find:
- 🚀 Table of Contents
- 📖 Overview & Purpose
- 🔧 Dependencies & Technologies
- 🏗 Class Diagram (UML)
- 🎯 Key Functional Areas
- 📦 Data Model: Issue
- 🔄 API Endpoints Overview
- ⚙️ Helper Methods & Utilities
- 🚨 Error Handling & Return Types
- 💡 Usage Examples
- 🎉 Conclusion
🚀 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Class Diagram (UML)
- Key Functional Areas
- Data Model: Issue
- API Endpoints Overview
- Helper Methods & Utilities
- Error Handling & Return Types
- Usage Examples
- Conclusion
📖 Overview & Purpose
The IssuesController provides standard CRUD (Create, Read, Update, Delete) operations on the Issue entity in the IrbyImaging application. It inherits from a shared BaseController, leveraging common functionality, and uses Entity Framework Core to interact with the database via IrbyContext.
Key Goals:
- Display a list of issues
- View detailed information about a single issue
- Add new issues
- Edit existing issues
- Delete issues
🔧 Dependencies & Technologies
| Dependency | Purpose |
|---|---|
| Microsoft.AspNetCore.Mvc | MVC framework for controllers, views, routing |
| Microsoft.AspNetCore.Authorization | (Commented out) Policy-based auth for restricting access |
| Microsoft.EntityFrameworkCore | ORM for database interactions |
| Microsoft.Extensions.Configuration | Configuration abstraction for settings |
| IrbyImaging.DomainClasses | Domain models (e.g., Issue) support business entities |
| IrbyImaging.UI.Controllers.BaseController | Shared controller logic |
🏗 Class Diagram (UML)
classDiagram
BaseController <|-- IssuesController
IssuesController o-- IrbyContext
IssuesController .. IConfiguration
BaseController <--|> Controller
IrbyContext <|-- DbContext
class Issue {
+Guid Id
+string Description
}
IssuesController : +Index()
IssuesController : +Details(Guid? id)
IssuesController : +Create()
IssuesController : +Create(Issue issue)
IssuesController : +Edit(Guid? id)
IssuesController : +Edit(Guid id, Issue issue)
IssuesController : +Delete(Guid? id)
IssuesController : +DeleteConfirmed(Guid id)
IssuesController : -bool IssueExists(Guid id)
🎯 Key Functional Areas
4.1 Index
- Route: GET
/Issues - Method:
public async Task<IActionResult> Index() - Description: Fetches all issues from the database and renders the Index view.
public async Task<IActionResult> Index()
{
var list = await _context.DefaultIssues.ToListAsync();
return View(list);
}
4.2 Details
- Route: GET
/Issues/Details/{id} - Method:
public async Task<IActionResult> Details(Guid? id) - Description: Shows details for a specific issue. Returns
404 NotFoundifidis null or not found.
public async Task<IActionResult> Details(Guid? id)
{
if (id == null) return NotFound();
var issue = await _context.DefaultIssues.FirstOrDefaultAsync(m => m.Id == id);
if (issue == null) return NotFound();
return View(issue);
}
4.3 Create
4.3.1 Create (GET)
- Route: GET
/Issues/Create - Method:
public IActionResult Create() - Description: Renders an empty form for creating a new issue.
public IActionResult Create()
{
return View();
}
4.3.2 Create (POST)
- Route: POST
/Issues/Create - Method:
public async Task<IActionResult> Create([Bind("Id,Description")] Issue issue) - Description: Validates the model, assigns a new
Guid, saves to DB, redirects to Index.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Description")] Issue issue)
{
if (ModelState.IsValid)
{
issue.Id = Guid.NewGuid();
_context.Add(issue);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(issue);
}
4.4 Edit
4.4.1 Edit (GET)
- Route: GET
/Issues/Edit/{id} - Method:
public async Task<IActionResult> Edit(Guid? id) - Description: Loads an existing issue into the edit form. Returns
404if missing.
public async Task<IActionResult> Edit(Guid? id)
{
if (id == null) return NotFound();
var issue = await _context.DefaultIssues.FindAsync(id);
if (issue == null) return NotFound();
return View(issue);
}
4.4.2 Edit (POST)
- Route: POST
/Issues/Edit/{id} - Method:
public async Task<IActionResult> Edit(Guid id, [Bind("Id,Description")] Issue issue) - Description: Persists changes, handles concurrency conflicts via
DbUpdateConcurrencyException.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Guid id, [Bind("Id,Description")] Issue issue)
{
if (id != issue.Id) return NotFound();
if (ModelState.IsValid)
{
try
{
_context.Update(issue);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!IssueExists(issue.Id)) return NotFound();
else throw;
}
return RedirectToAction(nameof(Index));
}
return View(issue);
}
4.5 Delete
4.5.1 Delete (GET)
- Route: GET
/Issues/Delete/{id} - Method:
public async Task<IActionResult> Delete(Guid? id) - Description: Prompts for confirmation. Returns
404if missing.
public async Task<IActionResult> Delete(Guid? id)
{
if (id == null) return NotFound();
var issue = await _context.DefaultIssues.FirstOrDefaultAsync(m => m.Id == id);
if (issue == null) return NotFound();
return View(issue);
}
4.5.2 DeleteConfirmed (POST)
- Route: POST
/Issues/Delete/{id} - Method:
public async Task<IActionResult> DeleteConfirmed(Guid id) - Description: Deletes the issue and redirects to Index.
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(Guid id)
{
var issue = await _context.DefaultIssues.FindAsync(id);
_context.DefaultIssues.Remove(issue);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
📦 Data Model: Issue
Namespace:
IrbyImaging.DomainClasses
public class Issue
{
public Guid Id { get; set; }
public string Description { get; set; }
}
- Id: Primary key (GUID)
- Description: Textual summary of the issue
🔄 API Endpoints Overview
| HTTP Verb | Route | Action | Description |
|---|---|---|---|
| GET | /Issues |
Index | List all issues |
| GET | /Issues/Details/{id} |
Details | View details of a specific issue |
| GET | /Issues/Create |
Create (GET) | Show create form |
| POST | /Issues/Create |
Create (POST) | Submit new issue |
| GET | /Issues/Edit/{id} |
Edit (GET) | Show edit form for an existing issue |
| POST | /Issues/Edit/{id} |
Edit (POST) | Submit updates for an existing issue |
| GET | /Issues/Delete/{id} |
Delete (GET) | Confirm deletion of an issue |
| POST | /Issues/Delete/{id} |
DeleteConfirmed (POST) | Perform deletion of the issue |
⚙️ Helper Methods & Utilities
| Method | Visibility | Description |
|---|---|---|
IssueExists(id) |
Private | Checks if an Issue with the given Guid exists in the database. |
private bool IssueExists(Guid id)
{
return _context.DefaultIssues.Any(e => e.Id == id);
}
🚨 Error Handling & Return Types
- 404 NotFound
- When
idis null or no matching record found inDetails,Edit, orDeletemethods.
- When
- ConcurrencyException
- The POST
Editmethod catchesDbUpdateConcurrencyException, verifies existence, and rethrows if unexpected.
- The POST
- Redirects
- Successful creates, edits, and deletes redirect to Index().
- ModelState Validation
- All POST actions respect
ModelState.IsValidto prevent overposting and invalid data persistence.
- All POST actions respect
- Anti-Forgery
[ValidateAntiForgeryToken]protects POST actions from CSRF attacks.
💡 Usage Examples
1. Viewing All Issues
GET /Issues
- HTTP 200 → Renders
Views/Issues/Index.cshtmlwith a table of issues.
2. Creating a New Issue (via cURL)
curl -X POST https://yourdomain.com/Issues/Create \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "Description=New+hardware+failure" \
-H "RequestVerificationToken: <token-from-form>"
3. Editing an Issue
GET /Issues/Edit/3fa85f64-5717-4562-b3fc-2c963f66afa6
- Loads the form.
- Submit changes to the same route via POST.
🎉 Conclusion
The IssuesController is a standard ASP.NET Core MVC controller providing full CRUD capabilities for Issue entities. It follows best practices:
- Dependency Injection for
IrbyContext&IConfiguration - Entity Framework Core for data access
- Model Binding & Validation for security
- Clear Routing conventions for maintainability
Use this documentation to understand, extend, or maintain the IssuesController in your IrbyImaging application. Feel free to reach out for any clarifications! 🚀