示例#1
0
        public IEnumerable <EventType> BookableEvents(bool futureEventsOnly, bool withSlotsOnly, int limitBooking, bool isAdmin = false)
        {
            try
            {
                var  member       = _memberProvider.GetLoggedInMember();
                var  memberType   = member.GetValue <MembershipTypeEnum>(MemberProperty.membershipType);
                var  btfNumber    = member.GetValue <string>(MemberProperty.BTFNumber);
                bool hasBTFNumber = !string.IsNullOrEmpty(btfNumber);
                var  isGuest      = memberType == MembershipTypeEnum.Guest;

                List <EventType> eventTypes = _dataTypeProvider.GetEventTypes();
                var eventSlots = _eventSlotRepository.GetAll(futureEventsOnly, eventTypes, hasBTFNumber, limitBooking);
                if (!isAdmin)
                {
                    eventSlots = eventSlots.Where(es => es.IsGuestEvent == isGuest);
                }

                foreach (var eventType in eventTypes)
                {
                    eventType.EventSlots = eventSlots.Where(es => es.EventTypeId == eventType.Id).ToList();
                }

                return(withSlotsOnly ?  eventTypes.Where(e => e.EventSlots.Any()) : eventTypes);
            }
            catch (Exception ex)
            {
                Logger.Error(typeof(EventController), string.Format("Exception calling GetEventTypes: {0}", ex.ToString()), ex);
                return(new List <EventType>());
            }
        }
        public void ContentService_Saving(Umbraco.Core.Services.IContentService sender, SaveEventArgs <IContent> e)
        {
            List <EventType> eventTypes = _dataTypeProvider.GetEventTypes();

            foreach (IContent entity in e.SavedEntities)
            {
                if (entity.ContentType.Alias == "event")
                {
                    IPublishedContent eventPageContent = entity.ToPublishedContent();
                    var eventPage = new Event(eventPageContent);
                    if (eventPage.Id == 0)
                    {
                        //No need to check this as must be creating a new event page
                        continue;
                    }

                    var eventType = eventTypes.SingleOrDefault(et => et.Name == eventPage.EventType);
                    if (eventType == null)
                    {
                        //Log and move on
                        _logger.Warn(typeof(ContentEventHandler), $"No event type found for name '{eventPage.EventType}'.");
                        continue;
                    }

                    var eventDates = GetEventDates(eventPage, true);
                    List <EventSlot> existingEventSlots = _eventSlotRepository.GetAll(true, eventTypes, null, null).ToList();
                    existingEventSlots = existingEventSlots.Where(es => es.EventTypeId == eventType.Id && es.EventPageId == eventPage.Id).ToList();
                    if (existingEventSlots.Any(es => eventDates.Contains(es.Date) == false && es.EventParticipants.Count > 0))
                    {
                        string message = $"Unable to save changes - existing bookings for event slots of type {eventType.Name}, please cancel the bookings through the Event Booking Admin page first.";
                        _logger.Warn(typeof(ContentEventHandler), message);
                        //If any slots are no longer needed and have participants then cancel saving with message
                        e.Messages.Add(new EventMessage("Error", message, EventMessageType.Error));
                        e.Cancel = true;
                        return;
                    }
                }
            }
        }