Пример #1
0
        //This method calculates the number of tickets available to sell
        //based on the initial number of tickets available to an event minus the number of tickets
        //already sold and the number of tickets that are currently reserved.
        public int AvailableAllocation()
        {
            int salesAndReservations = 0;

            PurchasedTickets.ForEach(t => salesAndReservations += t.TicketQuantity);

            ReservedTickets.FindAll(r => r.StillActive()).ForEach(r => salesAndReservations += r.TicketQuantity);

            return(Allocation - salesAndReservations);
        }
Пример #2
0
        //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
 public IEnumerable <Ticket> GetTicketsPurchasedByUser(User user)
 => PurchasedTickets.Where(x => x.UserId == user.Id);