📄 TicketUpdateViewModel Documentation


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Class Structure & Key Functional Areas
  4. Property Reference
  5. Usage Examples & Code Snippets
  6. UML Class Diagram
  7. Error Handling & Validation
  8. Third-Party Integrations
  9. Conclusion

🔍 Overview & Purpose

The TicketUpdateViewModel is part of the IrbyImaging.UI assembly and serves as a data carrier between the user interface (UI) and the server-side logic. It encapsulates all the fields needed for updating a support ticket, including metadata, attachments, request types, and user notifications.

Key goals:

  • Provide a strongly typed contract for update requests.
  • Support file uploads (IFormFile) and raw image bytes.
  • Maintain audit history with old/new JSON snapshots.
  • Enable fine-grained control over notifications and review scheduling.

⚙️ Dependencies & Technologies

Technology / Library Purpose
.NET 6 / .NET Core Framework for ASP.NET Core applications
Microsoft.AspNetCore.Http Handles file uploads via IFormFile
System.ComponentModel.DataAnnotations Enables display names and validation attributes
IrbyImaging.Utility Defines helper enums like TicketStatus

🏗 Class Structure & Key Functional Areas

namespace IrbyImaging.ViewModels
{
    public class TicketUpdateViewModel
    {
        // Ticket identity
        public Guid TicketId { get; set; }
        public int TicketNumber { get; set; }

        // Attachments & File handling
        public byte[] ImageContents { get; set; }
        public IFormFile File { get; set; }

        // Customer & Contact details
        public string Customer { get; set; }
        [Display(Name = "Callback Number")]
        public string CallbackNumber { get; set; }
        [Display(Name = "Response Email")]
        public string Email { get; set; }

        // Descriptions
        [Display(Name = "Ticket Description")]
        public string TicketDescription { get; set; }
        [Required]
        [Display(Name = "(Public) Description of Update")]
        public string Description { get; set; }

        // Categories of requests
        [Display(Name = "Hardware Request")]
        public ICollection<RequestOptionForUpdateViewModel> HardwareRequests { get; set; }
        [Display(Name = "Software Request")]
        public ICollection<RequestOptionForUpdateViewModel> SoftwareRequests { get; set; }
        [Display(Name = "Enterprise Request")]
        public ICollection<RequestOptionForUpdateViewModel> EnterpriseRequests { get; set; }
        [Display(Name = "Shared Access Request")]
        public ICollection<RequestOptionForUpdateViewModel> AccessRequests { get; set; }
        [Display(Name = "Irby Systems Request")]
        public ICollection<RequestOptionForUpdateViewModel> SystemRequests { get; set; }

        // Additional details
        [Display(Name = "Job Description")]
        public string JobDetails { get; set; }
        [Display(Name = "Shipping Address")]
        public string ShippingAddress { get; set; }
        [Display(Name = "Employee Number")]
        public string EmployeNumber { get; set; }

        // Audit & state
        public string OldJson { get; set; }
        public string NewJson { get; set; }
        public string Type { get; set; }
        public TicketStatus Status { get; set; }

        // Notifications & Review
        [Display(Name = "Notify the user of this update?")]
        public bool ShouldNotifyUser { get; set; }
        public bool ReviewAfter { get; set; }
        public DateTime? ReviewAfterDate { get; set; }
        public string ReviewReason { get; set; }
    }
}

📋 Property Reference

Below is a detailed table of each property, its type, annotation, and purpose:

