/// <summary>
        /// Handles the Delete event of the gDefinedType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gDefinedType_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            var definedValueService = new DefinedValueService( rockContext );
            var definedTypeService = new DefinedTypeService( rockContext );

            DefinedType type = definedTypeService.Get( e.RowKeyId );

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

                // if this DefinedType has DefinedValues, see if they can be deleted
                var definedValues = definedValueService.GetByDefinedTypeId( type.Id ).ToList();

                foreach ( var value in definedValues )
                {
                    if ( !definedValueService.CanDelete( value, out errorMessage ) )
                    {
                        mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }
                }

                foreach ( var value in definedValues )
                {
                    definedValueService.Delete( value );
                }

                definedTypeService.Delete( type );

                rockContext.SaveChanges();
            }

            gDefinedType_Bind();
        }
        /// <summary>
        /// Handles the Click event of the btnSaveType 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 btnSaveType_Click( object sender, EventArgs e )
        {
            var rockContext = new RockContext();

            DefinedType definedType = null;
            DefinedTypeService typeService = new DefinedTypeService( rockContext );

            int definedTypeId = hfDefinedTypeId.ValueAsInt();

            if ( definedTypeId == 0 )
            {
                definedType = new DefinedType();
                definedType.IsSystem = false;
                definedType.Order = 0;
                typeService.Add( definedType );
            }
            else
            {
                DefinedTypeCache.Flush( definedTypeId );
                definedType = typeService.Get( definedTypeId );
            }

            definedType.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
            definedType.Name = tbTypeName.Text;
            definedType.Category = tbTypeCategory.Text;
            definedType.Description = tbTypeDescription.Text;
            definedType.HelpText = tbHelpText.Text;

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

            rockContext.SaveChanges();

            var qryParams = new Dictionary<string, string>();
            qryParams["definedTypeId"] = definedType.Id.ToString();
            NavigateToPage( RockPage.Guid, qryParams );
        }
 /// <summary>
 /// Handles the Click event of the btnEdit 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 btnEdit_Click( object sender, EventArgs e )
 {
     DefinedTypeService definedTypeService = new DefinedTypeService( new RockContext() );
     DefinedType definedType = definedTypeService.Get( hfDefinedTypeId.ValueAsInt() );
     ShowEditDetails( definedType );
 }
        /// <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 )
        {
            RockContext rockContext = new RockContext();
            DefinedTypeService definedTypeService = new DefinedTypeService( rockContext );
            DefinedType definedType = definedTypeService.Get( int.Parse( hfDefinedTypeId.Value ) );

            if ( definedType != null )
            {
                if ( !definedType.IsAuthorized( Authorization.EDIT, this.CurrentPerson ) )
                {
                    mdDeleteWarning.Show( "Sorry, You are not authorized to delete this Defined Type.", ModalAlertType.Information );
                    return;
                }

                string errorMessage;
                if ( !definedTypeService.CanDelete( definedType, out errorMessage ) )
                {
                    mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                definedTypeService.Delete( definedType );

                rockContext.SaveChanges();

            }

            NavigateToParentPage();
        }
 /// <summary>
 /// Handles the Click event of the btnCancelType 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 btnCancelType_Click( object sender, EventArgs e )
 {
     if ( hfDefinedTypeId.IsZero() )
     {
         // Cancelling on Add.  Return to Grid
         NavigateToParentPage();
     }
     else
     {
         // Cancelling on Edit.  Return to Details
         DefinedTypeService definedTypeService = new DefinedTypeService(new RockContext());
         DefinedType definedType = definedTypeService.Get( hfDefinedTypeId.ValueAsInt() );
         ShowReadonlyDetails( definedType );
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Process all the data in the XML file; deleting stuff and then adding stuff.
        /// as per https://github.com/SparkDevNetwork/Rock/wiki/z.-Rock-Solid-Demo-Church-Specification#wiki-xml-data
        /// </summary>
        /// <param name="sampleXmlFile"></param>
        private void ProcessXml( string sampleXmlFile )
        {
            var xdoc = XDocument.Load( sampleXmlFile );

            RockContext rockContext = new RockContext();
            rockContext.Configuration.AutoDetectChangesEnabled = false;

            DefinedTypeService definedTypeService = new DefinedTypeService( rockContext );
            _maritalStatusDefinedType = definedTypeService.Get( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS.AsGuid() );
            _smallGroupTopicDefinedType = definedTypeService.Get( Rock.SystemGuid.DefinedType.SMALL_GROUP_TOPIC.AsGuid() );
            _recordStatusReasonDefinedType = definedTypeService.Get( Rock.SystemGuid.DefinedType.PERSON_RECORD_STATUS_REASON.AsGuid() );
            _suffixDefinedType = definedTypeService.Get( Rock.SystemGuid.DefinedType.PERSON_SUFFIX.AsGuid() );

            var elemFamilies = xdoc.Element( "data" ).Element( "families" );
            var elemGroups = xdoc.Element( "data" ).Element( "groups" );
            var elemRelationships = xdoc.Element( "data" ).Element( "relationships" );
            var elemConnections = xdoc.Element( "data" ).Element( "connections" );
            var elemFollowing = xdoc.Element( "data" ).Element( "following" );
            var elemSecurityGroups = xdoc.Element( "data" ).Element( "securityRoles" );
            var elemRegistrationTemplates = xdoc.Element( "data" ).Element( "registrationTemplates" );
            var elemRegistrationInstances = xdoc.Element( "data" ).Element( "registrationInstances" );

            TimeSpan ts;

            //// First delete any sample data that might exist already
            // using RockContext in case there are multiple saves (like Attributes)
            rockContext.WrapTransaction( () =>
            {
                _stopwatch.Start();
                AppendFormat( "00:00.00 started <br/>" );

                // Delete this stuff that might have people attached to it
                DeleteRegistrationTemplates( elemRegistrationTemplates, rockContext );

                // Now we'll clean up by deleting any previously created data such as
                // families, addresses, people, photos, attendance data, etc.
                DeleteExistingGroups( elemGroups, rockContext );
                DeleteExistingFamilyData( elemFamilies, rockContext );

                //rockContext.ChangeTracker.DetectChanges();
                //rockContext.SaveChanges( disablePrePostProcessing: true );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} data deleted <br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );
            } );

            // make sure the database auth MEF component is initialized in case it hasn't done its first Load/Save Attributes yet (prevents possible lockup)
            var authenticationComponent = Rock.Security.AuthenticationContainer.GetComponent( EntityTypeCache.Read(_authenticationDatabaseEntityTypeId).Name );

            // Import the sample data
            // using RockContext in case there are multiple saves (like Attributes)
            rockContext.WrapTransaction( () =>
            {
                // Now we can add the families (and people) and then groups.
                AddFamilies( elemFamilies, rockContext );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} families added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                AddRelationships( elemRelationships, rockContext );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} relationships added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                AddGroups( elemGroups, rockContext );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} groups added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                AddConnections( elemConnections, rockContext );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} people connection requests added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                AddFollowing( elemFollowing, rockContext );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} people following added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                AddToSecurityGroups( elemSecurityGroups, rockContext );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} people added to security roles<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                // Add Registration Templates
                AddRegistrationTemplates( elemRegistrationTemplates, rockContext );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} registration templates added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                // Add Registration Instances
                AddRegistrationInstances( elemRegistrationInstances, rockContext );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} registration instances added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                rockContext.ChangeTracker.DetectChanges();
                rockContext.SaveChanges( disablePrePostProcessing: true );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} changes saved<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                // add logins, but only if we were supplied a password
                if ( !string.IsNullOrEmpty( tbPassword.Text.Trim() ) )
                {
                    AddPersonLogins( rockContext );
                    ts = _stopwatch.Elapsed;
                    AppendFormat( "{0:00}:{1:00}.{2:00} person logins added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );
                }

                // Add Person Notes
                AddPersonNotes( elemFamilies, rockContext );
                rockContext.SaveChanges( disablePrePostProcessing: true );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} notes added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                // Add Person Previous LastNames
                AddPeoplesPreviousNames( elemFamilies, rockContext );
                rockContext.SaveChanges( disablePrePostProcessing: true );
                ts = _stopwatch.Elapsed;
                AppendFormat( "{0:00}:{1:00}.{2:00} previous names added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

                // Add Person Metaphone/Sounds-like stuff
                AddMetaphone();

            } );

            // done.
            ts = _stopwatch.Elapsed;
            AppendFormat( "{0:00}:{1:00}.{2:00} done.<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );

            if ( GetAttributeValue( "EnableStopwatch" ).AsBoolean() )
            {
                lStopwatchLog.Text = _sb.ToString();
            }

            // Clear the static objects that contains all security roles and auth rules (so that it will be refreshed)
            foreach ( var role in Rock.Security.Role.AllRoles() )
            {
                Rock.Security.Role.Flush(role.Id);
            }

            Rock.Security.Authorization.Flush();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Handles the Delete event of the gDefinedType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gDefinedType_Delete( object sender, RowEventArgs e )
        {
            var definedValueService = new DefinedValueService();
            var definedTypeService = new DefinedTypeService();

            DefinedType type = definedTypeService.Get( e.RowKeyId );

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

                // if this DefinedType has DefinedValues, see if they can be deleted
                var definedValues = definedValueService.GetByDefinedTypeId( type.Id ).ToList();

                foreach ( var value in definedValues )
                {
                    if ( !definedValueService.CanDelete( value, out errorMessage ) )
                    {
                        mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }
                }

                RockTransactionScope.WrapTransaction( () =>
                {
                    foreach ( var value in definedValues )
                    {
                        definedValueService.Delete( value, CurrentPersonId );
                        definedValueService.Save( value, CurrentPersonId );
                    }

                    definedTypeService.Delete( type, CurrentPersonId );
                    definedTypeService.Save( type, CurrentPersonId );
                } );
            }

            gDefinedType_Bind();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Handles the Click event of the btnSaveType 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 btnSaveType_Click( object sender, EventArgs e )
        {
            DefinedType definedType = null;
            DefinedTypeService typeService = new DefinedTypeService();

            int definedTypeId = hfDefinedTypeId.ValueAsInt();

            if ( definedTypeId == 0 )
            {
                definedType = new DefinedType();
                definedType.IsSystem = false;
                definedType.Order = 0;
                typeService.Add( definedType, CurrentPersonId );
            }
            else
            {
                DefinedTypeCache.Flush( definedTypeId );
                definedType = typeService.Get( definedTypeId );
            }

            definedType.Name = tbTypeName.Text;
            definedType.Category = tbTypeCategory.Text;
            definedType.Description = tbTypeDescription.Text;
            definedType.FieldTypeId = int.Parse( ddlTypeFieldType.SelectedValue );

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

            RockTransactionScope.WrapTransaction( () =>
            {
                typeService.Save( definedType, CurrentPersonId );

                // get it back to make sure we have a good Id
                definedType = typeService.Get( definedType.Guid );
            } );

            var qryParams = new Dictionary<string, string>();
            qryParams["definedTypeId"] = definedType.Id.ToString();
            NavigateToPage( RockPage.Guid, qryParams );
        }
Ejemplo n.º 9
0
        protected void btnSaveType_Click( object sender, EventArgs e )
        {
            using ( new Rock.Data.UnitOfWorkScope() )
            {
                DefinedTypeService typeService = new DefinedTypeService();

                DefinedType definedType;

                int typeId = (( hfIdType.Value ) != null && hfIdType.Value != String.Empty ) ? Int32.Parse( hfIdType.Value ) : 0;

                if ( typeId == 0 )
                {
                    definedType = new DefinedType();
                    definedType.IsSystem = false;
                    definedType.Order = 0;
                    typeService.Add( definedType, CurrentPersonId );
                }
                else
                {
                    Rock.Web.Cache.DefinedTypeCache.Flush( typeId );
                    definedType = typeService.Get( typeId );
                }

                definedType.Name = tbTypeName.Text;
                definedType.Category = tbTypeCategory.Text;
                definedType.Description = tbTypeDescription.Text;
                definedType.FieldTypeId = Int32.Parse( ddlTypeFieldType.SelectedValue );

                typeService.Save( definedType, CurrentPersonId );
            }

            rGridType_Bind();

            pnlTypeDetails.Visible = false;
            pnlTypes.Visible = true;
        }