📱 MobileDeviceCreateViewModel.cs Documentation
Welcome to the comprehensive documentation for IrbyImaging/Models/MobileDevice/MobileDeviceCreateViewModel.cs. This document covers every aspect of the file—from its purpose and structure to usage examples and a UML class diagram. Strap in! 🚀
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- View Model Structure
4.1. Inheritance
4.2. Properties
4.3. Data Annotations & Validation - Usage Examples
- UML Class Diagram
- Error Handling & Return Types
- API Endpoints Overview
- Third‑party Integrations
- Conclusion
1. Overview & Purpose
MobileDeviceCreateViewModel is a specialized view model in the IrbyImaging UI layer, designed to capture and validate all necessary data when creating a new mobile device record in the system.
- 📌 Namespace:
IrbyImaging.Models - 🛠Assembly:
IrbyImaging.UI - 👤 Author: kvamshi
- 🗓 Created: 03-31-2022
Primary Goals
- Provide a strongly‑typed model for MVC forms.
- Enforce data validation via Data Annotations.
- Facilitate clean separation between UI and business logic.
2. Dependencies & Technologies
| Technology / Library | Purpose |
|---|---|
| .NET Core / .NET Framework | Runtime |
| System.ComponentModel.DataAnnotations | Validation attributes ([Required], [Display], etc.) |
| IrbyImaging.Utility | Contains shared enums (DeviceType, Carrier, etc.) |
| C# (7.0+) | Language features (auto‑properties, etc.) |
3. Key Functional Areas
-
Data Capture
- Captures all fields required for registering a mobile device: type, carrier, phone number, IMEI, SIM, flags for Telogis & IT review.
-
Validation
- Uses Data Annotations to enforce:
- Required fields
- Format (e.g., 10‑digit phone number)
- Human‑readable display names
- Uses Data Annotations to enforce:
-
Integration Point
- Designed to bind to MVC/Razor views and post back to MobileDeviceController (or equivalent API) for processing.
4. View Model Structure
namespace IrbyImaging.Models
{
/// <summary>
/// ViewModel for creating a new mobile device record.
/// Inherits from CreateViewModel (base class for create operations).
/// </summary>
public class MobileDeviceCreateViewModel : CreateViewModel
{
[Display(Name = "Device Type")]
public DeviceType Type { get; set; }
[Display(Name = "Service Provider")]
public Carrier Carrier { get; set; }
[Display(Name = "Phone Number")]
[DataType(DataType.PhoneNumber)]
[RegularExpression(@"^([0-9]{10})$", ErrorMessage = "Invalid Phone Number. Enter the digits only. Ex: 6017094729")]
public string PhoneNumber { get; set; }
[Display(Name = "IMEI")]
[Required]
public string Imei { get; set; }
[Display(Name = "SIM")]
public string Sim { get; set; }
[Display(Name = "Telogis Device?")]
public bool IsTelogis { get; set; }
[Display(Name = "Needs IT Review?")]
public bool NeedsReview { get; set; }
}
}
4.1. Inheritance
- Base Class:
CreateViewModel- Likely provides common properties (e.g.,
CreatedBy,CreatedOn) and methods for all CREATE operations across the app.
- Likely provides common properties (e.g.,
4.2. Properties
| Property | Type | Display Name | Validation | Description |
|---|---|---|---|---|
| Type | DeviceType |
Device Type | — | Enum representing device categories (e.g., Phone, Tablet). |
| Carrier | Carrier |
Service Provider | — | Enum for network carriers (e.g., AT&T, Verizon). |
| PhoneNumber | string |
Phone Number | 10‑digit regex | User’s phone number (digits only). |
| Imei | string |
IMEI | [Required] |
International Mobile Equipment Identity. |
| Sim | string |
SIM | — | SIM card identifier (optional). |
| IsTelogis | bool |
Telogis Device? | — | Flag if device uses Telogis integration. |
| NeedsReview | bool |
Needs IT Review? | — | Flag if IT department must review before activation. |
4.3. Data Annotations & Validation
-
[Display(Name = "...")]
Provides human‑readable labels in views and validation messages. -
[DataType(DataType.PhoneNumber)]
Instructs the UI to render appropriate input type (e.g.,<input type="tel">). -
[RegularExpression(@"^([0-9]{10})$"...)]
Ensures phone numbers are exactly 10 digits—no hyphens or spaces. -
[Required]
Marks IMEI as mandatory.
5. Usage Examples
5.1. Controller Action (MVC)
[HttpGet]
public IActionResult Create()
{
var model = new MobileDeviceCreateViewModel();
return View(model);
}
[HttpPost]
public IActionResult Create(MobileDeviceCreateViewModel model)
{
if (!ModelState.IsValid)
return View(model);
// Map to domain entity, save to database...
_mobileDeviceService.Create(new MobileDevice
{
Type = model.Type,
Carrier = model.Carrier,
PhoneNumber = model.PhoneNumber,
Imei = model.Imei,
Sim = model.Sim,
IsTelogis = model.IsTelogis,
NeedsReview = model.NeedsReview
});
return RedirectToAction("Index");
}
5.2. Razor View Snippet (Create.cshtml)
@model IrbyImaging.Models.MobileDeviceCreateViewModel
<form asp-action="Create">
<div class="form-group">
<label asp-for="Type"></label>
<select asp-for="Type" class="form-control" asp-items="Html.GetEnumSelectList<DeviceType>()"></select>
<span asp-validation-for="Type" class="text-danger"></span>
</div>
<!-- Repeat for Carrier, PhoneNumber, Imei, Sim -->
<div class="form-group form-check">
<input asp-for="IsTelogis" class="form-check-input" />
<label asp-for="IsTelogis" class="form-check-label"></label>
</div>
<div class="form-group form-check">
<input asp-for="NeedsReview" class="form-check-input" />
<label asp-for="NeedsReview" class="form-check-label"></label>
</div>
<button type="submit" class="btn btn-primary">Create Device</button>
</form>
6. UML Class Diagram
@startuml
package IrbyImaging.Models {
class CreateViewModel {
<<abstract>>
// Common create props...
}
class MobileDeviceCreateViewModel {
+DeviceType Type
+Carrier Carrier
+string PhoneNumber
+string Imei
+string Sim
+bool IsTelogis
+bool NeedsReview
}
MobileDeviceCreateViewModel --|> CreateViewModel
}
@enduml
7. Error Handling & Return Types
- Client‑side & Server‑side Validation
- Invalid inputs (e.g., non‑digit phone number) surface via
ModelStateerrors.
- Invalid inputs (e.g., non‑digit phone number) surface via
- Return Values
IActionResultthat returns the same view on error, or a redirect upon success.
8. API Endpoints Overview
Note: This view model is typically used in MVC pages. If exposing via Web API, similar DTOs would be employed:
POST /api/mobiledevices
Content-Type: application/json
{
"type": "Smartphone",
"carrier": "Verizon",
"phoneNumber": "6017094729",
"imei": "356938035643809",
"sim": "89014103211118510720",
"isTelogis": false,
"needsReview": true
}
9. Third‑party Integrations
- Telogis (Verizon Connect)
IsTelogisflag toggles Telogis‑specific workflows elsewhere in the application (e.g., location tracking services).
🔚 Conclusion
The MobileDeviceCreateViewModel is your go‑to DTO for registering new mobile devices within the IrbyImaging ecosystem. It neatly packages all device details, enforces validation rules at the UI boundary, and integrates seamlessly with MVC controllers or Web APIs. By leveraging built‑in .NET Data Annotations and a clear class design, it ensures data integrity and a smooth developer experience.
Happy coding! 🎉
End of documentation for MobileDeviceCreateViewModel.cs