Service/Data Access class for Rock.Model.DefinedType entity objects.
예제 #1
0
        /// <summary>
        /// Loads the cache objects.
        /// </summary>
        private void LoadCacheObjects()
        {
            using (new Rock.Data.UnitOfWorkScope())
            {
                // Cache all the Field Types
                var fieldTypeService = new Rock.Model.FieldTypeService();
                foreach (var fieldType in fieldTypeService.Queryable().ToList())
                {
                    Rock.Web.Cache.FieldTypeCache.Read(fieldType);
                }

                // Cache all tha Defined Types
                var definedTypeService = new Rock.Model.DefinedTypeService();
                foreach (var definedType in definedTypeService.Queryable().ToList())
                {
                    Rock.Web.Cache.DefinedTypeCache.Read(definedType);
                }

                // Cache all the Defined Values
                var definedValueService = new Rock.Model.DefinedValueService();
                foreach (var definedValue in definedValueService.Queryable().ToList())
                {
                    Rock.Web.Cache.DefinedValueCache.Read(definedValue);
                }

                // Read all the qualifiers first so that EF doesn't perform a query for each attribute when it's cached
                var qualifiers = new Dictionary <int, Dictionary <string, string> >();
                foreach (var attributeQualifier in new Rock.Model.AttributeQualifierService().Queryable())
                {
                    if (!qualifiers.ContainsKey(attributeQualifier.AttributeId))
                    {
                        qualifiers.Add(attributeQualifier.AttributeId, new Dictionary <string, string>());
                    }
                    qualifiers[attributeQualifier.AttributeId].Add(attributeQualifier.Key, attributeQualifier.Value);
                }

                // Cache all the attributes.
                foreach (var attribute in new Rock.Model.AttributeService().Queryable().ToList())
                {
                    if (qualifiers.ContainsKey(attribute.Id))
                    {
                        Rock.Web.Cache.AttributeCache.Read(attribute, qualifiers[attribute.Id]);
                    }
                    else
                    {
                        Rock.Web.Cache.AttributeCache.Read(attribute, new Dictionary <string, string>());
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Loads the cache objects.
        /// </summary>
        private void LoadCacheObjects(RockContext rockContext)
        {
            // Read all the qualifiers first so that EF doesn't perform a query for each attribute when it's cached
            var qualifiers = new Dictionary <int, Dictionary <string, string> >();

            foreach (var attributeQualifier in new Rock.Model.AttributeQualifierService(rockContext).Queryable())
            {
                if (!qualifiers.ContainsKey(attributeQualifier.AttributeId))
                {
                    qualifiers.Add(attributeQualifier.AttributeId, new Dictionary <string, string>());
                }
                qualifiers[attributeQualifier.AttributeId].Add(attributeQualifier.Key, attributeQualifier.Value);
            }

            // Cache all the attributes.
            foreach (var attribute in new Rock.Model.AttributeService(rockContext).Queryable("Categories").ToList())
            {
                if (qualifiers.ContainsKey(attribute.Id))
                {
                    Rock.Web.Cache.AttributeCache.Read(attribute, qualifiers[attribute.Id]);
                }
                else
                {
                    Rock.Web.Cache.AttributeCache.Read(attribute, new Dictionary <string, string>());
                }
            }

            // Cache all the Field Types
            var all = Rock.Web.Cache.FieldTypeCache.All();

            // DT: When running with production CCV Data, this is taking a considerable amount of time

            // Cache all tha Defined Types
            var definedTypeService = new Rock.Model.DefinedTypeService(rockContext);

            foreach (var definedType in definedTypeService.Queryable().ToList())
            {
                Rock.Web.Cache.DefinedTypeCache.Read(definedType);
            }

            // Cache all the Defined Values
            var definedValueService = new Rock.Model.DefinedValueService(rockContext);

            foreach (var definedValue in definedValueService.Queryable().ToList())
            {
                Rock.Web.Cache.DefinedValueCache.Read(definedValue);
            }
        }
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed )
        {
            string formattedValue = string.Empty;

            Guid? guid = value.AsGuidOrNull();
            if (guid.HasValue)
            {
                var definedType = new DefinedTypeService( new RockContext() ).Get( guid.Value );
                if (definedType != null)
                { 
                    formattedValue = definedType.Name;
                }
            }

            return base.FormatValue( parentControl, formattedValue, configurationValues, condensed );
        }
예제 #4
0
        /// <summary>
        /// Creates the control(s) necessary 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 )
        {
            var editControl = new RockDropDownList { ID = id };
            editControl.Items.Add( new ListItem() );

            var definedTypes = new DefinedTypeService( new RockContext() ).Queryable().OrderBy( d => d.Name );
            if ( definedTypes.Any() )
            {
                foreach ( var definedType in definedTypes )
                {
                    editControl.Items.Add( new ListItem( definedType.Name, definedType.Guid.ToString().ToUpper() ) );
                }

                return editControl;
            }

            return null;
        }
        /// <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>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            ddlCategoryFilter.Items.Clear();
            ddlCategoryFilter.Items.Add( new ListItem( Rock.Constants.All.Text, string.Empty ) );

            var items = new DefinedTypeService( new RockContext() ).Queryable()
                .Where( a => a.Category != string.Empty)
                .OrderBy( a => a.Category )
                .Select( a => a.Category )
                .Distinct()
                .ToList();

            foreach ( var item in items )
            {
                ListItem li = new ListItem( item );
                li.Selected = ( !Page.IsPostBack && tFilter.GetUserPreference( "Category" ) == item );
                ddlCategoryFilter.Items.Add( li );
            }
        }
예제 #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();
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="definedTypeId">The defined type identifier.</param>
        public void ShowDetail( int definedTypeId )
        {
            pnlDetails.Visible = true;
            DefinedType definedType = null;

            if ( !definedTypeId.Equals( 0 ) )
            {
                definedType = new DefinedTypeService( new RockContext() ).Get( definedTypeId );
            }

            if ( definedType == null )
            {
                definedType = new DefinedType { Id = 0 };
            }

            hfDefinedTypeId.SetValue( definedType.Id );

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if ( _isStandAlone )
            {
                readOnly = true;
            }
            else
            {
                if ( !IsUserAuthorized( Authorization.EDIT ) )
                {
                    readOnly = true;
                    nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( DefinedType.FriendlyTypeName );
                }

                if ( definedType.IsSystem )
                {
                    readOnly = true;
                    nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( DefinedType.FriendlyTypeName );
                }
            }

            if ( readOnly )
            {
                btnEdit.Visible = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails( definedType );
            }
            else
            {
                btnEdit.Visible = true;
                btnDelete.Visible = false;
                if ( definedType.Id > 0 )
                {
                    ShowReadonlyDetails( definedType );
                }
                else
                {
                    ShowEditDetails( definedType );
                }
            }

            BindDefinedTypeAttributesGrid();
        }
예제 #9
0
        /// <summary>
        /// Shows the type of the edit.
        /// </summary>
        /// <param name="typeId">The type id.</param>
        protected void ShowEditType( int typeId )
        {
            var typeModel = new DefinedTypeService().Get( typeId );

            if ( typeModel != null )
            {
                var type = Rock.Web.Cache.DefinedTypeCache.Read( typeModel );
                lType.Text = "Editing " + typeModel.Name;
                hfIdType.Value = typeId.ToString();
                tbTypeName.Text = typeModel.Name;
                tbTypeCategory.Text = typeModel.Category;
                tbTypeDescription.Text = typeModel.Description;
                if (typeModel.FieldTypeId != null)
                    ddlTypeFieldType.SelectedValue = typeModel.FieldTypeId.ToString();
            }
            else
            {
                lType.Text = "Adding Defined Type";
                hfIdType.Value = string.Empty;
                tbTypeName.Text = string.Empty;
                tbTypeCategory.Text = string.Empty;
                tbTypeDescription.Text = string.Empty;
            }

            pnlTypes.Visible = false;
            pnlTypeDetails.Visible = true;
        }
예제 #10
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        public void ShowDetail( string itemKey, int itemKeyValue )
        {
            if ( !itemKey.Equals( "definedTypeId" ) )
            {
                return;
            }

            pnlList.Visible = true;
            DefinedType definedType = null;

            if ( !itemKeyValue.Equals( 0 ) )
            {
                definedType = new DefinedTypeService().Get( itemKeyValue );
            }
            else
            {
                definedType = new DefinedType { Id = 0 };
            }

            hfDefinedTypeId.SetValue( definedType.Id );
            BindDefinedValuesGrid();
        }
예제 #11
0
        /// <summary>
        /// Loads the cache objects.
        /// </summary>
        private void LoadCacheObjects()
        {
            using ( new Rock.Data.UnitOfWorkScope() )
            {
                // Cache all the Field Types
                var fieldTypeService = new Rock.Model.FieldTypeService();
                foreach ( var fieldType in fieldTypeService.Queryable().ToList() )
                    Rock.Web.Cache.FieldTypeCache.Read( fieldType );

                // Cache all tha Defined Types
                var definedTypeService = new Rock.Model.DefinedTypeService();
                foreach ( var definedType in definedTypeService.Queryable().ToList() )
                    Rock.Web.Cache.DefinedTypeCache.Read( definedType );

                // Cache all the Defined Values
                var definedValueService = new Rock.Model.DefinedValueService();
                foreach ( var definedValue in definedValueService.Queryable().ToList() )
                    Rock.Web.Cache.DefinedValueCache.Read( definedValue );

                // Read all the qualifiers first so that EF doesn't perform a query for each attribute when it's cached
                var qualifiers = new Dictionary<int, Dictionary<string, string>>();
                foreach ( var attributeQualifier in new Rock.Model.AttributeQualifierService().Queryable() )
                {
                    if ( !qualifiers.ContainsKey( attributeQualifier.AttributeId ) )
                        qualifiers.Add( attributeQualifier.AttributeId, new Dictionary<string, string>() );
                    qualifiers[attributeQualifier.AttributeId].Add( attributeQualifier.Key, attributeQualifier.Value );
                }

                // Cache all the attributes.
                foreach ( var attribute in new Rock.Model.AttributeService().Queryable().ToList() )
                {
                    if ( qualifiers.ContainsKey( attribute.Id ) )
                        Rock.Web.Cache.AttributeCache.Read( attribute, qualifiers[attribute.Id] );
                    else
                        Rock.Web.Cache.AttributeCache.Read( attribute, new Dictionary<string, string>() );
                }
            }
        }
예제 #12
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();
        }
        /// <summary>
        /// Binds the grid for defined types.
        /// </summary>
        private void gDefinedType_Bind()
        {
            var queryable = new DefinedTypeService( new RockContext() ).Queryable();

            int? categoryId = tFilter.GetUserPreference( "Category" ).AsIntegerOrNull();
            if ( categoryId.HasValue )
            {
                queryable = queryable.Where( a => a.CategoryId.HasValue && a.CategoryId.Value == categoryId.Value );
            }

            SortProperty sortProperty = gDefinedType.SortProperty;
            if ( sortProperty != null )
            {
                queryable = queryable.Sort( sortProperty );
            }
            else
            {
                queryable = queryable.OrderBy( a => a.Category.Name ).ThenBy( a => a.Name );
            }

            gDefinedType.DataSource = queryable
                .Select( a =>
                new
                {
                    a.Id,
                    Category = a.Category.Name,
                    a.Name,
                    a.Description,
                    a.IsSystem,
                    FieldTypeName = a.FieldType.Name
                } )
                .ToList();
            gDefinedType.DataBind();
        }
예제 #14
0
        /// <summary>
        /// Loads the cache objects.
        /// </summary>
        private void LoadCacheObjects( RockContext rockContext )
        {
            // Read all the qualifiers first so that EF doesn't perform a query for each attribute when it's cached
            var qualifiers = new Dictionary<int, Dictionary<string, string>>();
            foreach ( var attributeQualifier in new Rock.Model.AttributeQualifierService( rockContext ).Queryable() )
            {
                if ( !qualifiers.ContainsKey( attributeQualifier.AttributeId ) )
                    qualifiers.Add( attributeQualifier.AttributeId, new Dictionary<string, string>() );
                qualifiers[attributeQualifier.AttributeId].Add( attributeQualifier.Key, attributeQualifier.Value );
            }

            // Cache all the attributes.
            foreach ( var attribute in new Rock.Model.AttributeService( rockContext ).Queryable( "Categories" ).ToList() )
            {
                if ( qualifiers.ContainsKey( attribute.Id ) )
                    Rock.Web.Cache.AttributeCache.Read( attribute, qualifiers[attribute.Id] );
                else
                    Rock.Web.Cache.AttributeCache.Read( attribute, new Dictionary<string, string>() );
            }

            // Cache all the Field Types
            var all = Rock.Web.Cache.FieldTypeCache.All();

            // DT: When running with production CCV Data, this is taking a considerable amount of time

            // Cache all tha Defined Types
            var definedTypeService = new Rock.Model.DefinedTypeService( rockContext );
            foreach ( var definedType in definedTypeService.Queryable().ToList() )
            {
                Rock.Web.Cache.DefinedTypeCache.Read( definedType );
            }

            // Cache all the Defined Values
            var definedValueService = new Rock.Model.DefinedValueService( rockContext );
            foreach ( var definedValue in definedValueService.Queryable().ToList() )
            {
                Rock.Web.Cache.DefinedValueCache.Read( definedValue );
            }
        }
예제 #15
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;
        }
