Exemple #1
0
        public ReservationOption FindReservationOption(int requestedSeatCount)
        {
            var option = new ReservationOption(trainId, requestedSeatCount);

            foreach (var seatWithBookingReference in this.Seats)
            {
                if (seatWithBookingReference.IsAvailable)
                {
                    option.AddSeatReservation(seatWithBookingReference.Seat);
                    if (option.IsFullfiled)
                    {
                        break;
                    }
                }
            }

            return(option);
        }
Exemple #2
0
        public ReservationOption FindReservationOption(int requestedSeatCount)
        {
            var option = new ReservationOption(TrainId, requestedSeatCount);

            if (!StillAllowedToReserveInThatTrain(requestedSeatCount))
            {
                return(option);
            }

            // Try the nice way (i.e. by respecting the "no more 70% of every coach" rule)
            foreach (var coach in coaches.Values)
            {
                if (coach.HasEnoughAvailableSeatsIfWeFollowTheIdealPolicy(requestedSeatCount))
                {
                    option = coach.FindReservationOption(requestedSeatCount);
                    if (option.IsFullfiled)
                    {
                        return(option);
                    }
                }
            }

            if (!option.IsFullfiled)
            {
                // Try the hard way (i.e. don't respect the "no more 70% of every coach" rule)
                foreach (var coach in coaches.Values)
                {
                    option = coach.FindReservationOption(requestedSeatCount);
                    if (option.IsFullfiled)
                    {
                        return(option);
                    }
                }
            }

            return(option);
        }