π 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
- Overview & Purpose
- Dependencies & Technologies
- View Model Details
- 3.1 Properties
- Key Functional Areas
- Error Handling & Return Types
- API Endpoints & Integrations
- Sample Code Blocks & Usage Examples
- UML Class Diagram
- 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
- Result Aggregation
- Holds summary counts (
SuccessfulCount,FailedCount).
- Holds summary counts (
- Error Messaging
- Provides
Problemsfor detailed diagnostics in the UI.
- Provides
- 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
Problemsbased 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!