예제 #16
0
        /// <summary>
        /// Check DB if school already listed in Defined Value
        /// </summary>
        /// <param name="school">The School Name</param>
        /// <returns>School ID as string</returns>
        private string checkSchool( string school )
        {
            var lookupContext = new RockContext();
            var dvService = new DefinedValueService( lookupContext );

            var dtService = new DefinedTypeService( lookupContext );
            int schoolDefinedTypeId = dtService.Queryable().Where( dt => dt.Name == "School" ).FirstOrDefault().Id;

            var schoolList = new List<DefinedValue>();
            var checkedSchool = new DefinedValue();
            //var schoolAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "School" ) );

            //Checks if school is in DB
            //Gets Defined Type and seaches Defined Values for the schoolDefinedTypeId
            schoolList = dvService.Queryable()
                .Where( dv => dv.DefinedTypeId == schoolDefinedTypeId ).ToList(); //Defined Type should equal 34 (CCC)
            //Gets school info if it is present in DB
            checkedSchool = schoolList.Where(s => s.Value == school.Trim()).FirstOrDefault();

            int count = 0;
            //If it isn't in the DB it will add it.
            while ( checkedSchool == null )
            {
                var newSchool = new DefinedValue();
                var newSchoolList = new List<DefinedValue>();

                newSchool.IsSystem = false;
                newSchool.DefinedTypeId = 34;
                newSchool.Order = 0;
                newSchool.Value = school.Trim();
                newSchool.Guid = new Guid();

                newSchoolList.Add( newSchool );

                var rockContext = new RockContext();
                rockContext.WrapTransaction( () =>
                {
                    rockContext.Configuration.AutoDetectChangesEnabled = false;
                    rockContext.DefinedValues.AddRange( newSchoolList );
                    rockContext.SaveChanges( DisableAudit );
                } );

                ReportProgress( 0, string.Format( "New School Added: {0}.", school.Trim() ) );

                count++;

                if ( count > 3 )
                {
                    ReportProgress( 0, string.Format( "Stuck in Loop and school is not being added properly.", school.Trim() ) );
                    return "173";
                }

            }

            //If School is already in Defined Value Table, its Id is returned.
            return Convert.ToString(checkedSchool.Id);

            throw new NotImplementedException();
        }
