Rock.Model.DefinedValueService.GetByDefinedTypeId C# (CSharp) Méthode

GetByDefinedTypeId() public méthode

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.
Résultat IOrderedQueryable
        public IOrderedQueryable<DefinedValue> GetByDefinedTypeId( int definedTypeId )
        {
            return Queryable()
                .Where( t => t.DefinedTypeId == definedTypeId )
                .OrderBy( t => t.Order )
                .ThenBy( a => a.Value );
        }

Usage Example

        /// <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();
        }
All Usage Examples Of Rock.Model.DefinedValueService::GetByDefinedTypeId