public TicketReservation GetReservationWith(Guid reservationId) { if (!HasReservationWith(reservationId)) { throw new ApplicationException(String.Format("No reservation ticket with matching id of ‘{0}’", reservationId.ToString())); } return(ReservedTickets.FirstOrDefault(t => t.Id == reservationId)); }
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); }
public TicketReservation ReserveTicket(int tktQty) { if (!CanReserveTicket(tktQty)) { ThrowExceptionWithDetailsOnWhyTicketsCannotBeReserved(); } TicketReservation reservation = TicketReservationFactory.CreateReservation(this, tktQty); ReservedTickets.Add(reservation); return(reservation); }
/// <summary> /// 获取可以用的票务量 /// </summary> /// <returns></returns> 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); }
private bool HasReservationWith(Guid reservationId) { return(ReservedTickets.Exists(t => t.Id == reservationId)); }