Example #1
0
        protected void Page_Load(object sender, EventArgs args)
        {
            var @event = _portal.Value.Entity;

            if (@event == null || @event.LogicalName != "adx_event")
            {
                return;
            }

            var dataAdapter = new EventDataAdapter(@event, new PortalContextDataAdapterDependencies(_portal.Value, PortalName));
            var now         = DateTime.UtcNow;

            var occurrences = (PortalConference != null) ? dataAdapter.SelectEventOccurrences(PortalConference.GetAttributeValue <DateTime?>("adx_startingdate").GetValueOrDefault(now.AddMonths(-3)), PortalConference.GetAttributeValue <DateTime?>("adx_enddate").GetValueOrDefault(now.AddMonths(3))).ToArray() :
                              dataAdapter.SelectEventOccurrences(now.AddMonths(-3), now.AddMonths(3)).ToArray();

            IEventOccurrence requestOccurrence;

            RequestEventOccurrence = dataAdapter.TryMatchRequestEventOccurrence(Request, occurrences, out requestOccurrence)
                                ? requestOccurrence
                                : occurrences.Length == 1 ? occurrences.Single() : null;

            var user = _portal.Value.User;

            CanRegister = Request.IsAuthenticated && user != null && RequestEventOccurrence != null && RequestEventOccurrence.Start >= now &&
                          (@event.GetAttributeValue <EntityReference>("adx_conferenceid") != null && UserIsRegisteredForConference ||
                           @event.GetAttributeValue <EntityReference>("adx_conferenceid") == null);

            RequiresRegistration = (@event.GetAttributeValue <bool?>("adx_requiresregistration").GetValueOrDefault() ||
                                    @event.GetAttributeValue <EntityReference>("adx_conferenceid") != null && UserIsRegisteredForConference) &&
                                   RequestEventOccurrence != null &&
                                   RequestEventOccurrence.Start >= now;

            if (CanRegister)
            {
                var registration = _portal.Value.ServiceContext.CreateQuery("adx_eventregistration")
                                   .FirstOrDefault(e => e.GetAttributeValue <EntityReference>("adx_attendeeid") == user.ToEntityReference() &&
                                                   e.GetAttributeValue <EntityReference>("adx_eventscheduleid") == RequestEventOccurrence.EventSchedule.ToEntityReference());

                if (registration != null)
                {
                    Unregister.CommandArgument = registration.Id.ToString();
                    IsRegistered = true;
                }
            }

            OtherOccurrences.DataSource = occurrences
                                          .Where(e => e.Start >= now)
                                          .Where(e => RequestEventOccurrence == null || !(e.EventSchedule.Id == RequestEventOccurrence.EventSchedule.Id && e.Start == RequestEventOccurrence.Start));

            OtherOccurrences.DataBind();

            var sessionEvent = @event;

            Speakers.DataSource = sessionEvent.GetRelatedEntities(_portal.Value.ServiceContext, new Relationship("adx_eventspeaker_event"));
            Speakers.DataBind();
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs args)
        {
            var @event = _portal.Value.Entity;

            if (@event == null || @event.LogicalName != "adx_event")
            {
                return;
            }

            var dataAdapter = new EventDataAdapter(@event, new PortalContextDataAdapterDependencies(_portal.Value, PortalName));
            var now         = DateTime.UtcNow;

            var past   = Html.TimeSpanSetting("Events/DisplayTimeSpan/Past").GetValueOrDefault(TimeSpan.FromDays(90));
            var future = Html.TimeSpanSetting("Events/DisplayTimeSpan/Future").GetValueOrDefault(TimeSpan.FromDays(90));

            var occurrences = dataAdapter.SelectEventOccurrences(now.Subtract(past), now.Add(future)).ToArray();

            IEventOccurrence requestOccurrence;

            RequestEventOccurrence = dataAdapter.TryMatchRequestEventOccurrence(Request, occurrences, out requestOccurrence)
                                ? requestOccurrence
                                : occurrences.Length == 1 ? occurrences.Single() : null;

            var user = _portal.Value.User;

            CanRegister = Request.IsAuthenticated && user != null && RequestEventOccurrence != null &&
                          RequestEventOccurrence.Start >= now && RequestEventOccurrence.EventSchedule != null &&
                          RequestEventOccurrence.Event != null;

            RequiresRegistration = @event.GetAttributeValue <bool?>("adx_requiresregistration").GetValueOrDefault() &&
                                   RequestEventOccurrence != null &&
                                   RequestEventOccurrence.Start >= now;


            RegistrationRequiresPayment =
                _portal.Value.ServiceContext.CreateQuery("adx_eventproduct")
                .Where(ep => ep.GetAttributeValue <EntityReference>("adx_event") == @event.ToEntityReference())
                .ToList()
                .Any();

            if (CanRegister)
            {
                var registration = _portal.Value.ServiceContext.CreateQuery("adx_eventregistration")
                                   .FirstOrDefault(e => e.GetAttributeValue <EntityReference>("adx_attendeeid") == user.ToEntityReference() &&
                                                   e.GetAttributeValue <EntityReference>("adx_eventscheduleid") == RequestEventOccurrence.EventSchedule.ToEntityReference() &&
                                                   e.GetAttributeValue <OptionSetValue>("statuscode") != null && e.GetAttributeValue <OptionSetValue>("statuscode").Value == (int)EventStatusCode.Completed);

                if (registration != null)
                {
                    IsRegistered = true;
                    Unregister.CommandArgument = registration.Id.ToString();
                }
            }

            OtherOccurrences.DataSource = occurrences
                                          .Where(e => e.Start >= now)
                                          .Where(e => RequestEventOccurrence == null || !(e.EventSchedule.Id == RequestEventOccurrence.EventSchedule.Id && e.Start == RequestEventOccurrence.Start));

            OtherOccurrences.DataBind();

            var sessionEvent = @event;

            Speakers.DataSource = sessionEvent.GetRelatedEntities(_portal.Value.ServiceContext, new Relationship("adx_eventspeaker_event"))
                                  .OrderBy(e => e.GetAttributeValue <string>("adx_name"));

            Speakers.DataBind();
        }