示例#1
0
        public EventResponse CancelEventParticipant(CancelEventRequest model)
        {
            var response       = new EventResponse();
            var loggedInmember = _memberProvider.GetLoggedInMember();

            if (loggedInmember == null)
            {
                Logger.Warn(typeof(EventController), "Unable to find logged in member record.");
                response.Error = "Unable to find logged in member record.";
                return(response);
            }

            var eventSlot = _eventSlotRepository.GetById(model.EventSlotId);

            if (eventSlot.Date.Date < DateTime.Now.Date)
            {
                response.Error = $"You can not cancel an event which is in the past.";
                return(response);
            }

            IMember eventMember;

            if (model.MemberId.HasValue)
            {
                eventMember = Services.MemberService.GetById(model.MemberId.Value);
                if (eventMember == null)
                {
                    Logger.Warn(typeof(EventController), $"Unable to find member with id {model.MemberId} for event cancellation.");
                    response.Error = $"Unable to find member with id {model.MemberId} for event cancellation.";
                    return(response);
                }
            }
            else
            {
                eventMember = loggedInmember;
                if (eventSlot.Date <= DateTime.Now)
                {
                    response.Error = $"You can not cancel an event which is in the past.";
                    return(response);
                }
            }


            EventParticipant eventParticipant = eventSlot.EventParticipants.FirstOrDefault(ep => ep.MemberId == eventMember.Id);

            if (eventParticipant == null)
            {
                Logger.Warn(typeof(EventController), $"Member {eventMember.Name} is not currently booked onto event slot {model.EventSlotId}.");
                response.Error = "You are not currently booked onto that event";
                return(response);
            }

            CancelEventParticipant(eventMember, eventParticipant);

            List <EventType> eventTypes = _dataTypeProvider.GetEventTypes();

            Logger.Info(typeof(EventController), $"Event slot cancelled - Member: {eventMember.Name} , Event: {eventTypes.SingleOrDefault(et => et.Id == eventSlot.EventTypeId)?.Name} on {eventSlot.Date.ToString("dd/MM/yyyy")} for £{eventParticipant.AmountPaid}.");

            return(response);
        }
示例#2
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)));
            }
        }
        public string CancelEvent(long hostId, CancelEventRequest value)
        {
            //Validate if event
            EventsServices eventsServices = new EventsServices();
            EventInfo      eventInfo      = eventsServices.GetEventByRef(hostId, value.ReferenceId);

            if (eventInfo == null)
            {
                return(CancelEventStatuses.EventNotFound);
            }

            //Validate event status
            if (eventInfo.Status != EventStatuses.Active)
            {
                return(CancelEventStatuses.EventNotActive);
            }

            //Validate if event start date is over
            if (DateTime.UtcNow >= eventInfo.StartDate)
            {
                return(CancelEventStatuses.EventHasAlreadyStarted);
            }

            //Cancel and Refund all tickets
            BookingServices bookingService = new BookingServices();
            var             tickets        = bookingService.GetTicketsByEvent(hostId, value.ReferenceId);

            if (tickets != null)
            {
                foreach (var ticket in tickets)
                {
                    string status = null;
                    CancelAndRefundTicket(hostId, ticket.TicketId.Value, out status);
                    //Not required to check on status as cancel event will try to cancel and refund all tickets
                }
            }

            //Update event status to Cancelled
            UpdateEventStatusRequest req = new UpdateEventStatusRequest();

            req.ReferenceId = value.ReferenceId;
            req.NewStatus   = EventStatuses.Cancelled;
            UpdateEventStatus(hostId, req);

            return(CancelEventStatuses.Success);
        }
示例#4
0
        public EventResponse CancelEventSlot(CancelEventRequest model)
        {
            var     response       = new EventResponse();
            IMember loggedInmember = _memberProvider.GetLoggedInMember();

            if (loggedInmember == null)
            {
                Logger.Warn(typeof(EventController), "Unable to find logged in member record.");
                response.Error = "Unable to find logged in member record.";
                return(response);
            }

            var eventSlot = _eventSlotRepository.GetById(model.EventSlotId);

            if (eventSlot.EventParticipants.Count == 0)
            {
                response.Error = "There are no participants booked onto the event.";
                return(response);
            }

            // Allow for events to be cancelled in the past

            /*if (eventSlot.Date.Date < DateTime.Now.Date)
             * {
             *      response.Error = $"You can not cancel an event which is in the past.";
             *      return response;
             * }*/

            foreach (var eventParticipant in eventSlot.EventParticipants)
            {
                var eventMember = Services.MemberService.GetById(eventParticipant.MemberId);
                CancelEventParticipant(eventMember, eventParticipant);
            }

            List <EventType> eventTypes = _dataTypeProvider.GetEventTypes();

            Logger.Info(typeof(EventController), $"Event slot cancelled for all members - Event: {eventTypes.SingleOrDefault(et => et.Id == eventSlot.EventTypeId)?.Name} on {eventSlot.Date.ToString("dd/MM/yyyy")}.");

            return(response);
        }