Exemple #1
0
        /// <summary>
        /// Handles the Click event of the btnCancel 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 btnCancel_Click(object sender, EventArgs e)
        {
            if (hfRegistrationInstanceId.Value.Equals("0"))
            {
                var qryParams = new Dictionary <string, string>();

                int?parentTemplateId = PageParameter(PageParameterKey.RegistrationTemplateId).AsIntegerOrNull();
                if (parentTemplateId.HasValue)
                {
                    qryParams[PageParameterKey.RegistrationTemplateId] = parentTemplateId.ToString();
                }

                // Cancelling on Add.  Return to Grid
                NavigateToParentPage(qryParams);
            }
            else
            {
                // Cancelling on Edit.  Return to Details
                using (var rockContext = new RockContext())
                {
                    RegistrationInstanceService service = new RegistrationInstanceService(rockContext);
                    RegistrationInstance        item    = service.Get(int.Parse(hfRegistrationInstanceId.Value));
                    ShowReadonlyDetails(item);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Handles the Click event of the DeleteInstance control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
        protected void DeleteInstance_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            RockContext rockContext = new RockContext();
            RegistrationInstanceService instanceService = new RegistrationInstanceService(rockContext);
            RegistrationInstance        instance        = instanceService.Get(e.RowKeyId);

            if (instance != null)
            {
                string errorMessage;
                if (!instanceService.CanDelete(instance, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    new RegistrationService(rockContext).DeleteRange(instance.Registrations);
                    instanceService.Delete(instance);
                    rockContext.SaveChanges();
                });
            }

            BindInstancesGrid();
        }
Exemple #3
0
        /// <summary>
        /// Handles the Click event of the btnDelete 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 btnDelete_Click(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                var service = new RegistrationInstanceService(rockContext);
                var registrationInstance = service.Get(hfRegistrationInstanceId.Value.AsInteger());

                if (registrationInstance != null)
                {
                    int registrationTemplateId = registrationInstance.RegistrationTemplateId;

                    if (UserCanEdit ||
                        registrationInstance.IsAuthorized(Authorization.EDIT, CurrentPerson) ||
                        registrationInstance.IsAuthorized(Authorization.ADMINISTRATE, this.CurrentPerson))
                    {
                        rockContext.WrapTransaction(() =>
                        {
                            new RegistrationService(rockContext).DeleteRange(registrationInstance.Registrations);
                            service.Delete(registrationInstance);
                            rockContext.SaveChanges();
                        });

                        var qryParams = new Dictionary <string, string> {
                            { PageParameterKey.RegistrationTemplateId, registrationTemplateId.ToString() }
                        };
                        NavigateToParentPage(qryParams);
                    }
                    else
                    {
                        mdDeleteWarning.Show("You are not authorized to delete this registration instance.", ModalAlertType.Information);
                        return;
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Handles the Click event of the lbTemplate 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 lbTemplate_Click(object sender, EventArgs e)
        {
            var qryParams = new Dictionary <string, string>();

            using (var rockContext = new RockContext())
            {
                var service = new RegistrationInstanceService(rockContext);
                var registrationInstance = service.Get(hfRegistrationInstanceId.Value.AsInteger());
                if (registrationInstance != null)
                {
                    qryParams.Add(PageParameterKey.RegistrationTemplateId, registrationInstance.RegistrationTemplateId.ToString());
                }
            }

            NavigateToParentPage(qryParams);
        }
Exemple #5
0
        public virtual HttpResponseMessage DetachPlacementGroup(int groupId, int registrationTemplatePlacementId, int?registrationInstanceId = null)
        {
            // since we are doing a delete, create a new RockContext instead of this.Service.Context so that ProxyCreation, etc works
            var rockContext = new RockContext();
            var group       = new GroupService(rockContext).Get(groupId);

            if (group == null)
            {
                return(ControllerContext.Request.CreateErrorResponse(
                           HttpStatusCode.NotFound,
                           $"Specified group not found."));
            }

            if (registrationInstanceId.HasValue)
            {
                var registrationInstanceService = new RegistrationInstanceService(rockContext);
                var registrationInstance        = registrationInstanceService.Get(registrationInstanceId.Value);

                if (registrationInstance == null)
                {
                    return(ControllerContext.Request.CreateErrorResponse(
                               HttpStatusCode.NotFound,
                               $"Specified registration instance not found."));
                }

                registrationInstanceService.DeleteRegistrationInstancePlacementGroup(registrationInstance, group);
            }
            else
            {
                var registrationTemplatePlacementService = new RegistrationTemplatePlacementService(rockContext);
                var registrationTemplatePlacement        = registrationTemplatePlacementService.Get(registrationTemplatePlacementId);

                if (registrationTemplatePlacement == null)
                {
                    return(ControllerContext.Request.CreateErrorResponse(
                               HttpStatusCode.NotFound,
                               $"Specified registration template placement not found."));
                }

                registrationTemplatePlacementService.DeleteRegistrationTemplatePlacementPlacementGroup(registrationTemplatePlacement, group);
            }

            rockContext.SaveChanges();

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
        /// <summary>
        /// Populates ddlFeeName with the name of the DDL fee.
        /// </summary>
        private void Populate_ddlFeeName()
        {
            int?instanceId = this.RegistrationInstanceId;

            if (instanceId.GetValueOrDefault(0) == 0)
            {
                return;
            }

            var rockContext = new RockContext();
            var registrationInstanceService = new RegistrationInstanceService(rockContext);
            var templateId = registrationInstanceService.Get(( int )instanceId).RegistrationTemplateId;

            var registrationTemplateFeeService = new RegistrationTemplateFeeService(new RockContext());
            var templateFees = registrationTemplateFeeService.Queryable().Where(f => f.RegistrationTemplateId == templateId).ToList();

            ddlFeeName.Items.Add(new ListItem());

            foreach (var templateFee in templateFees)
            {
                ddlFeeName.Items.Add(new ListItem(templateFee.Name, templateFee.Id.ToString()));
            }
        }
Exemple #7
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);
                }
            }
        }
Exemple #8
0
 protected void lbTemplate_Click( object sender, EventArgs e )
 {
     var qryParams = new Dictionary<string, string>();
     using ( var rockContext = new RockContext() )
     {
         var service = new RegistrationInstanceService( rockContext );
         var registrationInstance = service.Get( hfRegistrationInstanceId.Value.AsInteger() );
         if ( registrationInstance != null )
         {
             qryParams.Add( "RegistrationTemplateId", registrationInstance.RegistrationTemplateId.ToString() );
         }
     }
     NavigateToParentPage( qryParams );
 }
Exemple #9
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 );
            }
        }
