📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Class:
RequestOptionForUpdateViewModel - UML Class Diagram
- Usage Examples
- Conclusion
🌟 Overview & Purpose
The RequestOptionForUpdateViewModel is part of the IrbyImaging.UI project. It transforms an existing RequestOptionViewModel into a model fitted for rendering and updating options in the UI.
- It encapsulates both the raw data (index, text, approval details) and an HTML snippet (
Input) to display a “Mark Complete” toggle. - Designed for MVC/Razor views, it helps build forms where each request option can be marked complete and shows approval state & messages.
🔧 Dependencies & Technologies
| Category | Description |
|---|---|
| Platform | .NET (C#) |
| Namespace | IrbyImaging.ViewModels |
| Related ViewModel | RequestOptionViewModel (input model) |
| Front‑End Library | Bootstrap CSS classes (btn, btn-xs) |
| Browser Behavior | Uses data-toggle="buttons" for toggle UI |
🚀 Key Functional Areas
- Data Mapping
- Converts a
RequestOptionViewModelinto an updatable model.
- Converts a
- HTML Generation
- Produces a small HTML fragment for a “Mark Complete” button group.
- Approval Workflow
- Carries approval metadata (required, department, decision, message).
🏗️ Class: RequestOptionForUpdateViewModel
Properties
| Property | Type | Description |
|---|---|---|
| Index | int |
Position or identifier of the option. |
| Item | string |
The display text of the request option. |
| Input | string |
HTML snippet for “Mark Complete” control (empty if already completed). |
| ApprovalRequired | bool |
Indicates if approval is needed. |
| ApprovalDepartment | string |
Department responsible for approval. |
| HasApprovalDecision | bool |
Whether a decision has been made. |
| IsApproved | bool |
Indicates final approval status. |
| ApprovalMessage | string |
Optional message from the approver. |
Constructor
/// <summary>
/// Initializes a new instance of the RequestOptionForUpdateViewModel
/// by mapping from a RequestOptionViewModel.
/// </summary>
/// <param name="request">The source view model.</param>
public RequestOptionForUpdateViewModel(RequestOptionViewModel request)
{
Index = request.Index;
Item = request.Item;
Input = GenerateHtml(Index, Item, request.IsCompleted);
ApprovalRequired = request.ApprovalRequired;
ApprovalDepartment = request.ApprovalDepartment;
HasApprovalDecision = request.HasApprovalDecision;
IsApproved = request.IsApproved;
ApprovalMessage = request.ApprovalMessage;
}
- Purpose: Copies data from the source model and invokes
GenerateHtmlto build theInputproperty.
Methods
GenerateHtml(int index, string item, bool isCompleted)
/// <summary>
/// Builds the HTML string for the “Mark Complete” toggle button.
/// Returns an empty string if the option is already completed.
/// </summary>
/// <param name="index">Unique index for DOM IDs</param>
/// <param name="item">Label text (unused directly in HTML)</param>
/// <param name="isCompleted">If true, skip rendering control</param>
/// <returns>HTML string</returns>
private string GenerateHtml(int index, string item, bool isCompleted)
{
// If already completed, no toggle is needed.
if (isCompleted)
return string.Empty;
// Otherwise render a Bootstrap-styled toggle button.
return "<div class='btn-group' data-toggle='buttons' style='margin-bottom: 4px'>" +
$"<label class=\"btn btn-warning btn-xs\" id=\"label{index}\">" +
$"<input type=\"checkbox\" autocomplete=\"off\" id=\"checkbox{index}\">" +
$"<span id='span{index}'>Mark Complete</span>" +
"</label></div>";
}
- Logic
- Checks
isCompleted; if true, suppresses the control (read‑only state). - Otherwise, uses Bootstrap classes to create a compact checkbox toggle.
- Checks
📐 UML Class Diagram
+----------------------------------------------------------+
| RequestOptionForUpdateViewModel |
+----------------------------------------------------------+
| - Index: int |
| - Item: string |
| - Input: string |
| - ApprovalRequired: bool |
| - ApprovalDepartment: string |
| - HasApprovalDecision: bool |
| - IsApproved: bool |
| - ApprovalMessage: string |
+----------------------------------------------------------+
| + RequestOptionForUpdateViewModel(request: RequestOptionViewModel) |
| - GenerateHtml(index: int, item: string, isCompleted: bool): string|
+----------------------------------------------------------+
🔧 Usage Examples
1. Constructing the ViewModel
// Suppose you have the original RequestOptionViewModel list
List<RequestOptionForUpdateViewModel> updateModels = originalList
.Select(r => new RequestOptionForUpdateViewModel(r))
.ToList();
2. Rendering in a Razor View
@model IEnumerable<RequestOptionForUpdateViewModel>
<table class="table">
<thead>
<tr><th>#</th><th>Option</th><th>Action</th><th>Approval</th></tr>
</thead>
<tbody>
@foreach(var opt in Model)
{
<tr>
<td>@opt.Index</td>
<td>@opt.Item</td>
<td>
@Html.Raw(opt.Input) <!-- Renders the Mark Complete toggle -->
</td>
<td>
@if(opt.HasApprovalDecision) {
<span class="badge @(opt.IsApproved ? "badge-success" : "badge-danger")">
@opt.ApprovalMessage
</span>
} else {
<em>Pending (@opt.ApprovalDepartment)</em>
}
</td>
</tr>
}
</tbody>
</table>
3. Handling Post-Back
[HttpPost]
public IActionResult UpdateOptions(List<RequestOptionForUpdateViewModel> model)
{
// Iterate and check checkboxes via form values (e.g., Request.Form)
// Apply business logic, save updates, send for approval, etc.
return RedirectToAction("Index");
}
⚠️ Error Handling & Edge Cases
- Completed Items: No toggle rendered → UI cannot re‑toggle a completed option.
- Unique IDs:
indexmust be unique per page render to avoid duplicate element IDs. - Null Input: Assumes
RequestOptionViewModelis non-null and has non-nullItem.
✅ Conclusion
The RequestOptionForUpdateViewModel is a focused ViewModel that:
- Maps raw request option data.
- Augments it with an HTML control snippet for user interaction.
- Carries approval workflow metadata.
This design cleanly separates concerns:
- Data Transfer (ViewModel)
- Presentation Logic (HTML generation)
Use it in your MVC/Razor pages to build intuitive, toggle‑based request update forms! 🚀