Example #1
0
 /// <summary>
 /// Handles the Click event of the lbDeleteRegistration control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 protected void lbDeleteRegistration_Click(object sender, EventArgs e)
 {
     LinkageState = new EventItemOccurrenceGroupMap {
         Guid = Guid.Empty
     };
     DisplayRegistration();
 }
Example #2
0
 /// <summary>
 /// Handles the Click event of the lbLinkToExistingRegistration control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 protected void lbLinkToExistingRegistration_Click(object sender, EventArgs e)
 {
     LinkageState = new EventItemOccurrenceGroupMap {
         Guid = Guid.Empty
     };
     ShowExistingLinkageDialog();
 }
Example #3
0
        private void ShowEditDetails(EventItemOccurrence eventItemOccurrence)
        {
            if (eventItemOccurrence == null)
            {
                eventItemOccurrence = new EventItemOccurrence();
            }

            if (eventItemOccurrence.Id == 0)
            {
                lActionTitle.Text = ActionTitle.Add("Event Occurrence").FormatAsHtmlTitle();
            }
            else
            {
                lActionTitle.Text = ActionTitle.Edit("Event Occurrence").FormatAsHtmlTitle();
            }

            SetEditMode(true);

            hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString();

            ddlCampus.SetValue(eventItemOccurrence.CampusId ?? -1);
            tbLocation.Text = eventItemOccurrence.Location;

            if (eventItemOccurrence.Schedule != null)
            {
                sbSchedule.iCalendarContent = eventItemOccurrence.Schedule.iCalendarContent;
                lScheduleText.Text          = eventItemOccurrence.Schedule.FriendlyScheduleText;
            }
            else
            {
                sbSchedule.iCalendarContent = string.Empty;
                lScheduleText.Text          = string.Empty;
            }

            ppContact.SetValue(eventItemOccurrence.ContactPersonAlias != null ? eventItemOccurrence.ContactPersonAlias.Person : null);
            pnPhone.Text = eventItemOccurrence.ContactPhone;
            tbEmail.Text = eventItemOccurrence.ContactEmail;

            htmlOccurrenceNote.Text = eventItemOccurrence.Note;

            LinkageState = new EventItemOccurrenceGroupMap {
                Guid = Guid.Empty
            };
            var registration = eventItemOccurrence.Linkages.FirstOrDefault();

            if (registration != null)
            {
                LinkageState = registration.Clone(false);
                LinkageState.RegistrationInstance = registration.RegistrationInstance != null?registration.RegistrationInstance.Clone(false) : new RegistrationInstance();

                LinkageState.RegistrationInstance.RegistrationTemplate =
                    registration.RegistrationInstance != null && registration.RegistrationInstance.RegistrationTemplate != null?
                    registration.RegistrationInstance.RegistrationTemplate.Clone(false) : new RegistrationTemplate();

                LinkageState.Group = registration.Group != null?registration.Group.Clone(false) : new Group();
            }

            DisplayRegistration();
        }
