πŸ“„ Edit Computer View Documentation (Edit.cshtml)


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Models
  4. Key Components & Tag Helpers
  5. Form Fields Breakdown
  6. Validation & Error Handling
  7. Scripts & Partial Views
  8. Controller Interaction & API Endpoints
  9. UML Diagrams
  10. Usage Examples
  11. Conclusion

1. πŸ“ Overview & Purpose

The Edit.cshtml view under IrbyImaging/Views/Computers/ is a Razor page used to render and process the β€œUpdate Computer” form in an ASP.NET Core MVC application.

  • Intended Use: Allows administrators or power users to modify existing computer assets (serial numbers, status, owner, notes, etc.).
  • Layout: Inherits from ~/Views/Shared/_ATSLayout.cshtml to maintain consistent look-and-feel.
  • Model Binding: Strongly-typed to ComputerEditViewModel, ensuring compile-time safety.

2. πŸ”§ Dependencies & Technologies

Technology / Library Role
ASP.NET Core MVC MVC framework & Tag Helpers
Razor (cshtml) Server-side templating
Bootstrap 5 Responsive styling & layout
MetisMenu, Simplebar, Waves UI enhancements & interactive components
jQuery Validation Client-side form validation (via _ValidationScriptsPartial)
Partial Views Reusable error modal (_ErrorModalPartial)

3. 🧩 View Model & Data Models

ComputerEditViewModel

public class ComputerEditViewModel
{
    public int Id { get; set; }
    public int ModelId { get; set; }
    public IEnumerable<SelectListItem> ModelList { get; set; }
    public string SerialNumber { get; set; }
    public string AssetNumber { get; set; }
    public string UnitNumber { get; set; }
    public string CpsNumber { get; set; }
    public int OperatingSystemId { get; set; }
    public IEnumerable<SelectListItem> OperatingSystemList { get; set; }
    public DateTime PurchaseDate { get; set; }
    public int OwnerId { get; set; }
    public IEnumerable<SelectListItem> OwnerList { get; set; }
    public AssetStatus Status { get; set; }
    public bool NeedsReview { get; set; }
    public string Notes { get; set; }
    public string Reason { get; set; }
    public string ErrorMessage { get; set; }
}

AssetStatus Enum (Excerpt)

public enum AssetStatus
{
    All,
    Active,
    Inactive,
    Retired,
    UnderMaintenance
}

4. ✨ Key Components & Tag Helpers

Element Tag Helper / Attribute Purpose
<form> asp-action="EditComputer" Posts form data to EditComputer endpoint
<input> / <select> / <textarea> asp-for Binds form control to model property
<select> asp-items Populates dropdown via Model.*List
Validation messages asp-validation-summary / asp-validation-for Displays server- & client-side validation errors

5. πŸ–₯️ Form Fields Breakdown

Label Control Type Bound Property Description
Model Select ModelId / ModelList Choose computer model from pre-loaded list
Serial Number Text SerialNumber Unique identifier from manufacturer
Asset Number Text AssetNumber Company-assigned asset tag
Unit Number Text UnitNumber Internal unit reference
CPS Number Text CpsNumber Service tracking code
Operating System Select OperatingSystemId / OperatingSystemList OS selection dropdown
Purchase Date Date/Text PurchaseDate Date of acquisition
Owner Select OwnerId / OwnerList Select current owner from employee list
Status Select Status Enum-driven statuses (excludes β€œAll”)
Needs Review Checkbox NeedsReview Flag if asset requires review
Notes Textarea Notes Free-form notes and remarks
Reason Textarea Reason Reason for update/change

6. ⚠️ Validation & Error Handling

  • Server-side:

    • The asp-validation-summary="ModelOnly" placeholder displays model-level errors.
    • Each field has asp-validation-for to show property-level errors.
  • Client-side:

    • _ValidationScriptsPartial injects jQuery Validate & Unobtrusive scripts.
    • Real-time input validation before submission.
  • Error Modal:

    • If Model.ErrorMessage is not empty, the view renders _ErrorModalPartial to show a Bootstrap modal with the message.
@if (!string.IsNullOrEmpty(Model.ErrorMessage)) {
    await Html.RenderPartialAsync("_ErrorModalPartial");
}

