public static TicketReservation CreateTicket(Event pEvent, int ticketQuantity) { TicketReservation ticketReservation = new TicketReservation(); ticketReservation.Id = Guid.NewGuid(); ticketReservation.Event = pEvent; ticketReservation.ExpiryTime = DateTime.Now.AddMinutes(1); ticketReservation.TicketQuantity = ticketQuantity; return(ticketReservation); }
public TicketReservation ReservateTicket(int ticketQuantity) { if (!CanReservateTicket(ticketQuantity)) { throw new ApplicationException("此票不能被预定"); } TicketReservation reservation = TicketReservationFactory.CreateTicket(this, ticketQuantity); TicketReservations.Add(reservation); return(reservation); }
public TicketPurchase PurchaseTicketWith(Guid reservationId) { if (!CanPurchaseTicketWith(reservationId)) { throw new ApplicationException("此预定票不能被购买"); } TicketReservation ticketReservation = GetTicketReservationWith(reservationId); TicketPurchase ticketPurchase = TicketPurchaseFactory.CreateTicket(this, ticketReservation.TicketQuantity); ticketReservation.HasBeenRedeemed = true; TicketPurchases.Add(ticketPurchase); return(ticketPurchase); }
public string DetermineWhyATicketCannotbePurchasedWith(Guid reservationId) { string reservationIssue = ""; if (HasReservationWith(reservationId)) { TicketReservation reservation = GetTicketReservationWith(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); }