📄 IrbyImaging.Views.DeskPhones.Create.cshtml Documentation
Table of Contents
- Overview & Purpose 🌟
- Dependencies & Technologies 🔗
- ViewModel & Data Binding 📦
- Layout & Rendering 🎨
- Form Fields & Validation 📝
- Error Handling & Modals ⚠️
- Scripts & Third‑party Integrations 🚀
- UML Diagrams 📈
- Sample Usage & Code Snippets 💻
- Conclusion & Next Steps 🎯
1. Overview & Purpose 🌟
The Create.cshtml view is part of the DeskPhones feature in the IrbyImaging ASP.NET Core MVC application. Its primary goal is to:
- Render a “New Desk Phone” form for administrators or support staff.
- Bind user input to a strongly‑typed
DeskPhoneCreateViewModel. - Perform client‑side and server‑side validation.
- Post the completed form to the
Createaction ofDeskPhonesController.
🎯 Key Use Case: When a new desk phone arrives or is provisioned, staff navigate to /DeskPhones/Create to record its details (model, serial, MAC, owner, status, notes, etc.).
2. Dependencies & Technologies 🔗
| Category | Details |
|---|---|
| Framework | ASP.NET Core MVC (Razor Pages) |
| Layout | _ATSLayout.cshtml (Shared layout for ATS theme) |
| Client‑side scripting | Bootstrap 5, MetisMenu, SimpleBar, node‑waves |
| Validation | jQuery Validation via _ValidationScriptsPartial |
| Styling | Bootstrap CSS, custom IRBY classes (e.g. irby-red, irby-green) |
| Partial Views | _ErrorModalPartial, _ErrorModalScriptsPartial |
3. ViewModel & Data Binding 📦
@model DeskPhoneCreateViewModel
DeskPhoneCreateViewModel Properties
| Property | Type | Description |
|---|---|---|
| ModelId | int | Selected phone model ID |
| ModelList | IEnumerable | Dropdown items for available phone models |
| SerialNumber | string | Phone’s serial number |
| PhoneNumber | string | Assigned phone number |
| MacAddress | string | Hardware MAC address |
| PurchaseDate | DateTime | Date of purchase |
| OwnerId | int | Selected owner/user ID |
| OwnerList | IEnumerable | Dropdown items for users |
| Status | AssetStatus enum | Current asset status (Active, Repair, etc.) |
| Notes | string | Additional free‑form remarks |
| ErrorMessage | string | Server‑side error to display in modal |
4. Layout & Rendering 🎨
@{
ViewData["Title"] = "Create";
Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
<h2>New Desk Phone</h2>
<hr />
ViewData["Title"]sets the browser 〉 tab title to “Create”.Layoutdefines the master layout_ATSLayout.cshtml(common navigation, header, footer).
5. Form Fields & Validation 📝
The form uses the Tag Helpers (asp-for, asp-items, asp-validation-for) for strongly‑typed binding and validation.
Field Summary
| Field | Element | Validation Summary |
|---|---|---|
| Model | <select asp-for="ModelId" asp-items="Model.ModelList"> |
Required selection |
| SerialNumber | <input asp-for="SerialNumber" /> |
Required, unique format |
| PhoneNumber | <input asp-for="PhoneNumber" /> |
Required, phone format |
| MacAddress | <input asp-for="MacAddress" /> |
Required, MAC format |
| PurchaseDate | <input asp-for="PurchaseDate" type="date" /> |
Required, date picker |
| Owner | <select asp-for="OwnerId" asp-items="Model.OwnerList"> |
Required selection |
| Status | <select asp-for="Status"> |
Enum dropdown (excl. “All”) |
| Notes | <textarea asp-for="Notes"> |
Optional |
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
...
<span asp-validation-for="FieldName" class="text-danger"></span>
- Validation Summary shows model‑level errors.
- Validation Messages appear inline per field.
6. Error Handling & Modals ⚠️
At the bottom of the form, any server‑side error captured in Model.ErrorMessage triggers a modal:
@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
await Html.RenderPartialAsync("_ErrorModalPartial");
}
_ErrorModalPartial: A reusable Bootstrap modal that displaysModel.ErrorMessage._ErrorModalScriptsPartial(in@section Scripts) includes the JavaScript to launch the modal.
7. Scripts & Third‑party Integrations 🚀
Outside of @section Scripts, the view references several client libraries:
<script src="~/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/libs/metismenu/metisMenu.min.js"></script>
<script src="~/libs/simplebar/simplebar.min.js"></script>
<script src="~/libs/node-waves/waves.min.js"></script>
In @section Scripts:
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
@{ await Html.RenderPartialAsync("_ErrorModalScriptsPartial"); }
- Bootstrap Bundle: Modal, dropdown, date picker, form styling.
- MetisMenu / SimpleBar / Waves: Sidebar, custom scrollbars, ripple effects.
- jQuery Validation: Unobtrusive client‑side form validation.
8. UML Diagrams 📈
Class Diagram (ViewModel)
classDiagram
class DeskPhoneCreateViewModel {
+int ModelId
+IEnumerable<SelectListItem> ModelList
+string SerialNumber
+string PhoneNumber
+string MacAddress
+DateTime PurchaseDate
+int OwnerId
+IEnumerable<SelectListItem> OwnerList
+AssetStatus Status
+string Notes
+string ErrorMessage
}
Sequence Diagram (Simplified)
sequenceDiagram
participant User
participant Browser
participant Controller as DeskPhonesController
participant Service as DeskPhoneService
participant DB as Repository/DbContext
User->>Browser: Navigate to /DeskPhones/Create
Browser->>Controller: GET Create()
Controller-->>Browser: Render Create.cshtml + ViewModel
User->>Browser: Fill form & Submit
Browser->>Controller: POST Create(viewModel)
Controller->>Service: Validate & Save
Service->>DB: Insert new DeskPhone
DB-->>Service: Confirmation
Service-->>Controller: Success
Controller-->>Browser: Redirect to /DeskPhones/Index
9. Sample Usage & Code Snippets 💻
Controller (Excerpt)
// GET: DeskPhones/Create
public IActionResult Create()
{
var viewModel = _deskPhoneService
.GetCreateViewModel(); // Populates ModelList, OwnerList
return View(viewModel);
}
// POST: DeskPhones/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(DeskPhoneCreateViewModel vm)
{
if (!ModelState.IsValid)
return View(vm);
var result = await _deskPhoneService.CreateDeskPhoneAsync(vm);
if (!result.Succeeded)
{
vm.ErrorMessage = result.Error;
return View(vm);
}
return RedirectToAction(nameof(Index));
}
Form Snippet
<form asp-action="Create">
<div asp-validation-summary="ModelOnly"></div>
<!-- Model -->
<div class="form-group">
<label asp-for="ModelId"></label>
<select asp-for="ModelId" asp-items="Model.ModelList"></select>
</div>
<!-- Serial Number -->
<div class="form-group">
<label asp-for="SerialNumber"></label>
<input asp-for="SerialNumber" class="form-control"/>
<span asp-validation-for="SerialNumber" class="text-danger"></span>
</div>
<!-- Submit -->
<input type="submit" value="Create" class="btn btn-success"/>
</form>
10. Conclusion & Next Steps 🎯
The Create.cshtml view delivers a user‑friendly interface for registering new desk phones in the IrbyImaging system. By leveraging ASP.NET Core MVC Tag Helpers, partial views, and robust client‑side libraries (Bootstrap, jQuery Validation), it ensures:
- Strongly‑typed binding to
DeskPhoneCreateViewModel. - Inline & summary validation for quick feedback.
- Graceful error handling via modals.
- Consistent styling with the global
_ATSLayout.
Next Steps:
- Implement unit tests for the
DeskPhoneServiceand controller. - Extend the view to allow file uploads (photos, PDF manuals).
- Enhance accessibility (ARIA attributes) and mobile responsiveness.
✨ Happy coding! ✨