Skip to main content

Get Started in Minutes

This guide will help you set up and run the Canchas Deportivas booking system quickly. You’ll have a working application running locally with all core features operational.
Prerequisites: Ensure you have .NET 8.0 SDK, SQL Server, and Visual Studio 2022 (or VS Code) installed on your machine.

Quick Setup

1

Clone the Repository

Get the source code on your local machine:
git clone <repository-url>
cd canchas-deportivas
2

Restore Dependencies

Navigate to the solution directory and restore NuGet packages:
dotnet restore
The solution includes these packages:
  • Microsoft.Data.SqlClient (v6.1.2) - SQL Server data access
  • Microsoft.VisualStudio.Web.CodeGeneration.Design (v8.0.7) - Code generation tools
3

Configure Database Connection

Update the connection string in /source/capa_dato/CD_conexion.cs:
capa_dato/CD_conexion.cs
private readonly SqlConnection conexion = new SqlConnection(
    "Data Source=YOUR_SERVER_NAME;" +
    "Initial Catalog=DB_canchasdeportivas;" +
    "Integrated Security=True;" +
    "Encrypt=True;" +
    "Trust Server Certificate=True"
);
Replace YOUR_SERVER_NAME with your actual SQL Server instance name. For local SQL Server Express, this is typically localhost\\SQLEXPRESS.
4

Create Database and Schema

Execute the following SQL to create your database:
CREATE DATABASE DB_canchasdeportivas;
GO

USE DB_canchasdeportivas;
GO

-- Create Canchas table
CREATE TABLE Canchas (
    IdCancha INT PRIMARY KEY IDENTITY(1,1),
    Nombre NVARCHAR(100) NOT NULL,
    Tipo NVARCHAR(50),
    PrecioPorHora DECIMAL(10,2) NOT NULL,
    Estado NVARCHAR(20)
);

-- Create Clientes table
CREATE TABLE Clientes (
    IdCliente INT PRIMARY KEY IDENTITY(1,1),
    Nombre NVARCHAR(100) NOT NULL,
    Telefono NVARCHAR(20),
    Email NVARCHAR(100)
);

-- Create Usuarios table
CREATE TABLE Usuarios (
    IdUsuario INT PRIMARY KEY IDENTITY(1,1),
    NombreUsuario NVARCHAR(50) NOT NULL,
    Password NVARCHAR(255)
);

-- Create Reservas table
CREATE TABLE Reservas (
    IdReserva INT PRIMARY KEY IDENTITY(1,1),
    IdCancha INT FOREIGN KEY REFERENCES Canchas(IdCancha),
    IdCliente INT FOREIGN KEY REFERENCES Clientes(IdCliente),
    IdUsuario INT FOREIGN KEY REFERENCES Usuarios(IdUsuario),
    FechaReserva DATE NOT NULL,
    HoraInicio TIME NOT NULL,
    HoraFin TIME NOT NULL,
    Comentario NVARCHAR(500),
    Estado BIT DEFAULT 1
);
5

Create Required Stored Procedures

The application uses stored procedures for data operations. Create the essential ones:
-- List all reservations with related data
CREATE PROCEDURE SP_Reservas_List
AS
BEGIN
    SELECT 
        r.IdReserva,
        r.IdCancha,
        r.IdCliente,
        r.IdUsuario,
        r.FechaReserva,
        r.HoraInicio,
        r.HoraFin,
        r.Comentario,
        r.Estado,
        c.Nombre AS NombreCliente,
        ca.Nombre AS NombreCancha
    FROM Reservas r
    INNER JOIN Clientes c ON r.IdCliente = c.IdCliente
    INNER JOIN Canchas ca ON r.IdCancha = ca.IdCancha
    ORDER BY r.FechaReserva DESC, r.HoraInicio DESC;
END;
GO

-- Insert new reservation
CREATE PROCEDURE SP_Reservas_Insert
    @IdCancha INT,
    @IdCliente INT,
    @IdUsuario INT,
    @FechaReserva DATE,
    @HoraInicio TIME,
    @HoraFin TIME,
    @Comentario NVARCHAR(500)
AS
BEGIN
    INSERT INTO Reservas (IdCancha, IdCliente, IdUsuario, FechaReserva, HoraInicio, HoraFin, Comentario, Estado)
    VALUES (@IdCancha, @IdCliente, @IdUsuario, @FechaReserva, @HoraInicio, @HoraFin, @Comentario, 1);
END;
GO

-- Update existing reservation
CREATE PROCEDURE SP_Reservas_Update
    @IdReserva INT,
    @IdCancha INT,
    @IdCliente INT,
    @IdUsuario INT,
    @FechaReserva DATE,
    @HoraInicio TIME,
    @HoraFin TIME,
    @Comentario NVARCHAR(500),
    @Estado BIT
AS
BEGIN
    UPDATE Reservas
    SET IdCancha = @IdCancha,
        IdCliente = @IdCliente,
        IdUsuario = @IdUsuario,
        FechaReserva = @FechaReserva,
        HoraInicio = @HoraInicio,
        HoraFin = @HoraFin,
        Comentario = @Comentario,
        Estado = @Estado
    WHERE IdReserva = @IdReserva;
END;
GO

-- Delete reservation
CREATE PROCEDURE SP_Reservas_Delete
    @Id INT
AS
BEGIN
    DELETE FROM Reservas WHERE IdReserva = @Id;
END;
GO

-- Search reservations by client name
CREATE PROCEDURE SP_Listar_Reservas_Nombre
    @Buscar NVARCHAR(100)
