πŸ“‘ OfficePrinterDetailViewModel Documentation


πŸš€ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Class Diagram (UML)
  4. Key Functional Areas
  5. Properties (Data Model)
  6. Data Annotations & Validation
  7. Sample Code Blocks & Usage Examples
  8. Integration in an ASP.NET MVC / Razor Page
  9. Error Handling & Edge Cases
  10. Conclusion

1. Overview & Purpose

OfficePrinterDetailViewModel is a View Model class in the IrbyImaging.Models namespace designed to carry detailed information about an office printer from the server side to the UI (e.g., an ASP.NET MVC view or Razor component). It extends the abstract DetailViewModel base, inheriting common detail properties (e.g., Id, Name, Description) while adding printer‑specific details.

  • 🏒 Company: Which company owns or leases the printer.
  • πŸ“… ContractEndDate: When the service/lease contract for the printer expires.

This model is typically used in β€œDetails” pages where users need read‐only views of printer information.


2. Dependencies & Technologies

Technology / Package Purpose
.NET / C# Language & runtime for class definition.
System.ComponentModel.DataAnnotations Data annotation attributes for display/formatting.

3. Class Diagram (UML)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚            DetailViewModel              β”‚  <<abstract>>
│──────────────────────────────────────────│
β”‚ + Guid Id                               β”‚
β”‚ + string Name                           β”‚
β”‚ + string Description                    β”‚
│──────────────────────────────────────────│
β”‚ // other shared detail properties       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β–²
                  β”‚ inherits
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      OfficePrinterDetailViewModel       β”‚
│──────────────────────────────────────────│
β”‚ + string Company                        β”‚
β”‚ + DateTimeOffset ContractEndDate        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

4. Key Functional Areas

  1. Inheritance
    • Extends DetailViewModel for consistency across detail pages.
  2. Property Definitions
    • Company
    • ContractEndDate
  3. UI Metadata via Attributes
    • Display and DataType annotations to control how fields render in views.

5. Properties (Data Model)

Property Type Description
Company string Company that owns or contracts the printer.
ContractEndDate DateTimeOffset Lease/service contract expiration date.

Inherited from DetailViewModel:

  • Id (e.g., Guid)
  • Name (string)
  • Description (string)
    (Actual base class properties may vary.)

6. Data Annotations & Validation

[Display(Name = "Contract End Date")]
[DataType(DataType.Date)]
public DateTimeOffset ContractEndDate { get; set; }
  • [Display]
    • Friendly label in UI: Contract End Date instead of ContractEndDate.
  • [DataType(DataType.Date)]
    • Renders as a date picker / formats only the date portion.

No [Required], [StringLength], or custom validators exist hereβ€”fields are assumed mandatory if not null.


7. Sample Code Blocks & Usage Examples

7.1 Instantiation in Controller

public IActionResult Details(Guid id)
{
    // Hypothetical service to fetch entity
    var printerEntity = _printerService.GetPrinterById(id);
    if (printerEntity == null) return NotFound();

    var viewModel = new OfficePrinterDetailViewModel
    {
        Id = printerEntity.Id,
        Name = printerEntity.Name,
        Description = printerEntity.Description,
        Company = printerEntity.CompanyName,
        ContractEndDate = printerEntity.ContractEndDate
    };

    return View(viewModel);
}

7.2 Razor View Binding

@model IrbyImaging.Models.OfficePrinterDetailViewModel

<h2>Printer Details</h2>
<div>
  <strong>@Model.Name</strong> (<em>@Model.Company</em>)
</div>
<dl class="row">
  <dt class="col-sm-2">Description</dt>
  <dd class="col-sm-10">@Model.Description</dd>

  <dt class="col-sm-2">@Html.DisplayNameFor(m => m.ContractEndDate)</dt>
  <dd class="col-sm-10">@Model.ContractEndDate.ToString("yyyy-MM-dd")</dd>
</dl>

8. Integration in an ASP.NET MVC / Razor Page

  1. Controller Action
    • Populate OfficePrinterDetailViewModel in Details or Edit actions.
  2. View (cshtml / razor)
    • Use @model OfficePrinterDetailViewModel.
    • Leverage Html.DisplayFor / Html.EditorFor for form generation.
  3. Form Templates
    • Data annotations automatically steer label text and input types.

9. Error Handling & Edge Cases

  • Null Entities
    • Controller should return NotFound() if the underlying printer record is missing.
  • Invalid Dates
    • ContractEndDate is DateTimeOffset, so ensure UTC/local correctness.
  • Empty Strings
    • If Company is missing or blank, you may want to decorate with [Required] or handle in view logic.

10. Conclusion

The OfficePrinterDetailViewModel is a focused View Model for delivering printer‑specific detailsβ€”Company and Contract End Dateβ€”to your UI, while inheriting general detail properties from a shared base. By leveraging Data Annotations, it ensures consistent display and formatting across your ASP.NET MVC or Razor Pages.

πŸš€ Next Steps:

  • If you need validation (e.g., ensure ContractEndDate > Today()), augment with custom validation attributes.
  • Consider adding localization to the [Display] attributes for multi‐language support.
  • Extend the model to include service-level metrics (e.g., LastServicedOn) as needed.

Generated on 2023‑XX‑XX by IrbyImaging.UI πŸ–¨οΈβœ¨