public static TicketReservation CreateReservation(Event Event, int tktQty) { TicketReservation reservation = new TicketReservation(); reservation.Id = Guid.NewGuid(); reservation.Event = Event; reservation.ExpiryTime = DateTime.Now.AddMinutes(1); reservation.TicketQuantity = tktQty; return(reservation); }
public TicketReservation ReserveTicket(int tktQty) { if (!CanReserveTicket(tktQty)) { ThrowExceptionWithDetailsOnWhyTicketsCannotBeReserved(); } TicketReservation reservation = TicketReservationFactory.CreateReservation(this, tktQty); ReservedTickets.Add(reservation); return(reservation); }
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); }
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); }