Skip to main content

Overview

The IRepositorioEquipo interface and RepositorioEquipo implementation provide comprehensive data access operations for managing teams. This repository includes advanced features like search by name, filtering by municipality, and managing relationships with municipalities and technical directors.

Interface Definition

IRepositorioEquipo.cs

Implementation

RepositorioEquipo.cs

Methods Reference

AddEquipo

Adds a new team to the database with associations to municipality and technical director.
Equipo
required
The Equipo entity to add
int
required
The ID of the municipality where the team is based
int
required
The ID of the technical director managing the team
Equipo
The inserted Equipo entity with its generated ID and populated relationships
Implementation (Lines 10-19)
Key Features:
  • Validates municipality and technical director exist before association
  • Sets relationships to null if referenced entities don’t exist
  • Returns complete entity with relationships
Usage Example:

GetAllEquipos

Retrieves all teams with complete relationship graph.
IEnumerable<Equipo>
Collection of all Equipo entities with eagerly loaded relationships
Implementation (Lines 20-35)
Included Relationships:
  • Municipio - The team’s home municipality
  • DirectorTecnico - The team’s technical director
  • Jugadores - All players on the team
  • PartidosLocal - Matches where team plays as home team
  • PartidosVisitante - Matches where team plays as visiting team
Usage Example:

GetEquipo

Retrieves a specific team by ID with municipality and technical director relationships.
int
required
The ID of the team to retrieve
Equipo
The Equipo entity with Municipio and DirectorTecnico loaded, or null if not found
Implementation (Lines 37-45)
Usage Example:

UpdateEquipo

Updates an existing team’s information and relationships.
Equipo
required
The Equipo entity with updated values (must include valid Id)
int
required
The ID of the new municipality (or existing)
int
required
The ID of the new technical director (or existing)
Equipo
The updated Equipo entity with current relationships
Implementation (Lines 47-57)
Updated Properties:
  • Nombre - Team name
  • Municipio - Associated municipality
  • DirectorTecnico - Associated technical director
Usage Example:

DeleteEquipo

Deletes a team from the database.
int
required
The ID of the team to delete
Equipo
The deleted Equipo entity, or null if not found
Implementation (Lines 59-76)
Deleting a team may fail if:
  • The team has associated players (foreign key constraint)
  • The team is referenced in matches (foreign key constraint)
All foreign keys are configured with DeleteBehavior.Restrict.
Usage Example:

GetEquiposMunicipio

Retrieves all teams belonging to a specific municipality.
int
required
The ID of the municipality
IEnumerable<Equipo>
Collection of Equipo entities from the specified municipality with full relationships
Implementation (Lines 78-91)
Usage Example:

SearchEquipos

Searches for teams by name using partial matching.
string
required
The search term to match against team names (case-sensitive partial match)
IEnumerable<Equipo>
Collection of Equipo entities whose names contain the search term
Implementation (Lines 92-102)
Key Features:
  • Uses .Contains() for partial string matching
  • Loads complete relationship graph
  • Case-sensitive search
Usage Example:

validateDuplicates

Validates whether a team name already exists in the database.
Equipo
required
The Equipo entity to validate
bool
true if a team with the same name already exists, false otherwise
Implementation (Lines 145-170)
Validation Logic:
  • Case-insensitive comparison using .ToLower()
  • Trims whitespace from input
  • Returns false on any exception
This validation does NOT exclude the current entity when updating (unlike DirectorTecnico validation). Any team with a matching name will be flagged as duplicate.
Usage Example:

Dependency Injection

Register the repository in Program.cs:
Program.cs (Line 18)
Inject into controllers:

Common Workflows

Equipo Entity

Domain model for teams

Municipio Repository

Municipality data access

DirectorTecnico Repository

Technical director data access

Jugador Repository

Player data access

Partido Repository

Match data access

Performance Considerations

Optimization Tips:
  • GetAllEquipos() loads complete relationship graph - use GetEquipo() for single entities
  • SearchEquipos() performs case-sensitive search - consider adding case-insensitive variant
  • validateDuplicates() loads all teams - consider indexed query for production
  • All read operations use .AsNoTracking() for better performance