Ejemplo n.º 1
0
        public HttpResponseMessage RedeemTicket(RedeemTicketRequest request)
        {
            RedeemTicketReponse 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
                AdmissionServices admissionService = new AdmissionServices();
                string            status           = null;
                responseData = admissionService.UseTicket(hostId.Value, request.TicketNumber, out status);

                if (status == RedeemTicketStatuses.TicketNotFound)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Failed, "TicketNotFound")));
                }
                else if (status == RedeemTicketStatuses.TicketAlreadyUsed)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Failed, "TicketAlreadyUsed")));
                }
                else if (status == RedeemTicketStatuses.TicketIsInactive)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Failed, "TicketIsInactive")));
                }
                else if (status == RedeemTicketStatuses.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)));
            }
        }
Ejemplo n.º 2
0
        public RedeemTicketReponse UseTicket(long hostId, string ticketNo, out string status)
        {
            RedeemTicketReponse result = null;

            //Validate if ticket exists
            var ticket = GetTicketByTicketNo(hostId, ticketNo);

            if (ticket == null)
            {
                status = RedeemTicketStatuses.TicketNotFound;
                return(null);
            }

            //Check ticket status
            if (ticket.Status == TicketStatuses.Used)
            {
                status = RedeemTicketStatuses.TicketAlreadyUsed;
                return(null);
            }
            else if (ticket.Status != TicketStatuses.Active)
            {
                status = RedeemTicketStatuses.TicketIsInactive;
                return(null);
            }

            //Update ticket status
            UpdateTicketStatus(ticket.TicketId.Value, TicketStatuses.Used);

            //Commit to blockchain
            ContractApi blockchainContract = new ContractApi();

            blockchainContract.RedeemTicket(ticket.TicketNo);

            status = BookEventStatuses.Success;

            result                 = new RedeemTicketReponse();
            result.EventTitle      = ticket.EventTitle;
            result.TierTitle       = ticket.TierTitle;
            result.PaidPrice       = ticket.PaidPrice;
            result.NewTicketStatus = TicketStatuses.Used;

            return(result);
        }