πŸ–¨οΈ OfficePrinterEditViewModel Documentation

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


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Class Diagram (UML)
  4. Key Functional Areas
  5. Usage Scenarios & Examples
  6. Related Classes & View Models
  7. Error Handling & Validation
  8. Conclusion

πŸ“ Overview & Purpose

The OfficePrinterEditViewModel is a ViewModel used within the IrbyImaging UI layer to drive edit screens for office printers. It encapsulates only the fields required when creating or updating an office printer record, and enriches them with metadata for display and validation.

Main Goals

  • Provide a strongly-typed model for edit forms
  • Leverage data annotations for client/server validation
  • Decouple UI concerns from domain or database entities

πŸ”§ Dependencies & Technologies

Technology / Namespace Purpose
System Base .NET types (e.g., DateTimeOffset)
System.ComponentModel.DataAnnotations Validation and display metadata
IrbyImaging.Models Base EditViewModel and other shared contracts

This ViewModel is suitable for ASP.NET MVC or ASP.NET Core MVC projects.


πŸ“Š Class Diagram (UML)

classDiagram
    class EditViewModel {
      <<abstract>>
      + Guid Id
      + string CreatedBy
      + DateTimeOffset CreatedOn
      + string ModifiedBy
      + DateTimeOffset? ModifiedOn
    }
    class OfficePrinterEditViewModel {
      + string Company
      + DateTimeOffset ContractEndDate
    }
    EditViewModel <|-- OfficePrinterEditViewModel

Note: EditViewModel is assumed to define common edit properties like Id, audit fields, etc.


πŸ”‘ Key Functional Areas

4.1 Inheritance

  • Base Class: EditViewModel
  • Implication: Inherits standard properties (e.g., Id, audit fields) and possibly validation logic used across all edit screens.

4.2 Properties

Property Type Required? Description
Company string βœ“ Name of the printer vendor or leasing partner.
ContractEndDate DateTimeOffset βœ“ When the maintenance/lease contract expires.

4.3 Data Annotations

  • [Display(Name = "Contract End Date")]
    Β Β β€’ Human-friendly label in forms and validation messages.
  • [DataType(DataType.Date)]
    Β Β β€’ Renders a <input type="date" /> (HTML5 date picker) in Razor EditorFor helpers.

πŸš€ Usage Scenarios & Examples

Below are typical patterns for leveraging OfficePrinterEditViewModel in an ASP.NET MVC application.

5.1 Controller Example

using IrbyImaging.Models;
using Microsoft.AspNetCore.Mvc;
using System;

public class OfficePrinterController : Controller
{
    // GET: /OfficePrinter/Edit/{id}
    public IActionResult Edit(Guid id)
    {
        // 1. Retrieve domain entity from database
        var entity = _printerService.GetById(id);
        if (entity == null) return NotFound();

        // 2. Map to ViewModel
        var vm = new OfficePrinterEditViewModel
        {
            Id = entity.Id,
            Company = entity.Company,
            ContractEndDate = entity.ContractEndDate
        };

        return View(vm);
    }

    // POST: /OfficePrinter/Edit
    [HttpPost]
    public IActionResult Edit(OfficePrinterEditViewModel vm)
    {
        if (!ModelState.IsValid)
            return View(vm);

        // 3. Map back to domain model
        var updateEntity = new OfficePrinter
        {
            Id = vm.Id,
            Company = vm.Company,
            ContractEndDate = vm.ContractEndDate
        };

        _printerService.Update(updateEntity);
        return RedirectToAction("Index");
    }
}

5.2 Razor View Example

@model IrbyImaging.Models.OfficePrinterEditViewModel

<h2>Edit Office Printer πŸ–¨οΈ</h2>
<form asp-action="Edit" method="post">
    @Html.HiddenFor(m => m.Id)
    <div class="form-group">
        @Html.LabelFor(m => m.Company)
        @Html.TextBoxFor(m => m.Company, new { @class = "form-control" })
        @Html.ValidationMessageFor(m => m.Company)
    </div>
    <div class="form-group">
        @Html.LabelFor(m => m.ContractEndDate)
        @Html.EditorFor(m => m.ContractEndDate, new { htmlAttributes = new { @class = "form-control" } })
        @Html.ValidationMessageFor(m => m.ContractEndDate)
    </div>
    <button type="submit" class="btn btn-primary">Save</button>
</form>

5.3 Mapping to Domain Model

Using AutoMapper (optional):

CreateMap<OfficePrinter, OfficePrinterEditViewModel>().ReverseMap();

  • EditViewModel (Base)
    Defines common edit properties: Id, CreatedOn, ModifiedOn, etc.
  • OfficePrinterViewModel (Read-Only)
    Might contain additional computed fields used for listing printers.

❗ Error Handling & Validation

  • Server-side validation is driven by Data Annotations:
    • Missing Company or ContractEndDate will trigger ModelState errors.
  • Client-side validation (unobtrusive) automatically reads the same annotations to prevent round-trips.

πŸ”š Conclusion

OfficePrinterEditViewModel is a lightweight, annotation-driven class designed to streamline the edit experience for office printer records in the IrbyImaging UI. By inheriting from a shared EditViewModel, it enforces consistency across forms, leverages built‑in ASP.NET validation, and cleanly separates UI concerns from domain logic.

Use this ViewModel to:

  • Render edit forms with proper labels
  • Validate user input at both client/server layers
  • Map easily to and from your domain or data-layer entities

Happy coding! ✨