コード例 #1
0
ファイル: Event.cs プロジェクト: Ugwum/EventTicketApplication
        //This method creates a new TicketReservation and adds it to the Events collection
        public TicketReservationModel ReserveTicket(int tktQty)
        {
            if (!CanReserveTicket(tktQty))
            {
                ThrowExceptionWithDetailsOnWhyTicketsCannotBeReserved();
            }

            TicketReservationModel reservation = TicketReservationFactory.CreateReservation(this, tktQty);

            ReservedTickets.Add(reservation);

            return(reservation);
        }
コード例 #2
0
ファイル: Event.cs プロジェクト: Ugwum/EventTicketApplication
        //This method creates a TicketPurchase that matches the reserved ticket.
        public TicketPurchaseModel PurchaseTicketWith(Guid reservationId)
        {
            //check if ticket purchase is possible with a certain reservation Id
            if (!CanPurchaseTicketWith(reservationId))
            {
                throw new ApplicationException(
                          DetermineWhyTicketCannotbePurchasedWith(reservationId));
            }

            //get the reservation assigned to the reservation Id
            TicketReservationModel reservation = GetReservationWith(reservationId);

            //Create a new ticket
            TicketPurchaseModel ticket = TicketPurchaseFactory.CreateTicket(this, reservation.TicketQuantity);

            reservation.HasBeenRedeemed = true;

            PurchasedTickets.Add(ticket);

            return(ticket);
        }
コード例 #3
0
ファイル: Event.cs プロジェクト: Ugwum/EventTicketApplication
        //This method returns a string detailing why a ticket cannot be purchased based on a reservation ID.
        public string DetermineWhyTicketCannotbePurchasedWith(Guid reservationId)
        {
            string reservationIssue = "";

            if (HasReservationWith(reservationId))
            {
                TicketReservationModel 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 expired", reservationId.ToString());
                }
            }
            else
            {
                reservationIssue = String.Format("There is no ticket reservation with the Id '{0}'", reservationId.ToString());
            }

            return(reservationIssue);
        }