πŸ–¨οΈ PrinterCreateViewModel Documentation


πŸ“‹ Table of Contents

  1. Introduction
  2. Overview & Purpose
  3. Namespace & Assembly Info
  4. Class Definition
  5. Inheritance & Relationships (UML)
  6. Key Functional Areas
  7. Dependencies & Technologies
  8. Usage & Code Examples
  9. Error Handling & Return Types
  10. Related ViewModels & Data Models
  11. Conclusion

1. Introduction

Welcome to the detailed documentation for PrinterCreateViewModel.cs, part of the IrbyImaging.UI assembly. This file defines a ViewModel used in the creation screen (Create view) for a Printer entity in an ASP.NET MVC application.


2. Overview & Purpose

PrinterCreateViewModel is a marker ViewModel class that:

  • Extends a common base class CreateViewModel.
  • Serves as a strongly-typed model for the Create Printer view.
  • Enables separation of concerns between domain models and UI-specific models.
  • Can be extended in the future to include printer-specific properties (e.g., Model, Manufacturer, Location).

3. Namespace & Assembly Info

Attribute Detail
Assembly IrbyImaging.UI
Namespace IrbyImaging.Models
File Path IrbyImaging/Models/Printer/PrinterCreateViewModel.cs
Author kvamshi
Created On 03-31-2022
Last Modified 03-31-2022
// ***********************************************************************
// Assembly         : IrbyImaging.UI
// Author           : kvamshi
// Created          : 03-31-2022
//
// Last Modified By : kvamshi
// Last Modified On : 03-31-2022
// ***********************************************************************
// <copyright file="PrinterCreateViewModel.cs" company="IrbyImaging.UI">
// Copyright (c) . All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************

4. Class Definition

namespace IrbyImaging.Models
{
    /// <summary>
    /// Class PrinterCreateViewModel.
    /// Implements the <see cref="IrbyImaging.Models.CreateViewModel" />
    /// </summary>
    /// <seealso cref="IrbyImaging.Models.CreateViewModel" />
    public class PrinterCreateViewModel : CreateViewModel
    {
        // 🚧 No additional properties yet – reserved for future printer-specific fields.
    }
}
  • Class Name: PrinterCreateViewModel
  • Base Class: CreateViewModel
  • Modifiers: public
  • Responsibility: Data transfer between the Create Printer UI and the controller.

5. Inheritance & Relationships (UML)

+------------------------+        +----------------------+
|   CreateViewModel      |◀───────| PrinterCreateViewModel |
+------------------------+        +----------------------+
| - Id : Guid            |        | // inherits all props |
| - DisplayName : string |        |                      |
| - IsActive : bool      |        |                      |
+------------------------+        +----------------------+
       β–²
       β”‚
       β”‚ (Base for all Create VMs)
       β”‚
+------------------------+
| OtherCreateViewModel   |
+------------------------+
  • CreateViewModel is the common base for all β€œcreate” ViewModels.

6. Key Functional Areas

  • ViewModel Inheritance
    Leverages a shared base class to enforce consistency across β€œCreate” screens.

  • Type Safety
    Provides a strongly-typed model for binding in views and controllers.

  • Extensibility
    Placeholder for any printer-specific create-time properties (e.g., default settings).


7. Dependencies & Technologies

Technology Purpose
.NET / C# Programming language & runtime
ASP.NET MVC / Razor Pages UI framework
IrbyImaging.UI assembly Core UI layer
CreateViewModel (base) Shared ViewModel base class

8. Usage & Code Examples

8.1 Controller Integration

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

public class PrinterController : Controller
{
    // GET: /Printer/Create
    public IActionResult Create()
    {
        var vm = new PrinterCreateViewModel
        {
            // Base props are set in CreateViewModel constructor
        };
        return View(vm);
    }

    // POST: /Printer/Create
    [HttpPost]
    [ValidateAntiForgeryToken]
    public IActionResult Create(PrinterCreateViewModel model)
    {
        if (!ModelState.IsValid)
        {
            return View(model);
        }

        // Map ViewModel -> Domain Model
        var printer = new Printer
        {
            DisplayName = model.DisplayName,
            // ... other mappings ...
        };

        // Invoke service to save the printer
        _printerService.Create(printer);

        return RedirectToAction("Index");
    }
}

8.2 Razor View Example

@model IrbyImaging.Models.PrinterCreateViewModel
@{
    ViewData["Title"] = "Create Printer";
}

<h2>Create Printer πŸ–¨οΈ</h2>

<form asp-action="Create" method="post">
    <div class="form-group">
        <label asp-for="DisplayName"></label>
        <input asp-for="DisplayName" class="form-control" />
        <span asp-validation-for="DisplayName" class="text-danger"></span>
    </div>
    <!-- Future printer-specific fields go here -->
    <button type="submit" class="btn btn-primary">Create</button>
</form>

9. Error Handling & Return Types

  • ModelState Validation:
    Any missing or invalid fields (in CreateViewModel) will trigger ModelState.IsValid == false.

  • Return Types:

    • IActionResult from MVC actions
    • Renders the same PrinterCreateViewModel on validation errors

ViewModel Scenario
PrinterEditViewModel Editing an existing printer
PrinterDetailsViewModel Displaying printer details
CreateViewModel (base) Shared create-screen props
Domain Model Scenario
Printer Entity persisted in database

11. Conclusion

The PrinterCreateViewModel is a lightweight, extensible placeholder for your printer–creation UI in the IrbyImaging application. By inheriting from a shared CreateViewModel, it promotes consistency across all create screens, simplifies validation, and cleanly separates your UI layer from domain logic. πŸš€

Happy Coding! πŸŽ‰