Example #4
0
        /// <summary>
        /// Restores the view-state information from a previous user control request that was saved by the <see cref="M:System.Web.UI.UserControl.SaveViewState" /> method.
        /// </summary>
        /// <param name="savedState">An <see cref="T:System.Object" /> that represents the user control state to be restored.</param>
        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);

            string json = ViewState["LinkageState"] as string;

            if (string.IsNullOrWhiteSpace(json))
            {
                LinkageState = new EventItemOccurrenceGroupMap();
            }
            else
            {
                LinkageState = JsonConvert.DeserializeObject <EventItemOccurrenceGroupMap>(json);
            }
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        public void ShowDetail(int linkageId)
        {
            pnlDetails.Visible = true;

            EventItemOccurrenceGroupMap linkage = null;

            var rockContext = new RockContext();

            if (!linkageId.Equals(0))
            {
                linkage           = new EventItemOccurrenceGroupMapService(rockContext).Get(linkageId);
                lActionTitle.Text = ActionTitle.Edit("Linkage").FormatAsHtmlTitle();
            }

            if (linkage == null)
            {
                linkage = new EventItemOccurrenceGroupMap {
                    Id = 0
                };
                lActionTitle.Text = ActionTitle.Add("Linkage").FormatAsHtmlTitle();
            }

            hfLinkageId.Value = linkage.Id.ToString();

            if (linkage.EventItemOccurrence != null)
            {
                hfLinkageEventItemOccurrenceId.Value       = linkage.EventItemOccurrence.Id.ToString();
                lLinkageEventItemOccurrence.Text           = linkage.EventItemOccurrence.ToString();
                lbLinkageEventItemOccurrenceAdd.Visible    = false;
                lbLinkageEventItemOccurrenceRemove.Visible = true;
            }
            else
            {
                hfLinkageEventItemOccurrenceId.Value       = string.Empty;
                lLinkageEventItemOccurrence.Text           = string.Empty;
                lbLinkageEventItemOccurrenceAdd.Visible    = true;
                lbLinkageEventItemOccurrenceRemove.Visible = false;
            }

            gpLinkageGroup.SetValue(linkage.Group);
            gpLinkageGroup_SelectItem(null, null);

            tbLinkagePublicName.Text = linkage.PublicName;
            tbLinkageUrlSlug.Text    = linkage.UrlSlug;
        }
Example #6
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        public void ShowDetail( int linkageId )
        {
            pnlDetails.Visible = true;

            EventItemOccurrenceGroupMap linkage = null;

            var rockContext = new RockContext();

            if ( !linkageId.Equals( 0 ) )
            {
                linkage = new EventItemOccurrenceGroupMapService( rockContext ).Get( linkageId );
                lActionTitle.Text = ActionTitle.Edit( "Linkage" ).FormatAsHtmlTitle();
            }

            if ( linkage == null )
            {
                linkage = new EventItemOccurrenceGroupMap { Id = 0 };
                lActionTitle.Text = ActionTitle.Add( "Linkage" ).FormatAsHtmlTitle();
            }

            hfLinkageId.Value = linkage.Id.ToString();

            if ( linkage.EventItemOccurrence != null )
            {
                hfLinkageEventItemOccurrenceId.Value = linkage.EventItemOccurrence.Id.ToString();
                lLinkageEventItemOccurrence.Text = linkage.EventItemOccurrence.ToString();
                lbLinkageEventItemOccurrenceAdd.Visible = false;
                lbLinkageEventItemOccurrenceRemove.Visible = true;
            }
            else
            {
                hfLinkageEventItemOccurrenceId.Value = string.Empty;
                lLinkageEventItemOccurrence.Text = string.Empty;
                lbLinkageEventItemOccurrenceAdd.Visible = true;
                lbLinkageEventItemOccurrenceRemove.Visible = false;
            }

            gpLinkageGroup.SetValue( linkage.Group );

            tbLinkagePublicName.Text = linkage.PublicName;
            tbLinkageUrlSlug.Text = linkage.UrlSlug;
        }
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                var service = new EventItemOccurrenceGroupMapService(rockContext);

                EventItemOccurrenceGroupMap linkage = null;

                int?linkageId = hfLinkageId.Value.AsIntegerOrNull();
                if (linkageId.HasValue)
                {
                    linkage = service.Get(linkageId.Value);
                }

                if (linkage == null)
                {
                    linkage = new EventItemOccurrenceGroupMap();
                    linkage.RegistrationInstanceId = PageParameter("RegistrationInstanceId").AsInteger();
                    service.Add(linkage);
                }

                linkage.EventItemOccurrenceId = hfLinkageEventItemOccurrenceId.Value.AsIntegerOrNull();
                linkage.GroupId    = gpLinkageGroup.SelectedValueAsInt();
                linkage.PublicName = tbLinkagePublicName.Text;
                linkage.UrlSlug    = tbLinkageUrlSlug.Text;

                if (!Page.IsValid || !linkage.IsValid)
                {
                    return;
                }

                rockContext.SaveChanges();
            }

            var qryParams = new Dictionary <string, string>();

            qryParams.Add("RegistrationInstanceId", PageParameter("RegistrationInstanceId"));
            qryParams.Add("Tab", "4");
            NavigateToParentPage(qryParams);
        }
