Ejemplo n.º 1
0
        public HttpResponseMessage CancelEvent(CancelEventRequest request)
        {
            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.ReferenceId))
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, ResponseMessages.InvalidParam)));
                }

                //Perform transaction
                EventsServices eventsService = new EventsServices();
                string         status        = eventsService.CancelEvent(hostId.Value, request);

                if (status == CancelEventStatuses.EventNotFound)
                {
                    return(Request.CreateResponse(new GenericResponse(null, CancelEventStatuses.EventNotFound, "Event Not Found")));
                }
                else if (status == CancelEventStatuses.EventNotActive)
                {
                    return(Request.CreateResponse(new GenericResponse(null, CancelEventStatuses.EventNotActive, "Event is already cancelled or closed.")));
                }
                else if (status == CancelEventStatuses.EventHasAlreadyStarted)
                {
                    return(Request.CreateResponse(new GenericResponse(null, CancelEventStatuses.EventHasAlreadyStarted, "Event Has Already Started")));
                }
                else if (status == CancelEventStatuses.Success)
                {
                    return(Request.CreateResponse(new GenericResponse(null, 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)));
            }
        }