Exemple #10
0
        /// <summary>
        /// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e )
        {
            using ( var rockContext = new RockContext() )
            {
                var service = new RegistrationInstanceService( rockContext );
                var registrationInstance = service.Get( hfRegistrationInstanceId.Value.AsInteger() );

                if ( registrationInstance != null )
                {
                    int registrationTemplateId = registrationInstance.RegistrationTemplateId;

                    if ( !registrationInstance.IsAuthorized( Authorization.ADMINISTRATE, this.CurrentPerson ) )
                    {
                        mdDeleteWarning.Show( "You are not authorized to delete this registration instance.", ModalAlertType.Information );
                        return;
                    }

                    rockContext.WrapTransaction( () =>
                    {
                        new RegistrationService( rockContext ).DeleteRange( registrationInstance.Registrations );
                        service.Delete( registrationInstance );
                        rockContext.SaveChanges();
                    } );

                    var qryParams = new Dictionary<string, string> { { "RegistrationTemplateId", registrationTemplateId.ToString() } };
                    NavigateToParentPage( qryParams );
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// Handles the Click event of the btnCancel 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 btnCancel_Click( object sender, EventArgs e )
        {
            if ( hfRegistrationInstanceId.Value.Equals( "0" ) )
            {
                var qryParams = new Dictionary<string, string>();

                int? parentTemplateId = PageParameter( "RegistrationTemplateId" ).AsIntegerOrNull();
                if ( parentTemplateId.HasValue )
                {
                    qryParams["RegistrationTemplateId"] = parentTemplateId.ToString();
                }

                // Cancelling on Add.  Return to Grid
                NavigateToParentPage( qryParams );
            }
            else
            {
                // Cancelling on Edit.  Return to Details
                using ( var rockContext = new RockContext() )
                {
                    RegistrationInstanceService service = new RegistrationInstanceService( rockContext );
                    RegistrationInstance item = service.Get( int.Parse( hfRegistrationInstanceId.Value ) );
                    ShowReadonlyDetails( item );
                }
            }
        }
Exemple #12
0
        /// <summary>
        /// Handles the Click event of the DeleteInstance control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
        protected void DeleteInstance_Click( object sender, Rock.Web.UI.Controls.RowEventArgs e )
        {
            RockContext rockContext = new RockContext();
            RegistrationInstanceService instanceService = new RegistrationInstanceService( rockContext );
            RegistrationInstance instance = instanceService.Get( e.RowKeyId );
            if ( instance != null )
            {
                string errorMessage;
                if ( !instanceService.CanDelete( instance, out errorMessage ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                rockContext.WrapTransaction( () =>
                {
                    new RegistrationService( rockContext ).DeleteRange( instance.Registrations );
                    instanceService.Delete( instance );
                    rockContext.SaveChanges();
                } );

            }

            BindInstancesGrid();
        }
        /// <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 );
                }
            }
        }
        /// <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;
                }
            }
        }
Exemple #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)
        {
            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;
                    }
                }
            }
        }