Skip to main content

Overview

The IRepositorioDT interface and RepositorioDT implementation provide data access operations for managing technical directors in the tournament system. Each technical director can be associated with multiple teams.

Interface Definition

IRepositorioDT.cs

Implementation

RepositorioDT.cs

Methods Reference

AddDT

Adds a new technical director to the database.
DirectorTecnico
required
The DirectorTecnico entity to add
DirectorTecnico
The inserted DirectorTecnico entity with its generated ID
Implementation (Lines 8-14)
Usage Example:

GetAllDTs

Retrieves all technical directors with their associated teams.
IEnumerable<DirectorTecnico>
Collection of all DirectorTecnico entities with eagerly loaded Equipos
Implementation (Lines 16-28)
Key Features:
  • Uses .Include(e => e.Equipos) to eagerly load related teams
  • Uses .AsNoTracking() for improved read performance
  • Returns complete object graph including teams
Usage Example:

GetDT

Retrieves a specific technical director by ID.
int
required
The ID of the technical director to retrieve
DirectorTecnico
The DirectorTecnico entity, or null if not found
Implementation (Lines 29-33)
Usage Example:

UpdateDT

Updates an existing technical director’s information.
DirectorTecnico
required
The DirectorTecnico entity with updated values (must include valid Id)
DirectorTecnico
The updated DirectorTecnico entity
Exception
Throws exception with message “DT not found” if the ID doesn’t exist
Implementation (Lines 34-49)
Updated Properties:
  • Nombre - Technical director’s name
  • Documento - Identification document number
  • Telefono - Phone number
Usage Example:

DeleteDT

Deletes a technical director from the database.
int
required
The ID of the technical director to delete
DirectorTecnico
The deleted DirectorTecnico entity
Exception
Throws exception with message “DT not found” if the ID doesn’t exist
Implementation (Lines 50-63)
Deleting a technical director may fail if they are referenced by teams due to foreign key constraints configured with DeleteBehavior.Restrict.
Usage Example:

validateDuplicates

Validates whether a technical director’s document number already exists in the database.
DirectorTecnico
required
The DirectorTecnico entity to validate
bool
true if a duplicate document exists (different DT with same document), false otherwise
Implementation (Lines 65-102)
Validation Logic:
  1. Compares Documento field (trimmed) with existing records
  2. If same ID, allows update (not considered duplicate)
  3. If different ID with same document, marks as duplicate
  4. Returns false on any exception
Usage Example:

Dependency Injection

Register the repository in Program.cs:
Inject into controllers or services:

DirectorTecnico Entity

Domain model for technical directors

Equipo Repository

Teams managed by technical directors

Common Workflows

Error Handling

The UpdateDT and DeleteDT methods throw exceptions when the entity is not found. Always handle these exceptions:

Performance Considerations

  • GetAllDTs() uses .AsNoTracking() for improved read performance
  • validateDuplicates() calls GetAllDTs(), which may be inefficient for large datasets
  • Consider implementing indexed queries for duplicate validation in production