Ejemplo n.º 1
0
        public HttpResponseMessage CancelTicket(CancelTicketRequest request)
        {
            CancelTicketResponse responseData = null;

            try
            {
                //Authenticate API key
                long?hostId = HostServices.GetCallerHostId();
                if (!hostId.HasValue)
                {
                    Log.Warn(ResponseMessages.InvalidAPIKey);
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidAPIKey, ResponseMessages.InvalidAPIKey)));
                }

                //Validate input
                if (request == null ||
                    string.IsNullOrEmpty(request.TicketNumber))
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, ResponseMessages.InvalidParam)));
                }

                //Perform transaction
                EventsServices eventsService = new EventsServices();
                string         status        = null;
                responseData = eventsService.CancelTicket(hostId.Value, request, out status);

                if (status == CancelTicketStatuses.TicketNotFound)
                {
                    return(Request.CreateResponse(new GenericResponse(null, CancelTicketStatuses.TicketNotFound, "TicketNotFound")));
                }
                else if (status == CancelTicketStatuses.TicketAlreadyCancelled)
                {
                    return(Request.CreateResponse(new GenericResponse(null, CancelTicketStatuses.TicketAlreadyCancelled, "TicketAlreadyCancelled")));
                }
                else if (status == CancelTicketStatuses.TicketAlreadyUsed)
                {
                    return(Request.CreateResponse(new GenericResponse(null, CancelTicketStatuses.TicketAlreadyUsed, "TicketAlreadyUsed")));
                }
                else if (status == CancelTicketStatuses.EventNotFound)
                {
                    return(Request.CreateResponse(new GenericResponse(null, CancelTicketStatuses.EventNotFound, "EventNotFound")));
                }
                else if (status == CancelTicketStatuses.EventNotActive)
                {
                    return(Request.CreateResponse(new GenericResponse(null, CancelTicketStatuses.EventNotActive, "Event is already cancelled or closed.")));
                }
                else if (status == CancelTicketStatuses.EventHasAlreadyStarted)
                {
                    return(Request.CreateResponse(new GenericResponse(null, CancelTicketStatuses.EventHasAlreadyStarted, "EventHasAlreadyStarted")));
                }
                else if (status == CancelTicketStatuses.CustomerNotFound)
                {
                    return(Request.CreateResponse(new GenericResponse(null, CancelTicketStatuses.CustomerNotFound, "CustomerNotFound")));
                }
                else if (status == CancelTicketStatuses.Success)
                {
                    return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
                }
                else
                {
                    Log.Error("Unrecognized status: " + status);
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }