Exemple #1
0
        public HttpResponseMessage ClaimEarnings(ClaimEarningsRequest request)
        {
            ClaimEarningsResponse 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.ReferenceId))
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, ResponseMessages.InvalidParam)));
                }

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

                if (status == ClaimEarningsStatuses.EventNotFound)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ClaimEarningsStatuses.EventNotFound, "EventNotFound")));
                }
                else if (status == ClaimEarningsStatuses.EventNotStarted)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ClaimEarningsStatuses.EventNotStarted, "Event has not started. Event start date must be over before earnings for the event can be claimed.")));
                }
                else if (status == ClaimEarningsStatuses.EventAlreadyClaimed)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ClaimEarningsStatuses.EventAlreadyClaimed, "EventAlreadyClaimed")));
                }
                else if (status == ClaimEarningsStatuses.EventAlreadyCancelled)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ClaimEarningsStatuses.EventAlreadyCancelled, "EventAlreadyCancelled")));
                }
                else if (status == ClaimEarningsStatuses.HostNotFound)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ClaimEarningsStatuses.HostNotFound, "HostNotFound")));
                }
                else if (status == ClaimEarningsStatuses.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)));
            }
        }