7. πŸ› οΈ Scripts & Partial Views

<!-- Core JS 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>

@section Scripts {
    @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
    @{ await Html.RenderPartialAsync("_ErrorModalScriptsPartial"); }
}
  • _ValidationScriptsPartial: Enables unobtrusive and client validation.
  • _ErrorModalScriptsPartial: Handles modal open/close logic for error messages.

8. πŸ”— Controller Interaction & API Endpoints

GET: Edit (Display Form)

public IActionResult Edit(int id)
{
    var vm = _computerService.GetEditModel(id);
    return View(vm);
}
  • Path: /Computers/Edit/{id}
  • Function: Populates ComputerEditViewModel and renders Edit.cshtml.

POST: EditComputer (Process Submission)

[HttpPost]
public IActionResult EditComputer(ComputerEditViewModel model)
{
    if (!ModelState.IsValid)
    {
        // Re-populate dropdowns...
        return View("Edit", model);
    }
    var result = _computerService.Update(model);
    if (!result.Success)
    {
        model.ErrorMessage = result.ErrorMessage;
        return View("Edit", model);
    }
    return RedirectToAction("Index");
}
  • Path: /Computers/EditComputer
  • Behavior: Validates & updates the computer record, handles errors, and redirects back to index.

9. πŸ“Š UML Diagrams

Class Diagram

@startuml
class ComputerEditViewModel {
    +int Id
    +int ModelId
    +List<SelectListItem> ModelList
    +string SerialNumber
    +string AssetNumber
    +string UnitNumber
    +string CpsNumber
    +int OperatingSystemId
    +List<SelectListItem> OperatingSystemList
    +DateTime PurchaseDate
    +int OwnerId
    +List<SelectListItem> OwnerList
    +AssetStatus Status
    +bool NeedsReview
    +string Notes
    +string Reason
    +string ErrorMessage
}
class ComputersController {
    +IActionResult Edit(int id)
    +IActionResult EditComputer(ComputerEditViewModel vm)
}
ComputerEditViewModel <|-- Edit.cshtml
ComputersController ..> ComputerEditViewModel
@enduml

Sequence Diagram

@startuml
actor User
User -> Browser: Click β€œEdit” link
Browser -> ComputersController : GET /Computers/Edit/{id}
ComputersController -> Database: Fetch asset + lists
Database --> ComputersController: Return data
ComputersController -> Browser: Render Edit.cshtml(vm)
Browser -> User: Display form
User -> Browser: Submit β€œUpdate”
Browser -> ComputersController: POST /Computers/EditComputer(vm)
ComputersController -> Service: Validate & Update
Service --> ComputersController: Result
alt Success
    ComputersController -> Browser: Redirect to Index
else Failure
    ComputersController -> Browser: Render Edit.cshtml(with errors)
end
@enduml

10. πŸš€ Usage Examples

Rendering the Edit Form

// In ComputersController
public IActionResult Edit(int id)
{
    var vm = _computerService.GetEditModel(id);
    return View(vm);  // Renders Edit.cshtml
}

Handling Form Submission

[HttpPost]
public IActionResult EditComputer(ComputerEditViewModel model)
{
    if (!ModelState.IsValid)
    {
        model = _computerService.RefreshLists(model);
        return View("Edit", model);
    }
    var updateResult = _computerService.Update(model);
    if (!updateResult.Success)
    {
        model.ErrorMessage = updateResult.ErrorMessage;
        model = _computerService.RefreshLists(model);
        return View("Edit", model);
    }
    return RedirectToAction("Index");
}

11. 🎯 Conclusion

The Edit.cshtml view is a critical part of the Computers management UI in IrbyImaging. It:

  • Provides a full-featured form for updating computer assets.
  • Leverages ASP.NET Core Tag Helpers for clean, strongly-typed markup.
  • Integrates client/server validation, error modal, and partial views for a robust user experience.
  • Connects seamlessly to the ComputersController endpoints for GET/POST operations.

By adhering to this structure, the application ensures consistency, maintainability, and ease of extension for future asset management requirements.


Happy coding! πŸ–₯️✨