Example #8
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            EventItemOccurrence eventItemOccurrence = null;

            using (var rockContext = new RockContext())
            {
                bool newItem = false;
                var  eventItemOccurrenceService         = new EventItemOccurrenceService(rockContext);
                var  eventItemOccurrenceGroupMapService = new EventItemOccurrenceGroupMapService(rockContext);
                var  registrationInstanceService        = new RegistrationInstanceService(rockContext);
                var  scheduleService = new ScheduleService(rockContext);

                int eventItemOccurrenceId = hfEventItemOccurrenceId.ValueAsInt();
                if (eventItemOccurrenceId != 0)
                {
                    eventItemOccurrence = eventItemOccurrenceService
                                          .Queryable("Linkages")
                                          .Where(i => i.Id == eventItemOccurrenceId)
                                          .FirstOrDefault();
                }

                if (eventItemOccurrence == null)
                {
                    newItem             = true;
                    eventItemOccurrence = new EventItemOccurrence {
                        EventItemId = PageParameter("EventItemId").AsInteger()
                    };
                    eventItemOccurrenceService.Add(eventItemOccurrence);
                }

                int?newCampusId = ddlCampus.SelectedValueAsInt();
                if (eventItemOccurrence.CampusId != newCampusId)
                {
                    eventItemOccurrence.CampusId = newCampusId;
                    if (newCampusId.HasValue)
                    {
                        var campus = new CampusService(rockContext).Get(newCampusId.Value);
                        eventItemOccurrence.Campus = campus;
                    }
                    else
                    {
                        eventItemOccurrence.Campus = null;
                    }
                }

                eventItemOccurrence.Location = tbLocation.Text;

                string iCalendarContent = sbSchedule.iCalendarContent;
                var    calEvent         = ScheduleICalHelper.GetCalenderEvent(iCalendarContent);
                if (calEvent != null && calEvent.DTStart != null)
                {
                    if (eventItemOccurrence.Schedule == null)
                    {
                        eventItemOccurrence.Schedule = new Schedule();
                    }
                    eventItemOccurrence.Schedule.iCalendarContent = iCalendarContent;
                }
                else
                {
                    if (eventItemOccurrence.ScheduleId.HasValue)
                    {
                        var oldSchedule = scheduleService.Get(eventItemOccurrence.ScheduleId.Value);
                        if (oldSchedule != null)
                        {
                            scheduleService.Delete(oldSchedule);
                        }
                    }
                }

                if (!eventItemOccurrence.ContactPersonAliasId.Equals(ppContact.PersonAliasId))
                {
                    PersonAlias personAlias = null;
                    eventItemOccurrence.ContactPersonAliasId = ppContact.PersonAliasId;
                    if (eventItemOccurrence.ContactPersonAliasId.HasValue)
                    {
                        personAlias = new PersonAliasService(rockContext).Get(eventItemOccurrence.ContactPersonAliasId.Value);
                    }

                    if (personAlias != null)
                    {
                        eventItemOccurrence.ContactPersonAlias = personAlias;
                    }
                }

                eventItemOccurrence.ContactPhone = PhoneNumber.FormattedNumber(PhoneNumber.DefaultCountryCode(), pnPhone.Number);
                eventItemOccurrence.ContactEmail = tbEmail.Text;
                eventItemOccurrence.Note         = htmlOccurrenceNote.Text;

                // Remove any linkage no longer in UI
                Guid uiLinkageGuid = LinkageState != null ? LinkageState.Guid : Guid.Empty;
                foreach (var linkage in eventItemOccurrence.Linkages.Where(l => !l.Guid.Equals(uiLinkageGuid)).ToList())
                {
                    eventItemOccurrence.Linkages.Remove(linkage);
                    eventItemOccurrenceGroupMapService.Delete(linkage);
                }

                // Add/Update linkage in UI
                if (!uiLinkageGuid.Equals(Guid.Empty))
                {
                    var linkage = eventItemOccurrence.Linkages.Where(l => l.Guid.Equals(uiLinkageGuid)).FirstOrDefault();
                    if (linkage == null)
                    {
                        linkage = new EventItemOccurrenceGroupMap();
                        eventItemOccurrence.Linkages.Add(linkage);
                    }
                    linkage.CopyPropertiesFrom(LinkageState);

                    // update registration instance
                    if (LinkageState.RegistrationInstance != null)
                    {
                        if (LinkageState.RegistrationInstance.Id != 0)
                        {
                            linkage.RegistrationInstance = registrationInstanceService.Get(LinkageState.RegistrationInstance.Id);
                        }

                        if (linkage.RegistrationInstance == null)
                        {
                            var registrationInstance = new RegistrationInstance();
                            registrationInstanceService.Add(registrationInstance);
                            linkage.RegistrationInstance = registrationInstance;
                        }

                        linkage.RegistrationInstance.CopyPropertiesFrom(LinkageState.RegistrationInstance);
                    }
                }

                if (!Page.IsValid)
                {
                    return;
                }

                if (!eventItemOccurrence.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.SaveChanges();

                var qryParams = new Dictionary <string, string>();
                qryParams.Add("EventCalendarId", PageParameter("EventCalendarId"));
                qryParams.Add("EventItemId", PageParameter("EventItemId"));

                if (newItem)
                {
                    NavigateToParentPage(qryParams);
                }
                else
                {
                    qryParams.Add("EventItemOccurrenceId", eventItemOccurrence.Id.ToString());
                    NavigateToPage(RockPage.Guid, qryParams);
                }
            }
        }
        protected void lbRegister_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            // get the person who was passed in for the registration registrar
            Person person = null;

            Guid personGuid = Guid.Empty;

            if (Request["PersonGuid"] != null)
            {
                personGuid = Request["PersonGuid"].AsGuid();

                person = new PersonService(_rockContext).Get(personGuid);
            }

            if (person == null)
            {
                lErrors.Text = "<div class='alert alert-warning'>Invalid person guid was passed.</div>";
                return;
            }

            // get event item
            int eventItemOccurrenceId = hfSelectedEventId.Value.AsInteger();

            // find registration
            var eventGroup = new EventItemOccurrenceGroupMapService(_rockContext).Queryable()
                             .Where(m => m.EventItemOccurrenceId == eventItemOccurrenceId)
                             .Select(m => m.Group)
                             .FirstOrDefault();

            var registrationLinkages = eventGroup.Linkages.ToList();


            if (registrationLinkages.Count() == 0)
            {
                lErrors.Text = "<div class='alert alert-warning'>No registration instances exists for this event.</div>";
                return;
            }

            EventItemOccurrenceGroupMap registrationLinkage = registrationLinkages.First();

            // create new registration
            var registrationService = new RegistrationService(rockContext);

            Registration registration = new Registration();

            registrationService.Add(registration);

            registration.RegistrationInstanceId = registrationLinkage.RegistrationInstanceId.Value;
            registration.ConfirmationEmail      = ebEmailReminder.Text;
            registration.PersonAliasId          = person.PrimaryAliasId;
            registration.FirstName   = person.NickName;
            registration.LastName    = person.LastName;
            registration.IsTemporary = true;

            // add registrants
            foreach (int registrantId in cblRegistrants.SelectedValuesAsInt)
            {
                RegistrationRegistrant registrant = new RegistrationRegistrant();
                registrant.PersonAliasId = registrantId;
                registration.Registrants.Add(registrant);
            }

            rockContext.SaveChanges();

            // redirect to registration page
            var queryParams = new Dictionary <string, string>();

            queryParams.Add("RegistrationInstanceId", registrationLinkage.RegistrationInstanceId.ToString());
            queryParams.Add("RegistrationId", registration.Id.ToString());
            queryParams.Add("StartAtBeginning", GetAttributeValue("StartRegistrationAtBeginning"));

            if (!string.IsNullOrWhiteSpace(registrationLinkage.UrlSlug))
            {
                queryParams.Add("Slug", registrationLinkage.UrlSlug);
            }

            if (registrationLinkage.Group != null)
            {
                queryParams.Add("GroupId", registrationLinkage.GroupId.ToString());
            }

            NavigateToLinkedPage("RegistrationPage", queryParams);
        }
        private void ShowEditDetails( EventItemOccurrence eventItemOccurrence )
        {
            LinkageState = new EventItemOccurrenceGroupMap { Guid = Guid.Empty };

            if ( eventItemOccurrence == null )
            {
                eventItemOccurrence = new EventItemOccurrence();
            }

            if ( eventItemOccurrence.Id == 0 )
            {
                lActionTitle.Text = ActionTitle.Add( "Event Occurrence" ).FormatAsHtmlTitle();

                var copyFromOccurrenceId = PageParameter( "CopyFromId" ).AsInteger();
                if ( copyFromOccurrenceId > 0 )
                {
                    var oldOccurrence = new EventItemOccurrenceService( new RockContext() ).Get( copyFromOccurrenceId );
                    if ( oldOccurrence != null )
                    {
                        // clone the workflow type
                        eventItemOccurrence = oldOccurrence.Clone( false );
                        eventItemOccurrence.Schedule = oldOccurrence.Schedule;
                        eventItemOccurrence.EventItem = oldOccurrence.EventItem;
                        eventItemOccurrence.ContactPersonAlias = oldOccurrence.ContactPersonAlias;
                        eventItemOccurrence.CreatedByPersonAlias = null;
                        eventItemOccurrence.CreatedByPersonAliasId = null;
                        eventItemOccurrence.CreatedDateTime = RockDateTime.Now;
                        eventItemOccurrence.ModifiedByPersonAlias = null;
                        eventItemOccurrence.ModifiedByPersonAliasId = null;
                        eventItemOccurrence.ModifiedDateTime = RockDateTime.Now;
                        eventItemOccurrence.Id = 0;
                        eventItemOccurrence.Guid = Guid.NewGuid();

                        // Clone the linkage
                        var linkage = oldOccurrence.Linkages.FirstOrDefault();
                        if ( linkage != null )
                        {
                            LinkageState = linkage.Clone( false );
                            LinkageState.EventItemOccurrenceId = 0;
                            LinkageState.CreatedByPersonAlias = null;
                            LinkageState.CreatedByPersonAliasId = null;
                            LinkageState.CreatedDateTime = RockDateTime.Now;
                            LinkageState.ModifiedByPersonAlias = null;
                            LinkageState.ModifiedByPersonAliasId = null;
                            LinkageState.ModifiedDateTime = RockDateTime.Now;
                            LinkageState.Id = 0;
                            LinkageState.Guid = Guid.NewGuid();
                            LinkageState.RegistrationInstance = linkage.RegistrationInstance != null ? linkage.RegistrationInstance.Clone( false ) : new RegistrationInstance();
                            LinkageState.RegistrationInstance.RegistrationTemplate =
                                linkage.RegistrationInstance != null && linkage.RegistrationInstance.RegistrationTemplate != null ?
                                linkage.RegistrationInstance.RegistrationTemplate.Clone( false ) : new RegistrationTemplate();
                            LinkageState.Group = linkage.Group != null ? linkage.Group.Clone( false ) : new Group();
                        }
                    }
                }
            }
            else
            {
                lActionTitle.Text = ActionTitle.Edit( "Event Occurrence" ).FormatAsHtmlTitle();

                var registration = eventItemOccurrence.Linkages.FirstOrDefault();
                if ( registration != null )
                {
                    LinkageState = registration.Clone( false );
                    LinkageState.RegistrationInstance = registration.RegistrationInstance != null ? registration.RegistrationInstance.Clone( false ) : new RegistrationInstance();
                    LinkageState.RegistrationInstance.RegistrationTemplate =
                        registration.RegistrationInstance != null && registration.RegistrationInstance.RegistrationTemplate != null ?
                        registration.RegistrationInstance.RegistrationTemplate.Clone( false ) : new RegistrationTemplate();
                    LinkageState.Group = registration.Group != null ? registration.Group.Clone( false ) : new Group();
                }
            }

            SetEditMode( true );

            hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString();

            ddlCampus.SetValue( eventItemOccurrence.CampusId ?? -1 );
            tbLocation.Text = eventItemOccurrence.Location;

            if ( eventItemOccurrence.Schedule != null )
            {
                sbSchedule.iCalendarContent = eventItemOccurrence.Schedule.iCalendarContent;
                lScheduleText.Text = eventItemOccurrence.Schedule.FriendlyScheduleText;
            }
            else
            {
                sbSchedule.iCalendarContent = string.Empty;
                lScheduleText.Text = string.Empty;
            }

            ppContact.SetValue( eventItemOccurrence.ContactPersonAlias != null ? eventItemOccurrence.ContactPersonAlias.Person : null );
            pnPhone.Text = eventItemOccurrence.ContactPhone;
            tbEmail.Text = eventItemOccurrence.ContactEmail;

            htmlOccurrenceNote.Text = eventItemOccurrence.Note;

            DisplayRegistration();
        }
        /// <summary>
        /// Restores the view-state information from a previous user control request that was saved by the <see cref="M:System.Web.UI.UserControl.SaveViewState" /> method.
        /// </summary>
        /// <param name="savedState">An <see cref="T:System.Object" /> that represents the user control state to be restored.</param>
        protected override void LoadViewState( object savedState )
        {
            base.LoadViewState( savedState );

            string json = ViewState["LinkageState"] as string;
            if ( string.IsNullOrWhiteSpace( json ) )
            {
                LinkageState = new EventItemOccurrenceGroupMap();
            }
            else
            {
                LinkageState = JsonConvert.DeserializeObject<EventItemOccurrenceGroupMap>( json );
            }
        }
 /// <summary>
 /// Handles the Click event of the lbLinkToExistingRegistration control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 protected void lbLinkToExistingRegistration_Click( object sender, EventArgs e )
 {
     LinkageState = new EventItemOccurrenceGroupMap { Guid = Guid.Empty };
     ShowExistingLinkageDialog();
 }
 /// <summary>
 /// Handles the Click event of the lbDeleteRegistration control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 protected void lbDeleteRegistration_Click( object sender, EventArgs e )
 {
     LinkageState = new EventItemOccurrenceGroupMap { Guid = Guid.Empty };
     DisplayRegistration();
 }
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click( object sender, EventArgs e )
        {
            EventItemOccurrence eventItemOccurrence = null;

            using ( var rockContext = new RockContext() )
            {
                bool newItem = false;
                var eventItemOccurrenceService = new EventItemOccurrenceService( rockContext );
                var eventItemOccurrenceGroupMapService = new EventItemOccurrenceGroupMapService( rockContext );
                var registrationInstanceService = new RegistrationInstanceService( rockContext );
                var scheduleService = new ScheduleService( rockContext );

                int eventItemOccurrenceId = hfEventItemOccurrenceId.ValueAsInt();
                if ( eventItemOccurrenceId != 0 )
                {
                    eventItemOccurrence = eventItemOccurrenceService
                        .Queryable( "Linkages" )
                        .Where( i => i.Id == eventItemOccurrenceId )
                        .FirstOrDefault();
                }

                if ( eventItemOccurrence == null )
                {
                    newItem = true;
                    eventItemOccurrence = new EventItemOccurrence{ EventItemId = PageParameter("EventItemId").AsInteger() };
                    eventItemOccurrenceService.Add( eventItemOccurrence );
                }

                int? newCampusId = ddlCampus.SelectedValueAsInt();
                if ( eventItemOccurrence.CampusId != newCampusId )
                {
                    eventItemOccurrence.CampusId = newCampusId;
                    if ( newCampusId.HasValue )
                    {
                        var campus = new CampusService( rockContext ).Get( newCampusId.Value );
                        eventItemOccurrence.Campus = campus;
                    }
                    else
                    {
                        eventItemOccurrence.Campus = null;
                    }
                }

                eventItemOccurrence.Location = tbLocation.Text;

                string iCalendarContent = sbSchedule.iCalendarContent;
                var calEvent = ScheduleICalHelper.GetCalenderEvent( iCalendarContent );
                if ( calEvent != null && calEvent.DTStart != null )
                {
                    if ( eventItemOccurrence.Schedule == null )
                    {
                        eventItemOccurrence.Schedule = new Schedule();
                    }
                    eventItemOccurrence.Schedule.iCalendarContent = iCalendarContent;
                }
                else
                {
                    if ( eventItemOccurrence.ScheduleId.HasValue )
                    {
                        var oldSchedule = scheduleService.Get( eventItemOccurrence.ScheduleId.Value );
                        if ( oldSchedule != null )
                        {
                            scheduleService.Delete( oldSchedule );
                        }
                    }
                }

                if ( !eventItemOccurrence.ContactPersonAliasId.Equals( ppContact.PersonAliasId ))
                {
                    PersonAlias personAlias = null;
                    eventItemOccurrence.ContactPersonAliasId = ppContact.PersonAliasId;
                    if ( eventItemOccurrence.ContactPersonAliasId.HasValue )
                    {
                        personAlias = new PersonAliasService( rockContext ).Get( eventItemOccurrence.ContactPersonAliasId.Value );
                    }

                    if ( personAlias != null )
                    {
                        eventItemOccurrence.ContactPersonAlias = personAlias;
                    }
                }

                eventItemOccurrence.ContactPhone = PhoneNumber.FormattedNumber( PhoneNumber.DefaultCountryCode(), pnPhone.Number );
                eventItemOccurrence.ContactEmail = tbEmail.Text;
                eventItemOccurrence.Note = htmlOccurrenceNote.Text;

                // Remove any linkage no longer in UI
                Guid uiLinkageGuid = LinkageState != null ? LinkageState.Guid : Guid.Empty;
                foreach( var linkage in eventItemOccurrence.Linkages.Where( l => !l.Guid.Equals(uiLinkageGuid)).ToList())
                {
                    eventItemOccurrence.Linkages.Remove( linkage );
                    eventItemOccurrenceGroupMapService.Delete( linkage );
                }

                // Add/Update linkage in UI
                if ( !uiLinkageGuid.Equals( Guid.Empty ))
                {
                    var linkage = eventItemOccurrence.Linkages.Where( l => l.Guid.Equals( uiLinkageGuid)).FirstOrDefault();
                    if ( linkage == null )
                    {
                        linkage = new EventItemOccurrenceGroupMap();
                        eventItemOccurrence.Linkages.Add( linkage );
                    }
                    linkage.CopyPropertiesFrom( LinkageState );

                    // update registration instance
                    if ( LinkageState.RegistrationInstance != null )
                    {
                        if ( LinkageState.RegistrationInstance.Id != 0 )
                        {
                            linkage.RegistrationInstance = registrationInstanceService.Get( LinkageState.RegistrationInstance.Id );
                        }

                        if ( linkage.RegistrationInstance == null )
                        {
                            var registrationInstance = new RegistrationInstance();
                            registrationInstanceService.Add( registrationInstance );
                            linkage.RegistrationInstance = registrationInstance;
                        }

                        linkage.RegistrationInstance.CopyPropertiesFrom( LinkageState.RegistrationInstance );
                    }

                }

                if ( !Page.IsValid )
                {
                    return;
                }

                if ( !eventItemOccurrence.IsValid )
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.SaveChanges();

                var qryParams = new Dictionary<string, string>();
                qryParams.Add( "EventCalendarId", PageParameter( "EventCalendarId" ) );
                qryParams.Add( "EventItemId", PageParameter( "EventItemId" ) );

                if ( newItem )
                {
                    NavigateToParentPage( qryParams );
                }
                else
                {
                    qryParams.Add( "EventItemOccurrenceId", eventItemOccurrence.Id.ToString() );
                    NavigateToPage( RockPage.Guid, qryParams );
                }
            }
        }
