πŸ“„ ContractTypeNumber.cs Documentation


πŸ“‘ Table of Contents

  1. πŸ“ Overview & Purpose
  2. πŸš€ Key Functional Areas
  3. πŸ“¦ Dependencies & Technologies
  4. πŸ†” Data Model
  5. πŸ” Properties Detail
  6. πŸ’Ύ Entity Framework Integration
  7. πŸ› οΈ Usage Examples
  8. πŸ“ˆ UML Class Diagram
  9. 🀝 Integration & Next Steps
  10. πŸ“œ 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 table irby.ContractTypeNumber using EF Core.

  • Uniqueness & Identification
    Uses a GUID (Id) as a primary key, ensuring global uniqueness.

  • Categorization & Counting
    Stores a string-based DocumentType and its corresponding integer TypeCount.

  • 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

πŸ” 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:

  • DocumentType can be constrained via validation attributes (e.g., [Required], [MaxLength(50)]) if business rules demand.
  • TypeCount should 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 AddContractTypeNumber
    • Update-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 an IContractTypeNumberService to encapsulate business logic (e.g., enforcing max counts).

  • API Controller
    Provide endpoints such as:

    • GET /api/contracttypes
    • POST /api/contracttypes
    • PUT /api/contracttypes/{id}
  • Validation & Error Handling

    • Add [Required], [MaxLength], and custom validation logic.
    • Return standardized error responses (400s for invalid data).
  • 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! πŸš€