π ContractTypeNumber.cs Documentation
π Table of Contents
- π Overview & Purpose
- π Key Functional Areas
- π¦ Dependencies & Technologies
- π Data Model
- π Properties Detail
- πΎ Entity Framework Integration
- π οΈ Usage Examples
- π UML Class Diagram
- π€ Integration & Next Steps
- π Conclusion
π Overview & Purpose
The ContractTypeNumber class is a domain entity in the IrbyImaging.DomainClasses namespace. Its primary function is to represent a tally of documents of a particular type (e.g., invoices, reports) within the applicationβs database. Each instance corresponds to a row in the irby.ContractTypeNumber table, facilitating:
- Tracking how many documents exist per DocumentType.
- Uniquely identifying each count entry by a Guid key.
- Seamless CRUD operations via Entity Framework Core.
This simple yet crucial entity helps modules that need to display, manage, or report documentβtype counts in the Irby Imaging solution.
π Key Functional Areas
-
Data Persistence
Mapped directly to the SQL tableirby.ContractTypeNumberusing EF Core. -
Uniqueness & Identification
Uses a GUID (Id) as a primary key, ensuring global uniqueness. -
Categorization & Counting
Stores a string-basedDocumentTypeand its corresponding integerTypeCount. -
Lightweight & Focused
No methodsβpurely a data carrier ensuring separation of concerns.
π¦ Dependencies & Technologies
| Dependency | Purpose |
|---|---|
| Microsoft.EntityFrameworkCore | ORM for database mapping & CRUD. |
| System.ComponentModel.DataAnnotations | Attributes for validation & schema mapping. |
| System.ComponentModel.DataAnnotations.Schema | Fineβgrained table/column mapping. |
- Target Framework: .NET Core / .NET 5+
- ORM: Entity Framework Core
- Language: C# 8.0+
π Data Model
namespace IrbyImaging.DomainClasses
{
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
[Table("ContractTypeNumber", Schema = "irby")]
public class ContractTypeNumber
{
[Key]
public Guid Id { get; set; }
public string DocumentType { get; set; }
public int TypeCount { get; set; }
}
}
- Namespace:
IrbyImaging.DomainClasses - Table Mapping:
- Table Name:
ContractTypeNumber - Schema:
irby
- Table Name:
π Properties Detail
| Property | Type | Description |
|---|---|---|
| Id | Guid |
Primary key, uniquely identifies the record. |
| DocumentType | string |
Name of the document category (e.g., βInvoiceβ, βReportβ). |
| TypeCount | int |
Number of documents of the specified type. |
Note:
DocumentTypecan be constrained via validation attributes (e.g.,[Required],[MaxLength(50)]) if business rules demand.TypeCountshould always be β₯Β 0; constraint logic can be added in service layers.
πΎ Entity Framework Integration
DbContext Configuration
public class IrbyDbContext : DbContext
{
public DbSet<ContractTypeNumber> ContractTypeNumbers { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ContractTypeNumber>(entity =>
{
entity.ToTable("ContractTypeNumber", "irby");
entity.HasKey(e => e.Id);
entity.Property(e => e.DocumentType)
.IsRequired()
.HasMaxLength(100);
entity.Property(e => e.TypeCount)
.HasDefaultValue(0);
});
}
}
- Migration
Add-Migration AddContractTypeNumberUpdate-Database
π οΈ Usage Examples
1. Creating a New Record
var newTypeCount = new ContractTypeNumber
{
Id = Guid.NewGuid(),
DocumentType = "Invoice",
TypeCount = 10
};
using var context = new IrbyDbContext();
context.ContractTypeNumbers.Add(newTypeCount);
context.SaveChanges();
2. Updating the Count
using var context = new IrbyDbContext();
var invoiceCount = context.ContractTypeNumbers
.FirstOrDefault(ct => ct.DocumentType == "Invoice");
if (invoiceCount != null)
{
invoiceCount.TypeCount += 5;
context.SaveChanges();
}
3. Retrieving All Types
using var context = new IrbyDbContext();
var allCounts = context.ContractTypeNumbers.ToList();
// e.g. [ { DocumentType="Invoice", TypeCount=15 }, ... ]
π UML Class Diagram
classDiagram
class ContractTypeNumber {
<<Entity>>
Guid Id
string DocumentType
int TypeCount
}
ContractTypeNumber : +Id
ContractTypeNumber : +DocumentType
ContractTypeNumber : +TypeCount
π€ Integration & Next Steps
-
Service Layer
Implement anIContractTypeNumberServiceto encapsulate business logic (e.g., enforcing max counts). -
API Controller
Provide endpoints such as:GET /api/contracttypesPOST /api/contracttypesPUT /api/contracttypes/{id}
-
Validation & Error Handling
- Add
[Required],[MaxLength], and custom validation logic. - Return standardized error responses (400s for invalid data).
- Add
-
UI / Reporting
- Display counts in dashboards.
- Filter by
DocumentType.
π Conclusion
The ContractTypeNumber class is a lightweight domain entity tailored for tracking counts of various document categories. Mapped via EF Core to the irby.ContractTypeNumber table, it serves as a foundational building block for services, APIs, and UI components that require simple, robust counting functionality. By extending with validation, service-layer rules, and API endpoints, you can fully leverage its design in the broader Irby Imaging ecosystem.
Happy Coding! π