コード例 #1
0
        public TicketReservationPresentation ReserveTicketsFor(string eventId, int countOfTickets)
        {
            TicketReservationPresentation reservationPresentation = new TicketReservationPresentation();
            ReservateTicketRequest        request = new ReservateTicketRequest();

            request.EventId        = eventId;
            request.TicketQuantity = countOfTickets;
            ReservateTicketResponse response = _ticketService.ReservateTicket(request);

            if (response.Success)
            {
                reservationPresentation.TicketWasSuccessfullyReserved = true;
                reservationPresentation.ReservationId = response.ReservationId;
                reservationPresentation.ExpiryDate    = response.ExpirationDate;
                reservationPresentation.EventId       = response.EventId;
                reservationPresentation.Description   = String.Format("{0} ticket(s) reserved for {1}.<br/><small>This reservation will expire on {2} at {3}.</small>",
                                                                      response.CountOfTickets, response.EventName, response.ExpirationDate.ToLongDateString(),
                                                                      response.ExpirationDate.ToLongTimeString());
            }
            else
            {
                reservationPresentation.TicketWasSuccessfullyReserved = false;
                reservationPresentation.Description = response.Message;
            }

            return(reservationPresentation);
        }
コード例 #2
0
        public ReservateTicketResponse ReservateTicket(ReservateTicketRequest request)
        {
            ReservateTicketResponse response = new ReservateTicketResponse();

            try
            {
                Event             eventEntity = _eventRepository.FindBy(new Guid(request.EventId));
                TicketReservation reservation;
                if (eventEntity.CanReservateTicket(request.TicketQuantity))
                {
                    reservation = eventEntity.ReservateTicket(request.TicketQuantity);
                    _eventRepository.Save(eventEntity);
                    response         = reservation.ConvertToReservateTicketResponse();
                    response.Success = true;
                }
                else
                {
                    response.Success = false;
                    response.Message = string.Format("只有{0}数量的票是可以预定的", eventEntity.AvailableAllocation());
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ErrorLog.GenerateErrorRefMessageAndLog(ex);
            }

            return(response);
        }