예제 #17
0
        /// <summary>
        /// Binds the grid for defined types.
        /// </summary>
        private void rGridType_Bind()
        {
            var queryable = new DefinedTypeService().Queryable().
                Where( a => a.Category != "" && a.Category != null );

            if ( ddlCategoryFilter.SelectedValue != "[All]" )
                queryable = queryable.
                    Where( a => a.Category == ddlCategoryFilter.SelectedValue );

            SortProperty sortProperty = rGridType.SortProperty;
            if ( sortProperty != null )
                queryable = queryable.
                    Sort( sortProperty );
            else
                queryable = queryable.
                    OrderBy( a => a.Category );

            rGridType.DataSource = queryable.ToList();
            rGridType.DataBind();
        }
예제 #18
0
        /// <summary>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            if ( ddlCategoryFilter.SelectedItem == null )
            {
                ddlCategoryFilter.Items.Clear();
                ddlCategoryFilter.Items.Add( "[All]" );

                DefinedTypeService typeService = new DefinedTypeService();
                var items = typeService.Queryable().
                    Where( a => a.Category != "" && a.Category != null ).
                    OrderBy( a => a.Category ).
                    Select( a => a.Category ).
                    Distinct().ToList();

                foreach ( var item in items )
                    ddlCategoryFilter.Items.Add( item );
            }
        }
        /// <summary>
        /// Binds the grid for defined types.
        /// </summary>
        private void gDefinedType_Bind()
        {
            var queryable = new DefinedTypeService( new RockContext() ).Queryable().Select( a =>
                new
                {
                    a.Id,
                    a.Category,
                    a.Name,
                    a.Description,
                    a.IsSystem,
                    FieldTypeName = a.FieldType.Name
                } );

            string categoryFilter = tFilter.GetUserPreference( "Category" );
            if ( !string.IsNullOrWhiteSpace(categoryFilter) && categoryFilter != Rock.Constants.All.Text )
            {
                queryable = queryable.Where( a => a.Category == categoryFilter );
            }

            SortProperty sortProperty = gDefinedType.SortProperty;
            if ( sortProperty != null )
            {
                queryable = queryable.Sort( sortProperty );
            }
            else
            {
                queryable = queryable.OrderBy( a => a.Category ).ThenBy( a => a.Name );
            }

            gDefinedType.DataSource = queryable.ToList();
            gDefinedType.DataBind();
        }