AS
BEGIN
    SELECT 
        r.IdReserva,
        r.IdCancha,
        r.IdCliente,
        r.IdUsuario,
        r.FechaReserva,
        r.HoraInicio,
        r.HoraFin,
        r.Comentario,
        r.Estado,
        c.Nombre AS NombreCliente,
        ca.Nombre AS NombreCancha
    FROM Reservas r
    INNER JOIN Clientes c ON r.IdCliente = c.IdCliente
    INNER JOIN Canchas ca ON r.IdCancha = ca.IdCancha
    WHERE c.Nombre LIKE '%' + @Buscar + '%'
    ORDER BY r.FechaReserva DESC;
END;
GO
You’ll need to create similar stored procedures for Canchas and Clientes tables. See the Installation Guide for the complete set.
6

Add Sample Data

Insert some test data to get started:
-- Add sample sports fields
INSERT INTO Canchas (Nombre, Tipo, PrecioPorHora, Estado)
VALUES 
    ('Cancha Principal', 'Fútbol 11', 150.00, 'Disponible'),
    ('Cancha Norte', 'Fútbol 7', 100.00, 'Disponible'),
    ('Cancha Sur', 'Fútbol 5', 80.00, 'Disponible');

-- Add sample clients
INSERT INTO Clientes (Nombre, Telefono, Email)
VALUES 
    ('Juan Pérez', '555-0101', '[email protected]'),
    ('María González', '555-0102', '[email protected]'),
    ('Carlos Rodríguez', '555-0103', '[email protected]');

-- Add default user
INSERT INTO Usuarios (NombreUsuario, Password)
VALUES ('admin', 'admin123');

-- Add sample reservation
INSERT INTO Reservas (IdCancha, IdCliente, IdUsuario, FechaReserva, HoraInicio, HoraFin, Comentario, Estado)
VALUES (1, 1, 1, GETDATE(), '18:00:00', '20:00:00', 'Partido amistoso', 1);
7

Build and Run

Build the presentation layer project and run the application:
cd source/capa_presentacion
dotnet build
dotnet run
The application will start on http://localhost:5000 (or the port specified in launchSettings.json).
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
8

Verify Installation

Open your browser and navigate to the application:
  • Home: http://localhost:5000
  • Reservations: http://localhost:5000/Reservas/ListarReservas
  • Sports Fields: http://localhost:5000/Canchas
  • Clients: http://localhost:5000/Clientes
You should see the sample data you inserted in Step 6.

Understanding the Application Flow

Once running, here’s how the application works:

View Reservations

Navigate to /Reservas/ListarReservas to see all bookings with client names, field details, and time slots

Create Booking

Use /Reservas/InsertarReservas to create new reservations with dropdowns for clients and fields

Search Functionality

Use /Reservas/BuscarReservaNombre to filter reservations by client name

Manage Fields

Access /Canchas to view and manage sports field configurations

Key Code Snippets

Here’s how the reservation controller lists bookings:
capa_presentacion/Controllers/ReservasController.cs
public ActionResult ListarReservas()
{
    try
    {
        if (!ModelState.IsValid)
        {
            throw new Exception("El estado del modelo no es válido.");
        }
        var olista = Reservas.Listar();
        return View(olista);
    }
    catch (Exception ex)
    {
        TempData["ErrorMessage"] = "Error al obtener la lista de reservas: " + ex.Message;
        return View(new List<CE_Reservas>());
    }
}
And here’s how data is retrieved from the database:
capa_dato/CD_Reservas.cs
public List<CE_Reservas> Listar()
{
    var ListarReserva = new List<CE_Reservas>();
    
    using (var conexionAbierta = conexion.abrir_conexion())
    {
        using (var comando = new SqlCommand("SP_Reservas_List", conexionAbierta))
        {
            comando.CommandType = System.Data.CommandType.StoredProcedure;
            using (var lector = comando.ExecuteReader())
            {
                while (lector.Read())
                {
                    ListarReserva.Add(new CE_Reservas
                    {
                        IdReserva = Convert.ToInt32(lector["IdReserva"]),
                        IdCancha = Convert.ToInt32(lector["IdCancha"]),
                        IdCliente = Convert.ToInt32(lector["IdCliente"]),
                        FechaReserva = Convert.ToDateTime(lector["FechaReserva"]),
                        HoraInicio = (TimeSpan)(lector["HoraInicio"]),
                        HoraFin = (TimeSpan)(lector["HoraFin"]),
                        NombreCliente = lector["Nombre"].ToString(),
                        NombreCancha = lector["NombreCancha"].ToString(),
                        Estado = Convert.ToBoolean(lector["Estado"])
                    });
                }
            }
        }
        conexion.cerrar_conexion();
        return ListarReserva;
    }
}

Common Issues and Solutions

If you see connection errors, verify:
  • SQL Server is running
  • Server name in connection string is correct
  • Windows Authentication is enabled or use SQL Server authentication
  • Firewall allows connections to SQL Server
Ensure all stored procedures are created in the correct database:
USE DB_canchasdeportivas;
GO
SELECT name FROM sys.procedures;
You should see: SP_Reservas_List, SP_Reservas_Insert, SP_Reservas_Update, SP_Reservas_Delete
Make sure you have .NET 8.0 SDK installed:
dotnet --version
Should return 8.0.x or higher.
If port 5000 is occupied, modify the port in Properties/launchSettings.json or let Kestrel assign a random port.

Next Steps

Complete Installation

Set up all stored procedures, configure authentication, and production settings

Architecture Guide

Learn about the three-tier architecture and how components interact

API Reference

Explore all controllers, models, and data access methods

Database Setup

Configure your database and stored procedures
You now have a working Canchas Deportivas installation! Explore the application and check out the detailed guides for more advanced configurations.

Build docs developers (and LLMs) love