πŸ“– NetworkEquipmentEditViewModel Documentation


πŸ—‚οΈ Table of Contents

  1. Overview & Purpose
  2. Context & Architectural Role
  3. Class Diagram (UML)
  4. Key Functional Areas
  5. Dependencies & Technologies
  6. Code Walkthrough
  7. Usage Example
  8. Integration in MVC Flow
  9. Extending the ViewModel
  10. Conclusion

1. Overview & Purpose

File: IrbyImaging/Models/NetworkEquipment/NetworkEquipmentEditViewModel.cs
Assembly: IrbyImaging.UI
Author: kvamshi
Created / Last Modified: 03-31-2022

NetworkEquipmentEditViewModel is a ViewModel used in the IrbyImaging web application, specifically for editing Network Equipment entities within an MVC-based UI. It inherits all basic editing functionality from the shared EditViewModel base class and serves as a strongly‑typed model for your β€œEdit Network Equipment” views.


2. Context & Architectural Role

In an ASP.NET MVC (or Razor Pages) application, ViewModels encapsulate data and validation logic required by your views. They sit between:

  • Controllers (handling HTTP requests)
  • Domain / Data Models (representing persistence)
  • Razor Views (rendering HTML)

This particular ViewModel:

  • Carries network equipment data to/from the Edit view.
  • Provides client‑side and server‑side validation via Data Annotations (inherited).
  • Keeps UI‑specific logic out of your domain entities.

3. Class Diagram (UML)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        EditViewModel          │◄───────────┐
│────────────────────────────────│            β”‚ inherits
β”‚ + Id: Guid                     β”‚            β”‚
β”‚ + CreatedBy: string            β”‚            β”‚
β”‚ + CreatedDate: DateTime        β”‚            β”‚
β”‚ + ModifiedBy: string           β”‚            β”‚
β”‚ + ModifiedDate: DateTime       β”‚            β”‚
β”‚ + IsActive: bool               β”‚            β”‚
β”‚ + Validate(): IEnumerable      β”‚            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
                                              
           β–² inherits                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚                                 β”‚ NetworkEquipmentEditViewModel     β”‚
           β”‚                                 │───────────────────────────────────│
           β”‚                                 β”‚  (no additional properties yet)   β”‚
           └──────────────────────────────────                                   β”‚
                                             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

4. Key Functional Areas

Area Description
Inheritance Extends EditViewModel to reuse common editing fields and validation.
Scaffold Placeholder Currently emptyβ€”serves as a spot to add NetworkEquipment‑specific edit properties in the future.
Validation Leverages Data Annotation attributes on base class for required‑field checks.
UI Binding Provides strong typing for Razor views (@model NetworkEquipmentEditViewModel).

5. Dependencies & Technologies

  • ASP.NET Core MVC / Razor
  • System.ComponentModel.DataAnnotations (inherited for validation)
  • IrbyImaging.Models namespace
  • EditViewModel base class
namespace IrbyImaging.Models
{
    public abstract class EditViewModel
    {
        [Required]
        public Guid Id { get; set; }

        public DateTime CreatedDate { get; set; }
        public string CreatedBy { get; set; }

        public DateTime? ModifiedDate { get; set; }
        public string ModifiedBy { get; set; }

        public bool IsActive { get; set; } = true;
    }
}

6. Code Walkthrough

// NetworkEquipmentEditViewModel.cs
namespace IrbyImaging.Models
{
    /// <summary>
    /// ViewModel for editing a Network Equipment entity.
    /// Inherits from EditViewModel for common fields.
    /// </summary>
    public class NetworkEquipmentEditViewModel : EditViewModel
    {
        // 🚧 Add network‑equipment-specific fields here.
        // e.g. public string Hostname { get; set; }
        //      [Display(Name="IP Address")]
        //      [RegularExpression(...)]
        //      public string IPAddress { get; set; }
    }
}
  • Namespace: Groups this class under the IrbyImaging.Models assembly.
  • XML Documentation: <summary> and <seealso> tags help generate API docs.
  • Class Signature: public class NetworkEquipmentEditViewModel : EditViewModel

7. Usage Example

7.1. Controller Action

public class NetworkEquipmentController : Controller
{
    // GET: /NetworkEquipment/Edit/{id}
    public IActionResult Edit(Guid id)
    {
        // Fetch domain model from DB/service
        var domainModel = _networkEquipmentService.GetById(id);

        // Map to ViewModel (using AutoMapper or manual mapping)
        var vm = new NetworkEquipmentEditViewModel
        {
            Id = domainModel.Id,
            CreatedDate = domainModel.CreatedDate,
            CreatedBy = domainModel.CreatedBy,
            ModifiedDate = domainModel.ModifiedDate,
            ModifiedBy = domainModel.ModifiedBy,
            IsActive = domainModel.IsActive
            // TODO: Map network equipment fields
        };

        return View(vm);
    }

    [HttpPost]
    public IActionResult Edit(NetworkEquipmentEditViewModel vm)
    {
        if (!ModelState.IsValid)
        {
            return View(vm);
        }

        // Map ViewModel back to domain model
        var domainModel = new NetworkEquipment
        {
            Id = vm.Id,
            // ...
        };

        _networkEquipmentService.Update(domainModel);
        return RedirectToAction("Index");
    }
}

7.2. Razor View Snippet

@model IrbyImaging.Models.NetworkEquipmentEditViewModel

<h2>Edit Network Equipment</h2>

<form asp-action="Edit" method="post">
    <input asp-for="Id" type="hidden" />

    <div class="form-group">
        <label asp-for="IsActive"></label>
        <input asp-for="IsActive" class="form-control" />
    </div>

    <!-- 🚧 Add your custom fields here -->
    <!-- e.g.
    <div class="form-group">
        <label asp-for="IPAddress"></label>
        <input asp-for="IPAddress" class="form-control" />
        <span asp-validation-for="IPAddress" class="text-danger"></span>
    </div>
    -->

    <button type="submit" class="btn btn-primary">Save</button>
</form>

8. Integration in MVC Flow

  1. Routing

    • GET /NetworkEquipment/Edit/{id} to populate form.
    • POST /NetworkEquipment/Edit to submit updates.
  2. Model Binding & Validation

    • ASP.NET automatically binds form fields to the NetworkEquipmentEditViewModel.
    • DataAnnotations on EditViewModel enforce required fields, etc.
  3. Mapping

    • Use AutoMapper (or manual mapping) in Controllers to convert between domain models and view models.
  4. Error Handling

    • ModelState.IsValid guards against invalid input.
    • Display validation messages in Razor with asp-validation-for.

9. Extending the ViewModel

As your app’s needs grow, you’ll likely add properties such as:

Property Name Type Annotations Purpose
Hostname string [Required], [StringLength(100)] Equipment hostname
IPAddress string [RegularExpression(...)] Validates IPv4/IPv6 format
Location string [Display(Name="Rack/Room")] Where the device is physically located
PurchaseDate DateTime [DataType(DataType.Date)] Acquisition date

❗ Tip: Always annotate fields with [Display(Name="…")] and validation attributes for a better UX.


10. Conclusion

🎯 NetworkEquipmentEditViewModel is a lightweight, extendable ViewModel designed to streamline the Edit experience for network equipment records in the IrbyImaging application. By inheriting from a shared base class, it promotes code reuse, consistency, and maintainability.

Feel free to extend it with custom properties, wire it up with your controller logic, and leverage Razor’s tag helpers for rapid UI development!


Happy Coding! πŸš€