예제 #20
0
        //using this to enter the Year Multi-Select GUID of a defined Year that is already in Rock
        private string MultiSelectYearGUID( DateTime? f1StartDate )
        {
            DateTime startDate = (DateTime)f1StartDate;

            var lookupContext = new RockContext();
            var dvService = new DefinedValueService( lookupContext );
            var dtService = new DefinedTypeService( lookupContext );

            var yearInList = new DefinedValue();
            int dtInList; //= new DefinedType();

            var yearMultiSelectDefinedType = dtService.Queryable()
                .Where( dt => dt.Name == "Year Multi-Selection" ).ToList(); //finds all rows in Defined Type with this name (only one present)
            dtInList = yearMultiSelectDefinedType.Where( dt => dt.Name == "Year Multi-Selection" ) //sets the above Defined Type ID to this variable.
                .Select( dt => dt.Id ).FirstOrDefault();

            var existingDefinedYears = dvService.Queryable()
                .Where( dv => dv.DefinedTypeId == dtInList ).ToList();  //finds all Definded Values with the Defined Type ID from the item above.

            string guid = string.Format( "{0}", existingDefinedYears.Where( dt => dt.Value == string.Format( "{0}", startDate.Year ) ).Select( dt => dt.Guid ).FirstOrDefault() ); //the value that will be returned.

            return guid;

            //if (f1StartDate != null)
            //{

            //    switch (startDate.Year)
            //    {
            //        case 2001:
            //            guid = "B9A40993-7758-49A3-BE6B-00E930FCF690";
            //            break;
            //        case 2002:
            //            guid = "56BF96EF-561E-424D-BA85-A93674569B47";
            //            break;
            //        case 2003:
            //            guid = "74EB6703-DEB4-4CEA-81E2-5EC7ED81BB18";
            //            break;
            //        case 2004:
            //            guid = "DD28ACBD-8B2C-49CC-81C9-B7FFE4D8E3C2";
            //            break;
            //        case 2005:
            //            guid = "F18A88B7-5228-4B7D-8079-4B118DF792C7";
            //            break;
            //        case 2006:
            //            guid = "719DF19D-B5AF-4125-B708-BDC22EB64E8F";
            //            break;
            //        case 2007:
            //            guid = "CE44EA17-020E-4B97-8975-4DE01830163D";
            //            break;
            //        case 2008:
            //            guid = "6810C1C9-85BD-42E9-9E04-85801A93096D";
            //            break;
            //        case 2009:
            //            guid = "2C8B55AF-B5E2-41F9-9E08-C2E6F4624550";
            //            break;
            //        case 2010:
            //            guid = "FB260D37-AEF4-4277-959C-5884E579E1AC";
            //            break;
            //        case 2011:
            //            guid = "6E84915B-CC11-4E66-954E-9B1D786B2E6F";
            //            break;
            //        case 2012:
            //            guid = "4ED12DFD-BA8F-4760-A045-E7AC898BEC50";
            //            break;
            //        case 2013:
            //            guid = "AFEC8401-3E49-4895-B320-6FF4918A5F4D";
            //            break;
            //        case 2014:
            //            guid = "F80B2BEA-5FA5-48C4-82FF-AC5E1A15C763";
            //            break;
            //        default:
            //            guid = "none";
            //            break;
            //    }
            //    return guid;
            //}
            //else
            //{
            //    return "none";
            //}
        }
 /// <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 );
     }
 }
