Skip to main content

Overview

The CN_Canchas class provides business logic operations for managing sports courts in the system. It acts as an intermediary between the presentation layer and the data layer (CD_Canchas), handling court-related business rules and operations. Namespace: capa_negocio Dependencies:
  • capa_entidad.CE_Canchas - Court entity model
  • capa_dato.CD_Canchas - Data access layer for courts

Class Definition

public class CN_Canchas
{
    CD_Canchas oCD_Canchas = new CD_Canchas();
}

Methods

ListarCanchas

Retrieves a list of all sports courts from the database.
return
List<CE_Canchas>
A list of all courts in the system
Example:
CN_Canchas cnCanchas = new CN_Canchas();
List<CE_Canchas> canchas = cnCanchas.ListarCanchas();

foreach (var cancha in canchas)
{
    Console.WriteLine($"Court: {cancha.Nombre}, Type: {cancha.Tipo}");
}
Data Layer Call: This method calls CD_Canchas.Listar() which executes the stored procedure SP_Canchas_List.
public List<CE_Canchas> ListarCanchas()
{
    oCD_Canchas = new CD_Canchas();
    return oCD_Canchas.Listar();
}

AgregarCancha

Adds a new sports court to the system.
cancha
CE_Canchas
required
The court object containing:
  • Nombre (string) - Court name
  • Tipo (string) - Court type (e.g., “Fútbol”, “Tenis”)
  • PrecioPorHora (decimal) - Price per hour
Example:
CN_Canchas cnCanchas = new CN_Canchas();
CE_Canchas nuevaCancha = new CE_Canchas
{
    Nombre = "Cancha Principal",
    Tipo = "Fútbol",
    PrecioPorHora = 50.00M
};

cnCanchas.AgregarCancha(nuevaCancha);
Data Layer Call: Calls CD_Canchas.AgregarCancha() which executes the stored procedure SP_Canchas_Insert with the following parameters:
  • @Nombre
  • @Tipo
  • @PrecioPorHora
public void AgregarCancha(CE_Canchas cancha)
{
    oCD_Canchas.AgregarCancha(cancha);
}

Actualizar

Updates an existing sports court’s information.
cancha
CE_Canchas
required
The court object with updated values:
  • IdCancha (int) - Court ID to update
  • Nombre (string) - Updated court name
  • Tipo (string) - Updated court type
  • PrecioPorHora (decimal) - Updated price per hour
Example:
CN_Canchas cnCanchas = new CN_Canchas();
CE_Canchas canchaActualizada = new CE_Canchas
{
    IdCancha = 1,
    Nombre = "Cancha Principal Renovada",
    Tipo = "Fútbol 7",
    PrecioPorHora = 60.00M
};

cnCanchas.Actualizar(canchaActualizada);
Data Layer Call: Calls CD_Canchas.ActualizarCancha() which executes the stored procedure SP_Canchas_Update with parameters:
  • @IdCancha
  • @Nombre
  • @Tipo
  • @PrecioPorHora
public void Actualizar(CE_Canchas cancha)
{
    oCD_Canchas.ActualizarCancha(cancha);
}

Eliminar

Deletes a sports court from the system.
id
int
required
The ID of the court to delete
Example:
CN_Canchas cnCanchas = new CN_Canchas();
int idCanchaEliminar = 5;

cnCanchas.Eliminar(idCanchaEliminar);
Data Layer Call: Calls CD_Canchas.EliminarCancha() which executes the stored procedure SP_Canchas_Delete with parameter @Id.
public void Eliminar(int id)
{
    oCD_Canchas.EliminarCancha(id);
}

Entity Model

The CE_Canchas entity used by this business logic class:
public class CE_Canchas
{
    public int IdCancha { get; set; }
    public string? Nombre { get; set; }
    public string? Tipo { get; set; }
    public decimal PrecioPorHora { get; set; }
    public string? Estado { get; set; }
}

Build docs developers (and LLMs) love