Beispiel #1
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);
                }
            }
        }
Beispiel #2
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 RegistrationInstanceService( rockContext );

                RegistrationInstance instance = null;

                int? RegistrationInstanceId = hfRegistrationInstanceId.Value.AsIntegerOrNull();
                if ( RegistrationInstanceId.HasValue )
                {
                    instance = service.Get( RegistrationInstanceId.Value );
                }

                if ( instance == null )
                {
                    instance = new RegistrationInstance();
                    instance.RegistrationTemplateId = PageParameter( "RegistrationTemplateId" ).AsInteger();
                    service.Add( instance );
                }

                rieDetails.GetValue( instance );

                if ( !Page.IsValid )
                {
                    return;
                }

                rockContext.SaveChanges();

                // Reload instance and show readonly view
                instance = service.Get( instance.Id );
                ShowReadonlyDetails( instance );
            }
        }
        /// <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 );
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Adds any registration instances given in the XML file.
        /// </summary>
        /// <param name="elemRegistrationInstances"></param>
        /// <param name="rockContext"></param>
        private void AddRegistrationInstances( XElement elemRegistrationInstances, RockContext rockContext )
        {
            if ( elemRegistrationInstances == null )
            {
                return;
            }

            foreach ( var element in elemRegistrationInstances.Elements( "registrationInstance" ) )
            {
                // skip any illegally formatted items
                if ( element.Attribute( "templateGuid" ) == null )
                {
                    continue;
                }

                // Now find the matching registration template
                RegistrationInstanceService registrationInstanceService = new RegistrationInstanceService( rockContext );

                RegistrationTemplateService registrationTemplateService = new RegistrationTemplateService( rockContext );
                Guid templateGuid = element.Attribute( "templateGuid" ).Value.AsGuid();
                var registrationTemplate = registrationTemplateService.Queryable()
                    .Where( g => g.Guid == templateGuid )
                    .FirstOrDefault();

                if ( registrationTemplate == null )
                {
                    throw new NotSupportedException( string.Format( "unknown registration template: {0}", templateGuid ) );
                }

                // Merge lava fields
                // LAVA additionalReminderDetails
                Dictionary<string, object> mergeObjects = new Dictionary<string, object>();
                DateTime? registrationStartsDate = null;
                DateTime? registrationEndsDate = null;
                DateTime? sendReminderDate = null;
                var additionalReminderDetails = string.Empty;
                var additionalConfirmationDetails = string.Empty;

                if ( element.Attribute( "registrationStarts" ) != null )
                {
                    var y = element.Attribute( "registrationStarts" ).Value.ResolveMergeFields( mergeObjects );
                    registrationStartsDate = DateTime.Parse( y );
                }

                if ( element.Attribute( "registrationEnds" ) != null )
                {
                    registrationEndsDate = DateTime.Parse( element.Attribute( "registrationEnds" ).Value.ResolveMergeFields( mergeObjects ) );
                }

                if ( element.Attribute( "sendReminderDate" ) != null )
                {
                    sendReminderDate = DateTime.Parse( element.Attribute( "sendReminderDate" ).Value.ResolveMergeFields( mergeObjects ) );
                }

                if ( element.Attribute( "additionalReminderDetails" ) != null )
                {
                    additionalReminderDetails = element.Attribute( "additionalReminderDetails" ).Value;
                    additionalReminderDetails = additionalReminderDetails.ResolveMergeFields( mergeObjects );
                }

                if ( element.Attribute( "additionalConfirmationDetails" ) != null )
                {
                    additionalConfirmationDetails = element.Attribute( "additionalConfirmationDetails" ).Value;
                    additionalConfirmationDetails = additionalConfirmationDetails.ResolveMergeFields( mergeObjects );
                }

                // Get the contact info
                int? contactPersonAliasId = null;
                if ( element.Attribute( "contactPersonGuid" ) != null )
                {
                    var guid = element.Attribute( "contactPersonGuid" ).Value.AsGuid();
                    if ( _peopleAliasDictionary.ContainsKey( guid ) )
                    {
                        contactPersonAliasId = _peopleAliasDictionary[element.Attribute( "contactPersonGuid" ).Value.AsGuid()];
                    }
                }

                // Find the matching account
                FinancialAccountService financialGatewayService = new FinancialAccountService( rockContext );
                string accountName = element.Attribute( "account" ) != null ? element.Attribute( "account" ).Value : string.Empty;
                var account = financialGatewayService.Queryable()
                    .Where( g => g.Name == accountName )
                    .FirstOrDefault();

                RegistrationInstance registrationInstance = new RegistrationInstance()
                {
                    Guid = ( element.Attribute( "guid" ) != null ) ? element.Attribute( "guid" ).Value.Trim().AsGuid() : Guid.NewGuid(),
                    Name = ( element.Attribute( "name" ) != null ) ? element.Attribute( "name" ).Value.Trim() : "New " + registrationTemplate.Name,
                    IsActive = true,
                    RegistrationTemplateId = registrationTemplate.Id,
                    StartDateTime = registrationStartsDate,
                    EndDateTime = registrationEndsDate,
                    MaxAttendees = element.Attribute( "maxAttendees" ) != null ? element.Attribute( "maxAttendees" ).Value.AsInteger() : 0,
                    SendReminderDateTime = sendReminderDate,
                    ContactPersonAliasId = contactPersonAliasId,
                    ContactPhone = element.Attribute( "contactPhone" ) != null ? element.Attribute( "contactPhone" ).Value : string.Empty,
                    ContactEmail = element.Attribute( "contactEmail" ) != null ? element.Attribute( "contactEmail" ).Value : string.Empty,
                    AccountId = ( account != null ) ? (int?)account.Id : null,
                    AdditionalReminderDetails = HttpUtility.HtmlDecode( additionalReminderDetails ),
                    AdditionalConfirmationDetails = HttpUtility.HtmlDecode( additionalConfirmationDetails ),
                    CreatedDateTime = RockDateTime.Now,
                    ModifiedDateTime = RockDateTime.Now,
                };

                registrationInstanceService.Add( registrationInstance );
            }
        }
        /// <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 )
        {
            RegistrationInstance instance = null;

            bool newInstance = false;

            using ( var rockContext = new RockContext() )
            {
                var service = new RegistrationInstanceService( rockContext );

                int? RegistrationInstanceId = hfRegistrationInstanceId.Value.AsIntegerOrNull();
                if ( RegistrationInstanceId.HasValue )
                {
                    instance = service.Get( RegistrationInstanceId.Value );
                }

                if ( instance == null )
                {
                    instance = new RegistrationInstance();
                    instance.RegistrationTemplateId = PageParameter( "RegistrationTemplateId" ).AsInteger();
                    service.Add( instance );
                    newInstance = true;
                }

                rieDetails.GetValue( instance );

                if ( !Page.IsValid )
                {
                    return;
                }

                rockContext.SaveChanges();
            }

            if ( newInstance )
            {
                var qryParams = new Dictionary<string, string>();
                qryParams.Add( "RegistrationTemplateId", PageParameter( "RegistrationTemplateId" ) );
                qryParams.Add( "RegistrationInstanceId", instance.Id.ToString() );
                NavigateToCurrentPage( qryParams );
            }
            else
            {

                // Reload instance and show readonly view
                using ( var rockContext = new RockContext() )
                {
                    instance = new RegistrationInstanceService( rockContext ).Get( instance.Id );
                    ShowReadonlyDetails( instance );
                }

                // show send payment reminder link
                if ( !string.IsNullOrWhiteSpace( GetAttributeValue( "PaymentReminderPage" ) ) && ( ( instance.RegistrationTemplate.SetCostOnInstance.HasValue && instance.RegistrationTemplate.SetCostOnInstance == true && instance.Cost.HasValue && instance.Cost.Value > 0 ) || instance.RegistrationTemplate.Cost > 0 ) )
                {
                    btnSendPaymentReminder.Visible = true;
                }
                else
                {
                    btnSendPaymentReminder.Visible = false;
                }
            }
        }