예제 #22
0
        /// <summary>
        /// Adds a new defined value to a given DefinedType.
        /// </summary>
        /// <param name="stringValue">the string value of the new defined value</param>
        /// <param name="definedType">a defined type to which the defined value will be added.</param>
        /// <param name="rockContext"></param>
        /// <returns></returns>
        private DefinedValue AddDefinedTypeValue( string stringValue, DefinedType definedType, RockContext rockContext )
        {
            DefinedValueService definedValueService = new DefinedValueService( rockContext );
            DefinedTypeService definedTypeService = new DefinedTypeService( rockContext );

            DefinedValue definedValue = new DefinedValue {
                Id = 0,
                IsSystem = false,
                Value = stringValue,
                Description = string.Empty,
                CreatedDateTime = RockDateTime.Now,
                DefinedTypeId = definedType.Id
            };

            definedValueService.Add( definedValue );
            rockContext.ChangeTracker.DetectChanges();
            rockContext.SaveChanges( disablePrePostProcessing: true );

            return definedValue;
        }
 /// <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 );
 }
예제 #24
0
        /// <summary>
        /// Loads the drop downs.
        /// </summary>
        private void LoadDropDowns()
        {
            RockContext rockContext = new RockContext();
            ddlDataView.Items.Clear();
            var dataviewList = new DataViewService( rockContext ).Queryable().Select(
                s => new
                {
                    s.Id,
                    s.Name
                } ).OrderBy( a => a.Name ).ToList();

            foreach ( var item in dataviewList )
            {
                ddlDataView.Items.Add( new ListItem( item.Name, item.Id.ToString() ) );
            }

            ddlSourceType.Items.Clear();
            foreach ( var item in new DefinedValueService( rockContext ).GetByDefinedTypeGuid( Rock.SystemGuid.DefinedType.METRIC_SOURCE_TYPE.AsGuid() ) )
            {
                ddlSourceType.Items.Add( new ListItem( item.Value, item.Id.ToString() ) );
            }

            rblScheduleSelect.Items.Clear();
            rblScheduleSelect.Items.Add( new ListItem( ScheduleSelectionType.Unique.ConvertToString(), ScheduleSelectionType.Unique.ConvertToInt().ToString() ) );
            rblScheduleSelect.Items.Add( new ListItem( ScheduleSelectionType.NamedSchedule.ConvertToString(), ScheduleSelectionType.NamedSchedule.ConvertToInt().ToString() ) );

            var scheduleCategoryId = new CategoryService( rockContext ).Get( Rock.SystemGuid.Category.SCHEDULE_METRICS.AsGuid() ).Id;
            var scheduleCategories = new ScheduleService( rockContext ).Queryable()
                .Where( a => a.CategoryId == scheduleCategoryId && a.Name != string.Empty )
                .OrderBy( a => a.Name ).ToList();

            ddlSchedule.Items.Clear();
            foreach ( var item in scheduleCategories )
            {
                ddlSchedule.Items.Add( new ListItem( item.Name, item.Id.ToString() ) );
            }

            // limit to EntityTypes that support picking a Value with a picker
            etpMetricPartitionEntityType.EntityTypes = new EntityTypeService( new RockContext() ).GetEntities().OrderBy( t => t.FriendlyName ).Where( a => a.SingleValueFieldTypeId.HasValue ).ToList();

            // just in case they select an EntityType that can be qualified by DefinedType...
            ddlMetricPartitionDefinedTypePicker.Items.Clear();
            ddlMetricPartitionDefinedTypePicker.Items.Add( new ListItem() );
            var definedTypesList = new DefinedTypeService( rockContext ).Queryable().OrderBy( a => a.Name )
                .Select( a => new
                {
                    a.Id,
                    a.Name
                } ).ToList();

            foreach ( var definedType in definedTypesList )
            {
                ddlMetricPartitionDefinedTypePicker.Items.Add( new ListItem( definedType.Name, definedType.Id.ToString() ) );
            }
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        public void ShowDetail( string itemKey, int itemKeyValue )
        {
            if ( !itemKey.Equals( "definedTypeId" ) )
            {
                return;
            }

            pnlDetails.Visible = true;
            DefinedType definedType = null;

            if ( !itemKeyValue.Equals( 0 ) )
            {
                definedType = new DefinedTypeService( new RockContext() ).Get( itemKeyValue );
                // If bad data was passed in, return and show nothing.
                if ( definedType == null )
                {
                    pnlDetails.Visible = false;
                    return;
                }
            }
            else
            {
                definedType = new DefinedType { Id = 0 };
            }

            hfDefinedTypeId.SetValue( definedType.Id );

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if ( _isReadOnly || !IsUserAuthorized( Authorization.EDIT ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( DefinedType.FriendlyTypeName );
            }

            if ( definedType.IsSystem )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( DefinedType.FriendlyTypeName );
            }

            if ( readOnly )
            {
                btnEdit.Visible = false;
                ShowReadonlyDetails( definedType );
            }
            else
            {
                btnEdit.Visible = true;
                if ( definedType.Id > 0 )
                {
                    ShowReadonlyDetails( definedType );
                }
                else
                {
                    ShowEditDetails( definedType );
                }
            }

            BindDefinedTypeAttributesGrid();
        }
예제 #26
0
        //using this to enter the Connect Group Seasons GUID of a defined Year that is already in Rock
        private string CrossroadsSportsCampYears( DateTime? f1StartDate, string playVol )
        {
            DateTime startDate = (DateTime)f1StartDate;

            var lookupContext = new RockContext();
            var dvService = new DefinedValueService( lookupContext );
            var dtService = new DefinedTypeService( lookupContext );

            var yearInList = new DefinedValue();
            int dtInList; //= new DefinedType();

            var yearMultiSelectDefinedType = dtService.Queryable()
                .Where( dt => dt.Name == "Crossroads Sports Camp Years" ).ToList(); //finds all rows in Defined Type with this name (only one present)
            dtInList = yearMultiSelectDefinedType.Where( dt => dt.Name == "Crossroads Sports Camp Years" ) //sets the above Defined Type ID to this variable.
                .Select( dt => dt.Id ).FirstOrDefault();

            var existingDefinedYears = dvService.Queryable()
                .Where( dv => dv.DefinedTypeId == dtInList ).ToList();  //finds all Definded Values with the Defined Type ID from the item above.

            string guid = string.Format( "{0}", existingDefinedYears.Where( dt => dt.Value == string.Format( "{0} ({1})", startDate.Year, playVol ) ).Select( dt => dt.Guid ).FirstOrDefault() ); //the value that will be returned. Takes on two properties, the start date and the second word (Play) etc.

            return guid;
        }
예제 #27
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();
        }
        /// <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();
        }