Example #15
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSave_Click( object sender, EventArgs e )
        {
            using ( var rockContext = new RockContext() )
            {
                var service = new EventItemOccurrenceGroupMapService( rockContext );

                EventItemOccurrenceGroupMap linkage = null;

                int? linkageId = hfLinkageId.Value.AsIntegerOrNull();
                if ( linkageId.HasValue )
                {
                    linkage = service.Get( linkageId.Value );
                }

                if ( linkage == null )
                {
                    linkage = new EventItemOccurrenceGroupMap();
                    linkage.RegistrationInstanceId = PageParameter( "RegistrationInstanceId" ).AsInteger();
                    service.Add( linkage );
                }

                linkage.EventItemOccurrenceId = hfLinkageEventItemOccurrenceId.Value.AsIntegerOrNull();
                linkage.GroupId = gpLinkageGroup.SelectedValueAsInt();
                linkage.PublicName = tbLinkagePublicName.Text;
                linkage.UrlSlug = tbLinkageUrlSlug.Text;

                if ( !Page.IsValid || !linkage.IsValid )
                {
                    return;
                }

                rockContext.SaveChanges();
            }

            var qryParams = new Dictionary<string, string>();
            qryParams.Add( "RegistrationInstanceId", PageParameter( "RegistrationInstanceId" ) );
            qryParams.Add( "Tab", "3" );
            NavigateToParentPage( qryParams );
        }
        private void ShowEditDetails( EventItemOccurrence eventItemOccurrence )
        {
            if ( eventItemOccurrence == null )
            {
                eventItemOccurrence = new EventItemOccurrence();
            }

            if ( eventItemOccurrence.Id == 0 )
            {
                lActionTitle.Text = ActionTitle.Add( "Event Occurrence" ).FormatAsHtmlTitle();
            }
            else
            {
                lActionTitle.Text = ActionTitle.Edit( "Event Occurrence" ).FormatAsHtmlTitle();
            }

            SetEditMode( true );

            hfEventItemOccurrenceId.Value = eventItemOccurrence.Id.ToString();

            ddlCampus.SetValue( eventItemOccurrence.CampusId ?? -1 );
            tbLocation.Text = eventItemOccurrence.Location;

            if ( eventItemOccurrence.Schedule != null )
            {
                sbSchedule.iCalendarContent = eventItemOccurrence.Schedule.iCalendarContent;
                lScheduleText.Text = eventItemOccurrence.Schedule.FriendlyScheduleText;
            }
            else
            {
                sbSchedule.iCalendarContent = string.Empty;
                lScheduleText.Text = string.Empty;
            }

            ppContact.SetValue( eventItemOccurrence.ContactPersonAlias != null ? eventItemOccurrence.ContactPersonAlias.Person : null );
            pnPhone.Text = eventItemOccurrence.ContactPhone;
            tbEmail.Text = eventItemOccurrence.ContactEmail;

            htmlOccurrenceNote.Text = eventItemOccurrence.Note;

            LinkageState = new EventItemOccurrenceGroupMap { Guid = Guid.Empty };
            var registration = eventItemOccurrence.Linkages.FirstOrDefault();
            if ( registration != null )
            {
                LinkageState = registration.Clone( false );
                LinkageState.RegistrationInstance = registration.RegistrationInstance != null ? registration.RegistrationInstance.Clone( false ) : new RegistrationInstance();
                LinkageState.RegistrationInstance.RegistrationTemplate =
                    registration.RegistrationInstance != null && registration.RegistrationInstance.RegistrationTemplate != null ?
                    registration.RegistrationInstance.RegistrationTemplate.Clone( false ) : new RegistrationTemplate();
                LinkageState.Group = registration.Group != null ? registration.Group.Clone( false ) : new Group();
            }

            DisplayRegistration();
        }