Ejemplo n.º 1
0
        public HttpResponseMessage GetCustomersByRef(string refId)
        {
            GetCustomerByRefResponse 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)));
                }

                //Perform transaction
                CustomerServices customerServices = new CustomerServices();
                var customer = customerServices.GetCustomerByRef(hostId.Value, refId);

                responseData          = new GetCustomerByRefResponse();
                responseData.Customer = customer;

                //Send response
                return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage GetEvents()
        {
            GetEventsResponse 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)));
                }

                //Perform transaction
                EventsServices eventsService = new EventsServices();
                var            events        = eventsService.GetEvents(hostId.Value);

                responseData        = new GetEventsResponse();
                responseData.Events = events;

                //Send response
                return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }
Ejemplo n.º 3
0
        public HttpResponseMessage GetBookingsByCustomer(string referenceId)
        {
            GetBookingsByCustomerResponse 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)));
                }

                //Perform transaction
                BookingServices bookingService = new BookingServices();
                var             bookings       = bookingService.GetBookingsByCustomer(hostId.Value, referenceId);

                responseData          = new GetBookingsByCustomerResponse();
                responseData.Bookings = bookings;

                //Send response
                return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }
Ejemplo n.º 4
0
        public HttpResponseMessage GetInfo()
        {
            HostInfoResponse 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)));
                }

                //Perform transaction
                HostServices hostService = new HostServices();
                var          hostInfo    = hostService.GetHostInfoByAPIKey(RequestHeaders.API_KEY);

                responseData      = new HostInfoResponse();
                responseData.Info = hostInfo;

                //Send response
                return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }
Ejemplo n.º 5
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.º 6
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)));
            }
        }
Ejemplo n.º 7
0
        public HttpResponseMessage CreateCustomer(CreateCustomerRequest request)
        {
            CreateCustomerResponse 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)));
                }

                //Validate input length
                if (request.ReferenceId.Length > 30)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, "Reference ID (max 30 length) is too long.")));
                }

                //Validate customer reference ID
                IdentityServices identityService = new IdentityServices();
                if (identityService.IsRefIdExists(IdentityServices.RefIdTypes.Customer, hostId.Value, request.ReferenceId))
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.DuplicateRefId, ResponseMessages.DuplicateRefId + " (Customer " + request.ReferenceId + ")")));
                }

                //Perform transaction
                CustomerServices customerServices = new CustomerServices();
                responseData = customerServices.CreateCustomer(hostId.Value, request);

                //Send response
                return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }
Ejemplo n.º 8
0
        public HttpResponseMessage GetEventDetailsByRef(string refId)
        {
            GetEventDetailsByRefResponse 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)));
                }

                //Get event
                EventsServices eventsService = new EventsServices();
                var            eventInfo     = eventsService.GetEventByRef(hostId.Value, refId);
                if (eventInfo != null)
                {
                    //Get tiers
                    var tiers = eventsService.GetEventTiersByEventId(eventInfo.EventId.Value);

                    responseData       = new GetEventDetailsByRefResponse();
                    responseData.Event = eventInfo;
                    responseData.Tiers = tiers;
                }

                //Send response
                return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }
Ejemplo n.º 9
0
        public HttpResponseMessage GetTicketByTicketNo(string ticketNo)
        {
            GetTicketsResponse 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)));
                }

                //Perform transaction
                AdmissionServices admissionService = new AdmissionServices();
                var ticket = admissionService.GetTicketByTicketNo(hostId.Value, ticketNo);

                if (ticket == null)
                {
                    return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.RecordNotFound, ResponseMessages.RecordNotFound)));
                }
                else
                {
                    responseData        = new GetTicketsResponse();
                    responseData.Ticket = ticket;

                    return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }
Ejemplo n.º 10
0
        public HttpResponseMessage GetBookingByConfirmationNo(string confirmationNo)
        {
            GetBookingByConfirmationNoResponse 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)));
                }

                //Perform transaction
                BookingServices bookingService = new BookingServices();
                var             bookingDetails = bookingService.GetBookingByConfirmationNo(hostId.Value, confirmationNo);

                if (bookingDetails == null)
                {
                    return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.RecordNotFound, ResponseMessages.RecordNotFound)));
                }
                else
                {
                    responseData = new GetBookingByConfirmationNoResponse();
                    responseData.BookingDetails = bookingDetails;

                    return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }
Ejemplo n.º 11
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)));
            }
        }
