Ejemplo n.º 1
0
        public TicketReservation ReserveTicket(int tktQty)
        {
            if (!CanReserveTicket(tktQty))
            {
                ThrowExceptionWithDetailsOnWhyTicketsCannotBeReserved();
            }
            TicketReservation reservation = TicketReservationFactory.CreateReservation(this, tktQty);

            ReservedTickets.Add(reservation);
            return(reservation);
        }
Ejemplo n.º 2
0
        public TicketPurchase PurchaseTicketWith(Guid reservationId)
        {
            if (!CanPurchaseTicketWith(reservationId))
            {
                throw new ApplicationException(DetermineWhyATicketCannotbePurchasedWith(reservationId));
            }
            TicketReservation reservation = GetReservationWith(reservationId);
            TicketPurchase    ticket      = TicketPurchaseFactory.CreateTicket(this, reservation.TicketQuantity);

            reservation.HasBeenRedeemed = true;
            PurchasedTickets.Add(ticket);

            return(ticket);
        }
Ejemplo n.º 3
0
        public string DetermineWhyATicketCannotbePurchasedWith(Guid reservationId)
        {
            string reservationIssue = "";

            if (HasReservationWith(reservationId))
            {
                TicketReservation reservation = GetReservationWith(reservationId);
                if (reservation.HasExpired())
                {
                    reservationIssue =
                        String.Format("Ticket reservation ‘{0}’ has expired", reservationId.ToString());
                }
                else if (reservation.HasBeenRedeemed)
                {
                    reservationIssue = String.Format("Ticket reservation ‘{0}’ has already been redeemed", reservationId.ToString());
                }
            }
            else
            {
                reservationIssue = String.Format("There is no ticket reservation with the Id ‘{0}’", reservationId.ToString());
            }
            return(reservationIssue);
        }