Overview
TheClientesController handles all CRUD operations for client management in the system. It provides endpoints for listing, creating, updating, and deleting client records.
Namespace: capa_presentacion.Controllers
Base Route: /Clientes
Methods
ListarClientes
Retrieves a list of all clients in the system.HTTP Method
GET
Route
/Clientes/ListarClientes
Returns
Type:ActionResult
- Success (200): Returns a view with
List<CE_Clientes>containing all clients - Error: Returns a view with an empty list and sets error message in
TempData["ErrorMessage"]
Response Model
Error Handling
- Validates
ModelStatebefore processing - Catches exceptions and stores error message in
TempData - Returns empty list on error instead of throwing
Usage Example
Source
Controllers/ClientesController.cs:14
InsertarCliente (GET)
Displays the form for adding a new client.HTTP Method
GET
Route
/Clientes/InsertarCliente
Returns
Type:ActionResult
Returns the view for creating a new client.
Usage Example
Source
Controllers/ClientesController.cs:33
InsertarClientes (POST)
Creates a new client in the system.HTTP Method
POST
Route
/Clientes/InsertarClientes
Parameters
The client object to createProperties:
Nombre(string): Full name of the clientTelefono(string): Phone numberCorreo(string): Email addressEstado(bool): Active status of the client
Returns
Type:ActionResult
- Success (302): Redirects to
ListarClientesaction - Error (404): Invalid model state - “No se encontro el modelo”
- Error (500): Exception during creation - “Error al agregar el cliente: “
Error Responses
Model state is invalid
Error during client creation
Usage Example
Notes
- Action method name is
InsertarClientes(plural) while the route parameter iscliente(singular) - Validates model state before processing
Source
Controllers/ClientesController.cs:40
Actualizar (GET)
Retrieves a specific client for editing.HTTP Method
GET
Route
/Clientes/Actualizar/{id}
Parameters
The unique identifier of the client to update
Returns
Type:ActionResult
- Success (200): Returns view with the
CE_Clientesobject - Error (404): Client not found - “No se pudo actualizar el cliente con el id: “
Error Responses
Client with specified ID not found
Usage Example
Source
Controllers/ClientesController.cs:63
Actualizar (POST)
Updates an existing client.HTTP Method
POST
Route
/Clientes/Actualizar
Parameters
The client object with updated informationProperties:
IdCliente(int): ID of the client to updateNombre(string): Updated nameTelefono(string): Updated phoneCorreo(string): Updated emailEstado(bool): Updated active status
Returns
Type:ActionResult
- Success (302): Redirects to
ListarClientesaction - Error (500): Exception during update - “Error al actualizar la cancha: “
Error Responses
Error during client update
Usage Example
Notes
- The method updates the client regardless of
ModelState.IsValidstatus (lines 79-85) - Both validation paths lead to the same update operation
- Error message references “cancha” instead of “cliente” (copy-paste from CanchasController)
Source
Controllers/ClientesController.cs:75
Eliminar
Deletes a client from the system.HTTP Method
POST (inferred from usage pattern)
Route
/Clientes/Eliminar
Parameters
The unique identifier of the client to delete
Returns
Type:ActionResult
- Success (302): Redirects to
ListarClientesaction - Error (500): Exception during deletion - “Error al eliminar el cliente: “
Error Responses
Error during client deletion
Usage Example
Notes
- Includes try-catch error handling unlike the Canchas controller version
- Returns appropriate error message to user
Source
Controllers/ClientesController.cs:99
Dependencies
- Business Layer:
CN_Clientesfromcapa_negocio - Entity Layer:
CE_Clientesfromcapa_entidad - Framework: ASP.NET Core MVC
Error Handling Strategy
- Model Validation: Checks
ModelState.IsValidbefore processing requests - Try-Catch Blocks: Wraps operations in exception handlers
- User Feedback: Uses
TempDatafor error messages in views - Status Codes: Returns appropriate HTTP status codes (404, 500)
- Graceful Degradation: Returns empty lists instead of error pages when listing fails
Known Issues
- Inconsistent Naming: GET method is
InsertarCliente(singular) but POST isInsertarClientes(plural) - Error Message: Update method error message references “cancha” instead of “cliente”
- Missing HTTP Attribute:
Eliminarmethod missing[HttpPost]attribute