📘 FieldOffice.cs Documentation


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Domain Model: FieldOffice
    1. Class-Level Annotations
    2. Core Properties
    3. Navigation Properties & Relationships
    4. NotMapped Helper Properties
  4. Relationships & Cardinality
  5. Sample Usage & Code Snippets
    1. Querying FieldOffice Entities
    2. Binding to an MVC Dropdown
    3. Populating NotMapped Counts
  6. UML Class Diagram
  7. Conclusion

🎯 Overview & Purpose

The FieldOffice class represents a field office entity in the Irby Imaging domain. In a typical construction or imaging services organization, each field office is a physical or regional hub with associated personnel, assets, and jobs. This model:

  • Maps to the irby.FieldOffice table in a relational database via Entity Framework Core.
  • Holds contact information, geolocation, and linkages to employees, assets, and jobs.
  • Provides helper properties for UI display (e.g., dropdown lists, counters).

🔗 Dependencies & Technologies

Technology / Package Purpose
Microsoft.EntityFrameworkCore ORM mapping ([Table], [Key], [NotMapped])
Microsoft.AspNetCore.Mvc.Rendering MVC helper (SelectListItem)
System.ComponentModel.DataAnnotations Data annotation attributes ([Display])
System.ComponentModel.DataAnnotations.Schema Schema mapping
  • .NET 6+ / .NET Core compatibility
  • Relies on domain classes: Employee, Asset, Job (assumed in the same assembly)

📂 Domain Model: FieldOffice

namespace IrbyImaging.DomainClasses
{
    [Table("FieldOffice", Schema = "irby")]
    public class FieldOffice
    {
        [Key]
        public Guid Id { get; set; }

        [Display(Name = "JDE Number")]
        public string JdeNumber { get; set; }

        public string Name { get; set; }
        public string BusinessUnitNumber { get; set; }
        public string BusinessUnitName { get; set; }

        // … (more properties and navigation collections)
    }
}

📋 3.1. Class-Level Annotations

Attribute Description
[Table("FieldOffice", Schema="irby")] Maps class to irby.FieldOffice table in DB.

🔑 3.2. Core Properties

Property Type Attributes Description
Id Guid [Key] Primary key identifier.
JdeNumber string [Display(Name="JDE Number")] External JDE system reference.
Name string Field office name.
BusinessUnitNumber string Business unit code.
BusinessUnitName string Business unit descriptive name.
MailingAddress string Mailing address.
ShippingAddress string Shipping address.
FaxNumber string Fax phone number.
OfficePhone string Main office phone.
OfficeExtension string Office phone extension.
Latitude decimal [NotMapped] Geolocation: latitude (for mapping UIs).
Longitude decimal [NotMapped] Geolocation: longitude (for mapping UIs).

🔄 3.3. Navigation Properties & Relationships

Property Type Description
ManagerId Guid? FK to the Manager.
Manager Employee Navigation to manager employee.
ProjectManagerId Guid? FK to the Project Manager.
ProjectManager Employee Navigation to project manager.
SuperintendentId Guid? FK to the Superintendent.
Superintendent Employee Navigation to superintendent.
AsstProjectManagerId Guid? FK to Assistant Project Manager.
AsstProjectManager Employee Navigation to assistant PM.
LeadId Guid? FK to Lead.
Lead Employee Navigation to lead.
DirectorId Guid? FK to Director.
Director Employee Navigation to director.
PrimaryContactId Guid? FK to Primary Contact.
PrimaryContact Employee Navigation to primary contact.
SecondaryContactId Guid? FK to Secondary Contact.
SecondaryContact Employee Navigation to secondary contact.
Assets ICollection<Asset> One-to-many: assets assigned to this office.
Jobs ICollection<Job> One-to-many: jobs associated with this office.

🛠️ 3.4. NotMapped Helper Properties

These properties are not persisted to the database. They provide UI-specific data, counts, or pre-populated lists:

