📄 RequestOptionForDetailsViewModel.cs Documentation


📑 Table of Contents

  1. Overview & Purpose
  2. Class Diagram (UML)
  3. Properties
  4. Constructor & Initialization
  5. Sample Usage & Code Snippets
  6. Dependencies & Technologies
  7. Third‑Party Integrations
  8. Conclusion

🔍 Overview & Purpose

The RequestOptionForDetailsViewModel class is part of the IrbyImaging.UI assembly.
It wraps a simpler RequestOptionViewModel to prepare data for detailed views in the UI—especially generating HTML snippets for completion status and approval workflows.

  • Namespace: IrbyImaging.ViewModels
  • Author: kvamshi
  • Created On: 2022-05-17

Key Responsibilities

  • Transform raw request option data into a rich view model for display.
  • Provide HTML-markup-ready properties for “Completed” / “Not Completed” badges.
  • Surface approval status, department, and messages in a detail page.

📊 Class Diagram (UML)

classDiagram
    class RequestOptionForDetailsViewModel {
        +int Index
        +string Item
        +string CompletionMark
        +bool ApprovalRequired
        +string ApprovalDepartment
        +bool HasApprovalDecision
        +bool IsApproved
        +string ApprovalMessage
        +RequestOptionForDetailsViewModel(RequestOptionViewModel)
    }

    RequestOptionViewModel --> RequestOptionForDetailsViewModel : uses

📋 Properties

Property Type Description
Index int The 0-based position of the option in the parent request.
Item string The label or name of this option item.
CompletionMark string An HTML snippet displaying a green check or red cross based on completion status.
ApprovalRequired bool Indicates if this option needs approval.
ApprovalDepartment string The department responsible for approving this option.
HasApprovalDecision bool true if an approval decision has already been made; otherwise false.
IsApproved bool true if the option was approved; false if denied.
ApprovalMessage string A custom message or comment provided by the approver (if any).

🚀 Constructor & Initialization

/// <summary>
/// Initializes a new instance by mapping a RequestOptionViewModel
/// to the details‑specific view model, including HTML for badges.
/// </summary>
/// <param name="Request">
/// The source RequestOptionViewModel to transform.
/// </param>
public RequestOptionForDetailsViewModel(RequestOptionViewModel Request)
{
    Index                = Request.Index;
    Item                 = Request.Item;
    // Render a green or red Bootstrap-styled badge
    CompletionMark       = Request.IsCompleted 
                            ? "<a href=\"#\" class=\"btn btn-success btn-xs\"><span class=\"glyphicon glyphicon-ok\"></span></a>" 
                            : "<a href=\"#\" class=\"btn btn-danger btn-xs\"><span class=\"glyphicon glyphicon-remove\"></span></a>";
    ApprovalRequired     = Request.ApprovalRequired;
    ApprovalDepartment   = Request.ApprovalDepartment;
    HasApprovalDecision  = Request.HasApprovalDecision;
    IsApproved           = Request.IsApproved;
    ApprovalMessage      = Request.ApprovalMessage;
}

Details

  • HTML Markup 🌟
    Uses Bootstrap CSS classes and Glyphicons to render a clickable badge—even though the href="#" is a placeholder.
  • Property Mapping
    Straightforward pass‑through for all non-HTML properties.

💻 Sample Usage & Code Snippets

1. Instantiating in C# Controller

// Assume you have a list of RequestOptionViewModel from your service
List<RequestOptionViewModel> rawOptions = _requestService.GetOptions(requestId);

// Convert to details VMs
var detailedOptions = rawOptions
    .Select(o => new RequestOptionForDetailsViewModel(o))
    .ToList();

// Pass to View:
return View("RequestDetails", detailedOptions);

2. Rendering in Razor View

<table class="table table-striped">
    <thead>
        <tr>
            <th>#</th>
            <th>Option</th>
            <th>Status</th>
            <th>Approval Dept.</th>
            <th>Approved?</th>
            <th>Message</th>
        </tr>
    </thead>
    <tbody>
        @foreach(var opt in Model /* List<RequestOptionForDetailsViewModel> */) {
            <tr>
                <td>@opt.Index</td>
                <td>@opt.Item</td>
                <td>@Raw(opt.CompletionMark)</td>
                <td>@opt.ApprovalDepartment</td>
                <td>
                    @if (!opt.ApprovalRequired) {
                        <span class="label label-default">N/A</span>
                    } else if (!opt.HasApprovalDecision) {
                        <span class="label label-warning">Pending</span>
                    } else if (opt.IsApproved) {
                        <span class="label label-success">Approved</span>
                    } else {
                        <span class="label label-danger">Denied</span>
                    }
                </td>
                <td>@opt.ApprovalMessage</td>
            </tr>
        }
    </tbody>
</table>

🔗 Dependencies & Technologies

  • .NET / C# – Target framework for the UI layer
  • Bootstrap 3.x – For buttons and glyphicons styling
  • ASP.NET MVC / Razor – Typical host for view models

🛠️ Third‑Party Integrations

  • Bootstrap Glyphicons
    • Used in CompletionMark to display ✔️ / ❌ icons.
  • HTML Helpers
    • Razor’s @Raw() to inject pre-formatted HTML strings.

📝 Conclusion

The RequestOptionForDetailsViewModel streamlines the process of displaying request‑specific options in a detailed view. By encapsulating HTML badge generation and approval metadata, it keeps your controller and Razor views clean and focused on presentation. Simply map your raw RequestOptionViewModel items to this class to unlock:

  • ✅ Visual completion indicators
  • 🏢 Approval workflow details
  • 🔄 Consistent rendering across views

Feel free to extend or modify its HTML templates for newer Bootstrap versions or custom styling!