コード例 #1
0
        public TicketPurchase PurchaseTicketWith(Guid reservationId)
        {
            if (!CanPurchaseTicketWith(reservationId))
            {
                throw new ApplicationException("cannot purchase with this id");
            }
            var            reservation = GetReservationWith(reservationId);
            TicketPurchase purchase    = TicketPurchaseFactory.CreateTicket(this, reservation.TicketQuantity);

            reservation.HasBeenRedeemed = true;
            this.purchasedTickets.Add(purchase);
            return(purchase);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        /// <summary>
        /// 根据预定票的id购买指定票
        /// </summary>
        /// <param name="reservationId"></param>
        /// <returns></returns>
        public TicketPurchase PurchaseTicketWith(Guid reservationId)
        {
            //判断当前id的票是否已经存在于预定票务集合中
            if (!CanPurchaseTicketWith(reservationId))
            {
                //若不存在则抛出一个不能购票的异常
                throw new ApplicationException(DetermineWhyATicketCannotbePurchasedWith(reservationId));
            }

            //若存在则获取该预定的票务对象
            TicketReservation reservation = GetReservationWith(reservationId);

            //创建购票实例
            TicketPurchase ticket = TicketPurchaseFactory.CreateTicket(this, reservation.TicketQuantity);

            //并对预定票对象设置其可赎回属性为true
            reservation.HasBeenRedeemed = true;

            //将购票对象加入购票集合中
            PurchasedTickets.Add(ticket);

            return(ticket);
        }