GetByDefinedTypeId() public method

Returns an enumerable collection of Rock.Model.DefinedValue">DefinedValues that belong to a specified
public GetByDefinedTypeId ( int definedTypeId ) : IOrderedQueryable
definedTypeId int A representing the DefinedTypeId of the to retrieve DefinedValues for.
return IOrderedQueryable
        /// <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();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the control(s) neccessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl( Dictionary<string, ConfigurationValue> configurationValues, string id )
        {
            ListControl editControl;

            if ( configurationValues != null && configurationValues.ContainsKey( ALLOW_MULTIPLE_KEY ) && configurationValues[ ALLOW_MULTIPLE_KEY ].Value.AsBoolean() )
            {
                editControl = new Rock.Web.UI.Controls.RockCheckBoxList { ID = id }; 
                editControl.AddCssClass( "checkboxlist-group" );
            }
            else
            {
                editControl = new Rock.Web.UI.Controls.RockDropDownList { ID = id }; 
                editControl.Items.Add( new ListItem() );
            }

            if ( configurationValues != null && configurationValues.ContainsKey( DEFINED_TYPE_KEY ) )
            {
                int definedTypeId = 0;
                if ( Int32.TryParse( configurationValues[DEFINED_TYPE_KEY].Value, out definedTypeId ) )
                {
                    Rock.Model.DefinedValueService definedValueService = new Model.DefinedValueService();
                    foreach ( var definedValue in definedValueService.GetByDefinedTypeId( definedTypeId ) )
                    {
                        editControl.Items.Add( new ListItem( definedValue.Name, definedValue.Id.ToString() ) );
                    }
                }
            }
            
            return editControl;
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the Delete event of the rGridType 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 rGridType_Delete( object sender, RowEventArgs e )
        {
            DefinedType type = new DefinedTypeService().Get( (int)rGridType.DataKeys[e.RowIndex]["id"] );

            var valueService = new DefinedValueService();
            var typeService = new DefinedTypeService();

            if ( type != null )
            {
                // if this DefinedType has DefinedValues, delete them
                var hasDefinedValues = valueService
                .GetByDefinedTypeId( type.Id )
                .ToList();

                foreach ( var value in hasDefinedValues )
                {
                    valueService.Delete( value, CurrentPersonId );
                    valueService.Save( value, CurrentPersonId );
                }

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

            rGridType_Bind();
        }