Reservations are represented by the CE_Reservas entity:
capa_entidad/CE_Reservas.cs
public class CE_Reservas{ public int IdReserva { get; set; } public int IdCancha { get; set; } public int IdCliente { get; set; } public int IdUsuario { get; set; } public DateTime FechaReserva { get; set; } public TimeSpan HoraInicio { get; set; } public TimeSpan HoraFin { get; set; } public string? NombreCliente { get; set; } public string? NombreCancha { get; set; } public string? Comentario { get; set; } public bool Estado { get; set; }}
The entity includes foreign keys to link with fields, clients, and users, plus denormalized names for efficient display.
A ViewModel combines reservation data with lookup lists:
capa_entidad/CE_Reservas.cs
public class ReservaViewModel{ public CE_Reservas Reserva { get; set; } public List<CE_Clientes> ListaClientes { get; set; } public List<CE_Canchas> ListaCanchas { get; set; }}
This pattern enables dropdown selection of clients and fields in the reservation form.
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>()); }}
public ActionResult InsertarReservas(){ // Create the ViewModel ReservaViewModel modelo = new ReservaViewModel(); // Populate dropdown lists modelo.ListaClientes = new CN_Clientes().Listar(); modelo.ListaCanchas = new CN_Canchas().ListarCanchas(); // Initialize the reservation modelo.Reserva = new CE_Reservas(); return View(modelo);}
[HttpGet]public ActionResult Actualizar(int id){ var oReserva = Reservas.Listar(); var reserva = oReserva.FirstOrDefault(c => c.IdReserva == id); if (reserva == null) { return NotFound($"No se pudo actualizar el cliente con el id: {id}"); } return View(reserva);}
The business layer coordinates reservation operations:
capa_negocio/CN_Reservas.cs
public class CN_Reservas{ CD_Reservas oCD_Reservas = new CD_Reservas(); public List<CE_Reservas> Listar() { oCD_Reservas = new CD_Reservas(); return oCD_Reservas.Listar(); } public void InsertarReservas(ReservaViewModel reserva) { oCD_Reservas.InsertarReserva(reserva); } public void Actualizar(CE_Reservas reserva) { oCD_Reservas.ActualizarReserva(reserva); } public void Eliminar(int id) { oCD_Reservas.EliminarReserva(id); } // Search by client name public List<CE_Reservas> ListarNombre(string BuscarNombreReserva) { return oCD_Reservas.ListarNombre(BuscarNombreReserva); }}