đ RequestViewModel.cs Documentation
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Class Diagram (UML)
- Key Functional Areas
- Properties & Data Annotations
- Data Validation / Error Handling
- Usage Examples
- Thirdâparty Integrations & Utilities
- Conclusion
1. Overview & Purpose
The RequestViewModel class is part of the IrbyImaging.UI project and is primarily used to represent all the data needed when creating, editing, or viewing a service request (tickets) in the web application. It gathers customer details, job metadata, selection options (hardware, software, etc.), file attachments, and audit fields into a single stronglyâtyped object that can be bound to Razor views and validated on the server side.
Use Cases:
- Create a new ticket/request
- Edit an existing ticket/request
- Display details of a ticket/request
2. Dependencies & Technologies
| Technology / Namespace | Purpose |
|---|---|
Microsoft.AspNetCore.Mvc |
MVC attributes ([HiddenInput]) and model binding |
Microsoft.AspNetCore.Mvc.Rendering |
SelectListItem & SelectList for dropdowns |
System.ComponentModel.DataAnnotations |
Builtâin validation attributes ([Required], [EmailAddress], etc.) |
Microsoft.AspNetCore.Http |
IFormFile support for file uploads |
IrbyImaging.DomainClasses |
Domain enums (TicketStatus, TicketType) & model classes (Update) |
IrbyImaging.Utility |
(Imported; provide general utilities in the project) |
3. Class Diagram (UML)
@startuml
class RequestViewModel {
+Guid Id
+int TicketNumber
+string CustomerName
+string CustomerUsername
+string ResponseEmail
+string UserEmail
+string CallBackNumber
+string Description
+string RequestedJson
+bool IsNewEmployee
+string NameOfNewEmployee
+string StreetAddress
+string City
+string State
+string Zip
+string EmployeeNumber
+string JobNumber
+List<SelectListItem> JobData
+string JobDepartment
+string JobTitle
+TicketStatus Status
+TicketType Type
+IFormFile File
+byte[] ImageContents
+string ShippingAddress
+ICollection<RequestOptionForCreateViewModel> HardwareOptions
+ICollection<RequestOptionForCreateViewModel> SoftwareOptions
+ICollection<RequestOptionForCreateViewModel> EnterpriseOptions
+ICollection<RequestOptionForCreateViewModel> AccessOptions
+ICollection<RequestOptionForCreateViewModel> SystemOptions
+ICollection<RequestOptionForDetailsViewModel> HardwareRequests
+ICollection<RequestOptionForDetailsViewModel> SoftwareRequests
+ICollection<RequestOptionForDetailsViewModel> EnterpriseRequests
+ICollection<RequestOptionForDetailsViewModel> AccessRequests
+ICollection<RequestOptionForDetailsViewModel> SystemRequests
+ICollection<Update> Updates
+string OtherRequests
+SelectList CustomerList
+DateTime CreatedOn
+string CreatedBy
+DateTime UpdatedOn
+string UpdatedBy
}
@enduml
4. Key Functional Areas
-
Customer & Contact Info
Gathers requestor details such as name, email, callback number. -
Job & Department Metadata
Identifies the job number, department, title, and builds dropdowns for selection. -
Request Options
- Create: Sets up which hardware/software (etc.) can be requested.
- Details: Displays what was actually requested per category.
-
File Upload & Image Handling
Accepts an attached file (IFormFile) and/or raw image bytes. -
Audit Trail
Tracks creation and update timestamps and user identifiers.
5. Properties & Data Annotations
Customer Information
| Property | Data Type | Display Name | Validation |
|---|---|---|---|
| Id | Guid |
â | â |
| TicketNumber | int |
â | â |
| CustomerName | string |
* Requested For |
Required, HiddenInput |
| CustomerUsername | string |
â | Required |
Contact Information
| Property | Data Type | Display Name | Validation |
|---|---|---|---|
| ResponseEmail | string |
* Response Email |
Required, EmailAddress |
| UserEmail | string |
* User Email |
â |
| CallBackNumber | string |
* Callback Number |
Required |
Job Information
| Property | Data Type | Display Name | Validation |
|---|---|---|---|
| JobNumber | string |
* Job Number |
Required |
| JobData | List<SelectListItem> |
â | â |
| JobDepartment | string |
* Job Department |
Required |
| JobTitle | string |
* Job Title |
Required |
Request Options & Selections
- Createâtime Options (
RequestOptionForCreateViewModel):HardwareOptions,SoftwareOptions,EnterpriseOptions,AccessOptions,SystemOptions
- Detailâtime Requests (
RequestOptionForDetailsViewModel):HardwareRequests,SoftwareRequests,EnterpriseRequests,AccessRequests,SystemRequests
File Upload & Image Data
| Property | Data Type | Purpose |
|---|---|---|
| File | IFormFile |
Uploaded file (e.g., image) |
| ImageContents | byte[] |
Raw image bytes for preview/save |
Audit & Metadata
| Property | Data Type | Purpose |
|---|---|---|
| CreatedOn | DateTime |
Timestamp when the ticket was created |
| CreatedBy | string |
User who created the ticket |
| UpdatedOn | DateTime |
Timestamp of last update |
| UpdatedBy | string |
User who last modified the ticket |
| Status | TicketStatus |
Current status (enum) |
| Type | TicketType |
Request type/category (enum) |
6. Data Validation / Error Handling
- Uses DataAnnotations:
[Required]ensures mandatory fields (ModelState errors if missing).[EmailAddress]validates proper email format.[HiddenInput]marks fields that should render as hidden in Razor forms.
- In a controller action:
if (!ModelState.IsValid) { // Return view with validation errors return View(requestViewModel); } - Validation messages automatically surfaced in Razor with:
<span asp-validation-for="ResponseEmail" class="text-danger"></span>
7. Usage Examples
Controller Action Snippet
public class RequestsController : Controller
{
// GET: /Requests/Create
public IActionResult Create()
{
var vm = new RequestViewModel
{
JobData = GetJobSelectList(),
CustomerList = GetCustomerSelectList(),
CreatedOn = DateTime.UtcNow,
// Initialize other collections
};
return View(vm);
}
// POST: /Requests/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(RequestViewModel vm)
{
if (!ModelState.IsValid)
return View(vm);
// Map vm to domain model, save to database
var ticket = MapToTicket(vm);
await _ticketService.CreateAsync(ticket);
return RedirectToAction("Details", new { id = ticket.Id });
}
}
Razor View Snippet
@model IrbyImaging.ViewModels.RequestViewModel
<form asp-action="Create" enctype="multipart/form-data" method="post">
<div class="form-group">
<label asp-for="CustomerName"></label>
<input asp-for="CustomerName" class="form-control" />
<span asp-validation-for="CustomerName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="JobNumber"></label>
<select asp-for="JobNumber" asp-items="Model.JobData" class="form-control"></select>
<span asp-validation-for="JobNumber" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="File">Attachment</label>
<input type="file" asp-for="File" class="form-control-file" />
</div>
<!-- Render HardwareOptions checkboxes -->
<fieldset>
<legend>Hardware Options</legend>
@foreach (var option in Model.HardwareOptions)
{
<div class="checkbox">
<label>
<input type="checkbox" name="HardwareOptions" value="@option.Id" />
@option.Name
</label>
</div>
}
</fieldset>
<button type="submit" class="btn btn-primary">Submit Request</button>
</form>
8. Thirdâparty Integrations & Utilities
- SelectList & SelectListItem from ASP.NET Core MVC for populating dropdowns.
- Domain enums
TicketStatus&TicketTypedefine state machine and request categorization. - Potential custom utilities in
IrbyImaging.Utility(e.g., JSON serialization ofRequestedJson, helper functions for mapping viewâmodel â domainâmodel).
9. Conclusion
The RequestViewModel is a central piece in the IrbyImaging UI stack, unifying multiple pieces of dataâcustomer info, job details, request options, file uploads, and audit trailsâinto a single model for seamless rendering, binding, and validation in MVC controllers and Razor views. Its comprehensive property set and data annotations ensure robust serverâside validation and ease of use, while its integration with ASP.NET Core MVC features (hidden inputs, select lists, file uploads) makes it a versatile view model for ticket/request workflows.
Feel free to extend this class (e.g., custom validation attributes, computed readâonly properties) or map it to your domain layer according to your persistence strategy. đ