public TicketReservationPresentation ReserveTicketsFor(string EventId, int NoOfTkts) { TicketReservationPresentation reservation = new TicketReservationPresentation(); ReserveTicketResponse response = new ReserveTicketResponse(); ReserveTicketRequest request = new ReserveTicketRequest(); request.EventId = EventId; request.TicketQuantity = NoOfTkts; response = _ticketService.ReserveTicket(request); if (response.Success) { reservation.TicketWasSuccessfullyReserved = true; reservation.ReservationId = response.ReservationNumber; reservation.ExpiryDate = response.ExpirationDate; reservation.EventId = response.EventId; reservation.Description = String.Format("{0} ticket(s) reserved for {1}.<br/><small>This reservation will expire on {2} at {3}.</small>", response.NoOfTickets, response.EventName, response.ExpirationDate.ToLongDateString(), response.ExpirationDate.ToLongTimeString()); } else { reservation.TicketWasSuccessfullyReserved = false; reservation.Description = response.Message; } return reservation; }
public ReserveTicketResponse ReserveTicket(ReserveTicketRequest reserveTicketRequest) { ReserveTicketResponse response = new ReserveTicketResponse(); try { Event Event = _eventRepository.FindBy(new Guid(reserveTicketRequest.EventId)); TicketReservation reservation; if (Event.CanReserveTicket(reserveTicketRequest.TicketQuantity)) { reservation = Event.ReserveTicket(reserveTicketRequest.TicketQuantity); _eventRepository.Save(Event); response = reservation.ConvertToReserveTicketResponse(); response.Success = true; } else { response.Success = false; response.Message = String.Format("There are {0} ticket(s) 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; }