Property Type Purpose
EmployeeData List<SelectListItem> Used to populate a dropdown of employees.
JobCount string Stores job count as a formatted string.
EmployeeCount string Stores employee count as a formatted string.
AssetCount string Stores asset count as a formatted string.
Latitude decimal Coordinates for mapping.
Longitude decimal Coordinates for mapping.

📊 Relationships & Cardinality

classDiagram
    FieldOffice o-- "0..*" Asset : Assets
    FieldOffice o-- "0..*" Job   : Jobs
    FieldOffice o-- Employee      : Manager
    FieldOffice o-- Employee      : ProjectManager
    FieldOffice o-- Employee      : Superintendent
    FieldOffice o-- Employee      : AsstProjectManager
    FieldOffice o-- Employee      : Lead
    FieldOffice o-- Employee      : Director
    FieldOffice o-- Employee      : PrimaryContact
    FieldOffice o-- Employee      : SecondaryContact
  • 1 FieldOffice can have 0.. Assets*
  • 1 FieldOffice can have 0.. Jobs*
  • Multiple optional one-to-one links to various Employee roles

🛠️ Sample Usage & Code Snippets

Below are common patterns illustrating how to work with the FieldOffice entity.

5.1. Querying FieldOffice Entities

using (var context = new IrbyDbContext())
{
    // Fetch all field offices with their assigned jobs & assets
    var offices = context.FieldOffices
                         .Include(f => f.Manager)
                         .Include(f => f.Assets)
                         .Include(f => f.Jobs)
                         .ToList();
}

5.2. Binding to an MVC Dropdown

public IActionResult Create()
{
    var offices = _context.FieldOffices
                          .Select(f => new SelectListItem {
                              Value = f.Id.ToString(),
                              Text = f.Name
                          }).ToList();
    ViewBag.FieldOfficeList = offices;
    return View();
}

In your Razor view:

@Html.DropDownList("FieldOfficeId", (IEnumerable<SelectListItem>)ViewBag.FieldOfficeList, 
                   "-- Select Office --", new { @class = "form-control" })

5.3. Populating NotMapped Counts

var office = _context.FieldOffices
                     .Include(f => f.Jobs)
                     .Include(f => f.Assets)
                     .First();

office.JobCount       = office.Jobs.Count.ToString();
office.AssetCount     = office.Assets.Count.ToString();

// Suppose we gather unique employees in roles:
var uniqueEmployees   = new HashSet<Guid>();
if (office.ManagerId.HasValue) uniqueEmployees.Add(office.ManagerId.Value);
if (office.ProjectManagerId.HasValue) uniqueEmployees.Add(office.ProjectManagerId.Value);
// … and so on …

office.EmployeeCount  = uniqueEmployees.Count.ToString();

🖼️ UML Class Diagram

classDiagram
    class FieldOffice {
        +Guid Id
        +string JdeNumber
        +string Name
        +string BusinessUnitNumber
        +string BusinessUnitName
        +string MailingAddress
        +string ShippingAddress
        +string FaxNumber
        +string OfficePhone
        +string OfficeExtension
        +decimal Latitude {NotMapped}
        +decimal Longitude {NotMapped}
        +List<SelectListItem> EmployeeData {NotMapped}
        +string JobCount {NotMapped}
        +string EmployeeCount {NotMapped}
        +string AssetCount {NotMapped}
    }
    class Employee
    class Asset
    class Job

    FieldOffice "1" --> "0..1" Employee : Manager
    FieldOffice "1" --> "0..1" Employee : ProjectManager
    FieldOffice "1" --> "0..1" Employee : Superintendent
    FieldOffice "1" --> "0..*" Asset : Assets
    FieldOffice "1" --> "0..*" Job : Jobs

📝 Conclusion

The FieldOffice class is a core domain entity representing organizational offices in the Irby Imaging system. It leverages EF Core annotations for schema mapping, defines rich relationships with Employee, Asset, and Job entities, and contains handy UI-centric properties marked [NotMapped]. By following the patterns above, developers can seamlessly query, display, and manipulate field office data throughout the application.

Happy coding! 🚀