예제 #29
0
        /// <summary>
        /// Returns an enumerable collection of <see cref="Rock.Model.DefinedValue">DefinedValues</see> that belong to a specified <see cref="Rock.Model.DefinedType"/> retrieved by the DefinedType's Guid identifier.
        /// </summary>
        /// <param name="definedTypeGuid">A <see cref="System.Guid"/> representing the Guid identifier of the <see cref="Rock.Model.DefinedType"/> to retrieve <see cref="Rock.Model.DefinedValue">DefinedValues</see>
        /// for.</param>
        /// <returns>An enumerable collection of <see cref="Rock.Model.DefinedValue">DefinedValues</see> that belong to the <see cref="Rock.Model.DefinedType"/> specified by the provided Guid. If a match
        /// is not found, an empty collection will be returned.</returns>
        public IEnumerable <DefinedValue> GetByDefinedTypeGuid(Guid definedTypeGuid)
        {
            var definedType = new DefinedTypeService().GetByGuid(definedTypeGuid);

            return(GetByDefinedTypeId(definedType.Id));
        }
        /// <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 );
        }
예제 #31
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        public void ShowDetail( string itemKey, int itemKeyValue )
        {
            if ( !itemKey.Equals( "definedTypeId" ) )
            {
                return;
            }

            pnlDetails.Visible = true;
            DefinedType definedType = null;

            if ( !itemKeyValue.Equals( 0 ) )
            {
                definedType = new DefinedTypeService().Get( itemKeyValue );
            }
            else
            {
                definedType = new DefinedType { Id = 0 };
                definedType.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id;
            }

            hfDefinedTypeId.SetValue( definedType.Id );

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if ( !IsUserAuthorized( "Edit" ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( DefinedType.FriendlyTypeName );
            }

            if ( definedType.IsSystem )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( DefinedType.FriendlyTypeName );
            }

            if ( readOnly )
            {
                btnEdit.Visible = false;
                ShowReadonlyDetails( definedType );
            }
            else
            {
                btnEdit.Visible = true;
                if ( definedType.Id > 0 )
                {
                    ShowReadonlyDetails( definedType );
                }
                else
                {
                    ShowEditDetails( definedType );
                }
            }

            BindDefinedTypeAttributesGrid();            
        }
