Example #1
0
        public ReserveTicketResponse ReserveTicket(ReserveTicketRequest request)
        {
            ReserveTicketResponse response = new ReserveTicketResponse();

            try
            {
                Event Event = _eventRepository.FindBy(new Guid(request.EventId));

                TicketReservation reservation;

                if (Event.CanReserveTicket(request.TicketQuantity))
                {
                    reservation = Event.ReserveTicket(request.TicketQuantity);

                    _eventRepository.Save(Event);

                    response = reservation.ConvertToReserveTicketResponse();
                    response.Success = true;
                }
                else
                {
                    response.Success = false;
                    response.Message = string.Format("There are {0} tickets available.", Event.AvailableAllocation());

                }
            }
             catch (Exception ex)
            {
            // Shield exceptions
            response.Message = ErrorLog.GenerateErrorRefMessageAndLog(ex);
            response.Success = false;
            }
            return response;
        }
 public static ReserveTicketResponse ConvertToReserveTicketResponse(this TicketReservation ticketReservation)
 {
     ReserveTicketResponse response = new ReserveTicketResponse();
     response.EventId = ticketReservation.Event.Id.ToString();
     response.EventName = ticketReservation.Event.Name;
     response.NoOfTickets = ticketReservation.TicketQuantity;
     response.ExpirationDate = ticketReservation.ExpiryTime;
     response.ReservationNumber = ticketReservation.Id.ToString();
     return response;
 }