πŸ“„ UploadResultsViewModel Documentation

File: IrbyImaging/Models/Upload/UploadResultsViewModel.cs
Assembly: IrbyImaging.UI
Author: kvamshi
Created: 03‑31‑2022
Last Modified: 03‑31‑2022


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model Details
  4. Key Functional Areas
  5. Error Handling & Return Types
  6. API Endpoints & Integrations
  7. Sample Code Blocks & Usage Examples
  8. UML Class Diagram
  9. Conclusion

πŸ“ 1. Overview & Purpose

The UploadResultsViewModel is a simple View Model used within the IrbyImaging UI layer to convey the outcome of a file or data upload operation back to the view. It encapsulates:

  • βœ… The count of successfully uploaded items
  • ❌ The count of failed items
  • ⚠️ A list of problem messages for failed uploads

This model is typically passed from a controller to a Razor view or returned by a Web API endpoint in JSON format to provide the client with structured feedback on an upload attempt.


πŸ”— 2. Dependencies & Technologies

Component / Package Version / Notes
.NET / .NET Core 5.0+ / Standard C# class library
Collection Types System.Collections.Generic.IList<T>

No third‑party dependencies. This is a plain C# POCO (Plain Old CLR Object) class.


πŸ“‚ 3. View Model Details

3.1 Properties

Property Name Type Description
SuccessfulCount string The number (as text) of items uploaded successfully.
FailedCount string The number (as text) of items that failed to upload.
Problems IList<string> A list of descriptive error messages for each failure case.
public class UploadResultsViewModel
{
    /// <summary>
    /// Gets or sets the successful count.
    /// </summary>
    public string SuccessfulCount { get; set; }

    /// <summary>
    /// Gets or sets the failed count.
    /// </summary>
    public string FailedCount { get; set; }

    /// <summary>
    /// Gets or sets the problems.
    /// </summary>
    public IList<string> Problems { get; set; }
}

⭐ 4. Key Functional Areas

  1. Result Aggregation
    • Holds summary counts (SuccessfulCount, FailedCount).
  2. Error Messaging
    • Provides Problems for detailed diagnostics in the UI.
  3. Data Transport
    • Acts as a Data Transfer Object (DTO) between server logic and presentation layer.

🚨 5. Error Handling & Return Types

  • Error Handling

    • This class does not implement validation or error handling logic. It is purely a container.
    • The calling logic (e.g., a service or controller) must populate Problems based on exceptions or validation failures.
  • Return Types

    • In Web APIs, this model is serialized to JSON:

      {
        "successfulCount": "5",
        "failedCount": "2",
        "problems": [
          "Image format not supported.",
          "Timeout while uploading file #7."
        ]
      }
      

πŸ”Œ 6. API Endpoints & Integrations

This file does not define API endpoints itself, but it is often used in conjunction with:

  • ASP.NET Core MVC Controllers
    [HttpPost("upload-files")]
    public IActionResult UploadFiles(IFormFile[] files)
    {
        var result = _uploadService.ProcessFiles(files);
        var vm = new UploadResultsViewModel
        {
            SuccessfulCount = result.SuccessCount.ToString(),
            FailedCount     = result.FailureCount.ToString(),
            Problems        = result.ErrorMessages
        };
        return Json(vm);
    }
    
  • Third‑Party Upload Services (e.g., cloud storage SDKs) feed into the service layer that ultimately populates this ViewModel.

πŸ’» 7. Sample Code Blocks & Usage Examples

Example: Populating in a Controller

public class ImagingController : Controller
{
    private readonly IUploadService _uploadService;

    public ImagingController(IUploadService uploadService)
    {
        _uploadService = uploadService;
    }

    [HttpPost]
    public IActionResult Upload(IFormFileCollection files)
    {
        var uploadResult = _uploadService.UploadImages(files);
        var viewModel = new UploadResultsViewModel
        {
            SuccessfulCount = uploadResult.SuccessCount.ToString(),
            FailedCount     = uploadResult.FailedCount.ToString(),
            Problems        = uploadResult.FailureDetails
        };

        return View("UploadSummary", viewModel);
    }
}

Example: Consuming in a Razor View

@model IrbyImaging.Models.UploadResultsViewModel

<h2>Upload Summary</h2>
<p>βœ… Successful: @Model.SuccessfulCount</p>
<p>❌ Failed:     @Model.FailedCount</p>

@if (Model.Problems?.Any() ?? false)
{
    <h3>Problems:</h3>
    <ul>
        @foreach (var problem in Model.Problems)
        {
            <li>@problem</li>
        }
    </ul>
}

πŸ“Š 8. UML Class Diagram

classDiagram
    class UploadResultsViewModel {
        <<ViewModel>>
        +string SuccessfulCount
        +string FailedCount
        +IList<string> Problems
    }

🏁 9. Conclusion

The UploadResultsViewModel is a lightweight, focused container for summarizing upload operations in the IrbyImaging application. By delivering clear counts and detailed problem messages, it supports both rich UI feedback and straightforward API responses.

  • Simple to instantiate and use
  • Flexible for any upload-related operations
  • Immutable in definitionβ€”no methods, purely data-backed

πŸŽ‰ Now you have everything you need to integrate upload result reporting into your controllers and views!