Property Type Attributes / Display Name Description
TicketId Guid — Unique identifier for the ticket.
TicketNumber int — Human-readable ticket number.
ImageContents byte[] — Raw binary data of an attached image.
File IFormFile — Uploaded file stream (e.g., screenshot).
Customer string — Name or ID of the customer.
CallbackNumber string “Callback Number” Phone number for follow-up.
Email string “Response Email” Email address for responses.
TicketDescription string “Ticket Description” Original description of the ticket.
Description string “(Public) Description of Update”[Required] Detailed description of this update.
HardwareRequests ICollection<RequestOptionForUpdateViewModel> “Hardware Request” List of hardware change options selected.
SoftwareRequests ICollection<RequestOptionForUpdateViewModel> “Software Request” List of software change options selected.
EnterpriseRequests ICollection<RequestOptionForUpdateViewModel> “Enterprise Request” List of enterprise-level requests (e.g., network).
AccessRequests ICollection<RequestOptionForUpdateViewModel> “Shared Access Request” Requests for shared folder or system access.
SystemRequests ICollection<RequestOptionForUpdateViewModel> “Irby Systems Request” Requests specific to Irby internal systems.
JobDetails string “Job Description” Details of the job or task associated with the update.
ShippingAddress string “Shipping Address” Address for any hardware shipping.
EmployeNumber string “Employee Number” Employee ID number initiating or requiring update.
OldJson string — Serialized snapshot of the ticket before update.
NewJson string — Serialized snapshot of the ticket after update.
Type string — Type or category of the update (e.g., “FollowUp”, “Escalation”).
Status TicketStatus — Current status after the update (enum from IrbyImaging.Utility).
ShouldNotifyUser bool “Notify the user of this update?” Flag to send notification to the user.
ReviewAfter bool — Indicates if a follow-up review is required.
ReviewAfterDate DateTime? — Optional date when review should occur.
ReviewReason string — Reason for scheduling a follow-up review.

📂 Usage Examples & Code Snippets

1. Creating an Update Request in a Controller

[HttpPost]
public async Task<IActionResult> UpdateTicket(TicketUpdateViewModel vm)
{
    if(!ModelState.IsValid)
        return BadRequest(ModelState);

    // Map ViewModel to domain model or DTO
    var updateDto = _mapper.Map<TicketUpdateDto>(vm);
    await _ticketService.UpdateAsync(updateDto);

    if(vm.ShouldNotifyUser)
        await _notificationService.SendUpdateEmailAsync(vm.Email, vm.TicketNumber);

    return Ok(new { Success = true, TicketId = vm.TicketId });
}

2. Rendering in a Razor View

<form asp-action="UpdateTicket" enctype="multipart/form-data" method="post">
    <input type="hidden" asp-for="TicketId" />
    <div class="form-group">
        <label asp-for="Description"></label>
        <textarea asp-for="Description" class="form-control"></textarea>
        <span asp-validation-for="Description" class="text-danger"></span>
    </div>
    <div class="form-group">
        <label asp-for="File">Upload Screenshot</label>
        <input asp-for="File" type="file" class="form-control" />
    </div>
    <!-- Additional fields... -->
    <button type="submit" class="btn btn-primary">Update Ticket</button>
</form>

📊 UML Class Diagram

classDiagram
    class TicketUpdateViewModel {
        +Guid TicketId
        +int TicketNumber
        +byte[] ImageContents
        +IFormFile File
        +string Customer
        +string CallbackNumber
        +string Email
        +string TicketDescription
        +string Description
        +ICollection<RequestOptionForUpdateViewModel> HardwareRequests
        +ICollection<RequestOptionForUpdateViewModel> SoftwareRequests
        +ICollection<RequestOptionForUpdateViewModel> EnterpriseRequests
        +ICollection<RequestOptionForUpdateViewModel> AccessRequests
        +ICollection<RequestOptionForUpdateViewModel> SystemRequests
        +string JobDetails
        +string ShippingAddress
        +string EmployeNumber
        +string OldJson
        +string NewJson
        +string Type
        +TicketStatus Status
        +bool ShouldNotifyUser
        +bool ReviewAfter
        +DateTime? ReviewAfterDate
        +string ReviewReason
    }

🚫 Error Handling & Validation

  • Data Annotations ensure that the Description property is mandatory.
  • Additional validations (e.g., file size/type checks) can be enforced in the controller or via a custom model binder.
  • ModelState is used to aggregate and report validation errors back to the UI.

🔌 Third-Party Integrations

  • IFormFile (from ASP.NET Core HTTP abstractions) enables seamless file uploads.
  • TicketStatus enum is provided by IrbyImaging.Utility, ensuring consistent status codes across the application.
  • No direct external APIs are consumed within this ViewModel.

🏁 Conclusion

The TicketUpdateViewModel is a comprehensive and extensible model designed to simplify ticket update workflows in the IrbyImaging UI. By bundling all relevant data—attachments, metadata, request categories, notifications, and audit snapshots—into a single object, developers can build robust, maintainable controllers and front-end forms that handle complex update scenarios with ease.

Feel free to extend or customize the model by:

  • Adding additional data annotations for server-side validation.
  • Integrating with automapper for DTO transformations.
  • Implementing custom validation attributes for file size/type or date constraints.

Happy coding! 🚀