Beispiel #6
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)
        {
            RegistrationInstance instance = null;

            bool newInstance = false;

            using (var rockContext = new RockContext())
            {
                var service = new RegistrationInstanceService(rockContext);

                int?registrationInstanceId = hfRegistrationInstanceId.Value.AsIntegerOrNull();
                if (registrationInstanceId.HasValue)
                {
                    instance = service.Get(registrationInstanceId.Value);
                }

                if (instance == null)
                {
                    instance = new RegistrationInstance();
                    instance.RegistrationTemplateId = PageParameter(PageParameterKey.RegistrationTemplateId).AsInteger();
                    service.Add(instance);
                    newInstance = true;
                }

                rieDetails.GetValue(instance);

                if (!Page.IsValid)
                {
                    return;
                }

                rockContext.SaveChanges();
            }

            if (newInstance)
            {
                var qryParams = new Dictionary <string, string>();
                qryParams.Add(PageParameterKey.RegistrationTemplateId, PageParameter(PageParameterKey.RegistrationTemplateId));
                qryParams.Add(PageParameterKey.RegistrationInstanceId, instance.Id.ToString());
                NavigateToCurrentPage(qryParams);
            }
            else
            {
                // Reload instance and show readonly view
                using (var rockContext = new RockContext())
                {
                    instance = new RegistrationInstanceService(rockContext).Get(instance.Id);
                    ShowReadonlyDetails(instance);

                    // show send payment reminder link
                    if (!string.IsNullOrWhiteSpace(GetAttributeValue(AttributeKey.PaymentReminderPage)) &&
                        ((instance.RegistrationTemplate.SetCostOnInstance.HasValue && instance.RegistrationTemplate.SetCostOnInstance == true && instance.Cost.HasValue && instance.Cost.Value > 0) ||
                         instance.RegistrationTemplate.Cost > 0 ||
                         instance.RegistrationTemplate.Fees.Count > 0))
                    {
                        btnSendPaymentReminder.Visible = true;
                    }
                    else
                    {
                        btnSendPaymentReminder.Visible = false;
                    }
                }
            }
        }