📱 MobileDeviceEditViewModel Documentation


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Class Definition & Inheritance
  4. UML Class Diagram
  5. Key Properties & Validation Rules
  6. How It Works
  7. Sample Usage
  8. Integration Points & Third‑party
  9. Error Handling & Return Types
  10. Conclusion

1. 📖 Overview & Purpose

The MobileDeviceEditViewModel is a ViewModel in the IrbyImaging.UI application that encapsulates all the data required to edit a mobile device record. It inherits from a base EditViewModel and adds mobile‑device‑specific fields such as phone number, IMEI, SIM, carrier, and device type.

  • Intended Use:
    • Bind to Razor/MVC views for Create/Edit forms
    • Carry user inputs from the UI to the server
    • Leverage DataAnnotations for validation

2. 🔧 Dependencies & Technologies

Technology/Library Purpose
.NET / C# Language & runtime
System.ComponentModel.DataAnnotations Data validation, display metadata
IrbyImaging.Utility Defines DeviceType & Carrier enums/types

3. 🏷️ Class Definition & Inheritance

using IrbyImaging.Utility;
using System.ComponentModel.DataAnnotations;

namespace IrbyImaging.Models
{
    /// <summary>
    /// ViewModel for editing a mobile device.
    /// Inherits from EditViewModel to include common edit properties.
    /// </summary>
    public class MobileDeviceEditViewModel : EditViewModel
    {
        [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; }
    }
}
  • Namespace: IrbyImaging.Models
  • Base Class: EditViewModel (assumed to contain shared edit properties like Id, Name, etc.)

4. 🖼️ UML Class Diagram

classDiagram
    EditViewModel <|-- MobileDeviceEditViewModel
    class EditViewModel {
        <<abstract>>
        +int Id
        +DateTime CreatedDate
        +DateTime? ModifiedDate
        +string CreatedBy
        +string ModifiedBy
    }
    class MobileDeviceEditViewModel {
        +DeviceType Type
        +Carrier Carrier
        +string PhoneNumber
        +string Imei
        +string Sim
        +bool IsTelogis
        +bool NeedsReview
    }

5. 🔑 Key Properties & Validation Rules

Property Type Display Name Validation/Notes
Type DeviceType Device Type Enumeration of device categories (e.g., Phone, Tablet).
Carrier Carrier Service Provider Enum for mobile carriers (e.g., Verizon, AT&T).
PhoneNumber string Phone Number Must be exactly 10 digits. Uses [RegularExpression(@"^([0-9]{10})$")].
Imei string IMEI Required. International Mobile Equipment Identity.
Sim string SIM Optional SIM serial.
IsTelogis bool Telogis Device? Indicates if the device uses Telogis tracking.
NeedsReview bool Needs IT Review? Flag for IT staff to review this device entry.

6. ⚙️ How It Works

  1. Form Rendering

    • A controller action populates an instance of MobileDeviceEditViewModel.
    • The Razor view uses asp-for helpers to render inputs and labels based on Display(Name = "...").
  2. Model Binding & Validation

    • On POST, ASP.NET Core binds form fields back to the ViewModel.
    • DataAnnotations attributes automatically trigger validation:
      • Required fields
      • Regex phone‑number check
  3. Service Layer Integration

    • If ModelState.IsValid, your controller maps the ViewModel to a domain/entity object.
    • Calls repository/service to create or update the mobile device record.

7. 📝 Sample Usage

Controller Snippet

public class MobileDeviceController : Controller
{
    // GET: /MobileDevice/Edit/5
    public IActionResult Edit(int id)
    {
        var device = _deviceService.GetById(id);
        var vm = new MobileDeviceEditViewModel
        {
            Id = device.Id,
            Type = device.Type,
            Carrier = device.Carrier,
            PhoneNumber = device.PhoneNumber,
            Imei = device.Imei,
            Sim = device.Sim,
            IsTelogis = device.IsTelogis,
            NeedsReview = device.NeedsReview
        };
        return View(vm);
    }

    // POST: /MobileDevice/Edit
    [HttpPost]
    public IActionResult Edit(MobileDeviceEditViewModel model)
    {
        if (!ModelState.IsValid)
            return View(model);

        var updated = new MobileDevice
        {
            Id           = model.Id,
            Type         = model.Type,
            Carrier      = model.Carrier,
            PhoneNumber  = model.PhoneNumber,
            Imei         = model.Imei,
            Sim          = model.Sim,
            IsTelogis    = model.IsTelogis,
            NeedsReview  = model.NeedsReview
        };
        _deviceService.Update(updated);
        return RedirectToAction("Index");
    }
}

Razor View Snippet

@model IrbyImaging.Models.MobileDeviceEditViewModel

<form asp-action="Edit" method="post">
    <div class="form-group">
        <label asp-for="Imei"></label>
        <input asp-for="Imei" class="form-control" />
        <span asp-validation-for="Imei" class="text-danger"></span>
    </div>

    <div class="form-group">
        <label asp-for="PhoneNumber"></label>
        <input asp-for="PhoneNumber" class="form-control" />
        <span asp-validation-for="PhoneNumber" class="text-danger"></span>
    </div>

    <!-- Additional fields for Type, Carrier, Sim, IsTelogis, NeedsReview -->

    <button type="submit" class="btn btn-primary">Save</button>
</form>

8. 🤝 Integration Points & Third‑party

  • IrbyImaging.Utility
    • Houses the DeviceType and Carrier definitions.
  • ASP.NET Core MVC
    • Model binding & DataAnnotations validation pipelines.
  • No external 3rd-party libraries are directly referenced within this ViewModel.

9. 🛠️ Error Handling & Return Types

  • Validation Errors
    • Managed via ModelState.
    • Custom error message on invalid phone number:
      Invalid Phone Number. Enter the digits only. Ex: 6017094729
      
  • Controller Returns
    • GET returns View(viewModel)
    • POST returns:
      • View(model) if invalid
      • RedirectToAction(...) on success

10. 🎯 Conclusion

The MobileDeviceEditViewModel is a focused, reusable model tailored for editing mobile device records in the IrbyImaging UI.

  • ✔️ Strongly‑typed form fields
  • ✔️ Built‑in validation via DataAnnotations
  • ✔️ Clear separation of concerns (ViewModel vs. Domain Model)

Leverage this ViewModel to ensure a consistent, validated experience whenever your users create or modify mobile device details! 🚀


Documentation generated on 2022-03-31 by the IrbyImaging.UI team.