Reserva entity is the aggregate root for the reservation domain. It orchestrates reservations, managing rooms, additional services, pricing snapshots, and state transitions with comprehensive business rule enforcement.
Overview
Reserva encapsulates all reservation logic including date management, room assignments, service additions, cost calculations, and state transitions. It enforces complex business rules through guard clauses and domain policies.
Namespace: SGRH.Domain.Entities.Reservas
Source: ~/workspace/source/SGRH.Domain/Entities/Reservas/Reserva.cs
Properties
Unique identifier for the reservation (primary key).
Reference to the customer making the reservation.
Current state of the reservation:
Pendiente, Confirmada, Cancelada, or Finalizada.Timestamp when the reservation was created (UTC).
Check-in date for the reservation.
Check-out date for the reservation.
Calculated property: Sum of all room rates plus service costs.
Read-only collection of rooms assigned to this reservation.
Read-only collection of additional services for this reservation.
Constructor
Pendiente state.
Parameters
- clienteId: Valid customer ID (must be > 0)
- fechaEntrada: Check-in date
- fechaSalida: Check-out date (must be after check-in)
Initial State
EstadoReserva=PendienteFechaReserva=DateTime.UtcNow- Empty room and service collections
Example
State Management
Estado Reserva Lifecycle
State Transition Methods
Confirmar()
Confirmar()
- Must be in
Pendientestate - Must have at least one room assigned
BusinessRuleViolationExceptionif state is notPendienteBusinessRuleViolationExceptionif no rooms are assigned
Cancelar()
Cancelar()
- Cannot be
Finalizada - Cannot already be
Cancelada
BusinessRuleViolationExceptionif already finalized or canceled
Finalizar()
Finalizar()
- Must be in
Confirmadastate
BusinessRuleViolationExceptionif not confirmed
Date Management
CambiarFechas
- Ensures all assigned rooms are available for new dates
- Checks no rooms are in maintenance during new period
- Validates services are available in the new season
- Recalculates pricing snapshots
Room Management
AgregarHabitacion
- Reservation must be editable (not confirmed/canceled/finalized)
- Room not already in reservation
- Room is available for the date range
- Room is not in maintenance
- Captures current rate as snapshot
QuitarHabitacion
Service Management
AgregarServicio
- At least one room must be assigned first
- Service not already in reservation (use
CambiarCantidadServicioto update) - Service must be available in the current season
- Price snapshot captured at time of addition
CambiarCantidadServicio
QuitarServicio
Business Rules
Editability Rules
Editability Rules
The
EnsureEditable() internal guard prevents modifications when:- State is
Confirmada(confirmed reservations are immutable) - State is
Cancelada(canceled reservations cannot be changed) - State is
Finalizada(finalized reservations are closed)
Pendiente reservations can be modified.Service Prerequisites
Service Prerequisites
Services can only be added to reservations that have at least one room assigned. This ensures services are properly priced based on room categories.
Pricing Snapshots
Pricing Snapshots
When rooms or services are added, current prices are captured as snapshots:
- Room rates are stored in
DetalleReserva.TarifaAplicada - Service prices stored in
ReservaServicioAdicional.PrecioUnitarioAplicado
Pendiente reservations).Duplicate Prevention
Duplicate Prevention
The aggregate prevents duplicates:
- Cannot add the same room twice (throws
ConflictException) - Cannot add the same service twice (throws
ConflictException)
Domain Policy Integration
TheReserva aggregate depends on IReservaDomainPolicy for:
- Room availability checks
- Maintenance schedule validation
- Season determination
- Rate calculation
- Service availability validation
- Service pricing (max price by room category)
Child Entities
DetalleReserva
Represents a room assignment within the reservation.ReservaServicioAdicional
Represents an additional service within the reservation.Related Documentation
- Cliente - Customer entity
- Habitacion - Room entity
- ServicioAdicional - Additional services
- Reservation Policies - Business rules and policies
- Validation Guards - Validation mechanisms