Ejemplo n.º 12
0
        public HttpResponseMessage CreateEvent(CreateEventsRequest 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) ||
                    string.IsNullOrEmpty(request.Title) ||
                    !request.StartDate.HasValue ||
                    request.Tiers == null ||
                    request.Tiers.Count == 0)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, ResponseMessages.InvalidParam)));
                }

                //Validate input length
                if (request.ReferenceId.Length > 30)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, "Reference ID (max 30 length) is too long.")));
                }
                if (request.Title.Length > 200 || request.Description.Length > 500)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, "Title (max 200 length) or Description (max 500 length) is too long.")));
                }
                if (request.Tiers.Count > 10)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, "Only a maximum of 10 tiers allowed.")));
                }

                //Ensure that start date is in future
                if (DateTime.UtcNow.Date > request.StartDate.Value)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, "Event start date must be a future date.")));
                }

                //Validate event reference ID
                IdentityServices identityService = new IdentityServices();
                if (identityService.IsRefIdExists(IdentityServices.RefIdTypes.Event, hostId.Value, request.ReferenceId))
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.DuplicateRefId, ResponseMessages.DuplicateRefId + " (Event " + request.ReferenceId + ")")));
                }
                //Validate event tier reference ID and input length
                foreach (var tier in request.Tiers)
                {
                    if (tier.ReferenceId.Length > 30)
                    {
                        return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, "Reference ID (max 30 length) is too long.")));
                    }
                    if (identityService.IsRefIdExists(IdentityServices.RefIdTypes.EventTier, hostId.Value, tier.ReferenceId))
                    {
                        return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.DuplicateRefId, ResponseMessages.DuplicateRefId + " (Tier " + tier.ReferenceId + ")")));
                    }
                    if (tier.Title.Length > 200)
                    {
                        return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, "Tier Title (max 200 length) is too long.")));
                    }
                }

                //Perform transaction
                EventsServices eventsService = new EventsServices();
                eventsService.CreateEvent(hostId.Value, request);

                //Send response
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Success, ResponseMessages.Success)));
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }
Ejemplo n.º 13
0
        public HttpResponseMessage BookEvent(BookEventRequest request)
        {
            BookEventResponse responseData;

            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.EventReferenceId) ||
                    string.IsNullOrEmpty(request.CustomerReferenceId) ||
                    request.Tickets == null ||
                    request.Tickets.Count == 0)
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, ResponseMessages.InvalidParam)));
                }

                //Perform transaction
                BookingServices bookingService = new BookingServices();
                string          status         = null;
                responseData = bookingService.BookEvent(hostId.Value, request, out status);

                if (status == BookEventStatuses.CustomerNotFound)
                {
                    return(Request.CreateResponse(new GenericResponse(null, BookEventStatuses.CustomerNotFound, "CustomerNotFound")));
                }
                else if (status == BookEventStatuses.EventNotFound)
                {
                    return(Request.CreateResponse(new GenericResponse(null, BookEventStatuses.EventNotFound, "EventNotFound")));
                }
                else if (status == BookEventStatuses.TierNotFound)
                {
                    return(Request.CreateResponse(new GenericResponse(null, BookEventStatuses.TierNotFound, "TierNotFound")));
                }
                else if (status == BookEventStatuses.EventNotActive)
                {
                    return(Request.CreateResponse(new GenericResponse(null, BookEventStatuses.EventNotActive, "Event is already cancelled or closed.")));
                }
                else if (status == BookEventStatuses.EventHasAlreadyStarted)
                {
                    return(Request.CreateResponse(new GenericResponse(null, BookEventStatuses.EventHasAlreadyStarted, "EventHasAlreadyStarted")));
                }
                else if (status == BookEventStatuses.InsufficientTickets)
                {
                    return(Request.CreateResponse(new GenericResponse(null, BookEventStatuses.InsufficientTickets, "InsufficientTickets")));
                }
                else if (status == BookEventStatuses.CustomerInsufficientFunds)
                {
                    return(Request.CreateResponse(new GenericResponse(null, BookEventStatuses.CustomerInsufficientFunds, "CustomerInsufficientFunds")));
                }
                else if (status == BookEventStatuses.InvalidTicketQuantity)
                {
                    return(Request.CreateResponse(new GenericResponse(null, BookEventStatuses.InvalidTicketQuantity, "InvalidTicketQuantity")));
                }
                else if (status == BookEventStatuses.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)));
            }
        }