예제 #32
0
        /// <summary>
        /// Creates the HTML controls required to configure this type of field
        /// </summary>
        /// <returns></returns>
        public override List<Control> ConfigurationControls()
        {
            var controls = base.ConfigurationControls();

            // build a drop down list of defined types (the one that gets selected is
            // used to build a list of defined values) 
            var ddl = new RockDropDownList();
            controls.Add( ddl );
            ddl.AutoPostBack = true;
            ddl.SelectedIndexChanged += OnQualifierUpdated;
            ddl.Label = "Defined Type";
            ddl.Help = "The Defined Type to select values from.";

            Rock.Model.DefinedTypeService definedTypeService = new Model.DefinedTypeService();
            foreach ( var definedType in definedTypeService.Queryable().OrderBy( d => d.Order ) )
            {
                ddl.Items.Add( new ListItem( definedType.Name, definedType.Id.ToString() ) );
            }

            // Add checkbox for deciding if the defined values list is renedered as a drop
            // down list or a checkbox list.
            var cb = new RockCheckBox();
            controls.Add( cb );
            cb.AutoPostBack = true;
            cb.CheckedChanged += OnQualifierUpdated;
            cb.Label = "Allow Multiple Values";
            cb.Text = "Yes";
            cb.Help = "When set, allows multiple defined type values to be selected.";
            return controls;
        }
예제 #33
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 );
        }