Exemple #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>());
                    }
                }
            }
        }
Exemple #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>
        /// 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;
        }
Exemple #4
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>() );
                }
            }
        }
Exemple #5
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;
        }
Exemple #6
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>
        /// 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>
        /// 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();
        }
        /// <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>
        /// Maps the Giftedness Program.
        /// </summary>
        /// <param name="tableData">The table data.</param>
        private void MapGiftednessProgram( IQueryable<Row> tableData )
        {
            int completed = 0;
            int totalRows = tableData.Count();
            int percentage = ( totalRows - 1 ) / 100 + 1;
            ReportProgress( 0, string.Format( "Verifying Giftedness Program import ({0:N0} found).", totalRows ) );

            foreach ( var row in tableData )
            {
                var rockContext = new RockContext();
                var categoryList = new CategoryService( rockContext ).Queryable().ToList();
                var attributeList = new AttributeService( rockContext ).Queryable().ToList();
                var definedTypeList = new DefinedTypeService( rockContext ).Queryable().ToList();
                var definedValueList = new DefinedValueService( rockContext ).Queryable().ToList();

                //check if category exists
                string category = row["CategoryName"] as string;
                if ( categoryList.Find( c => c.Name == category ) == null )
                {
                    var entityType = new EntityTypeService( rockContext );
                    //creates if category doesn't exist
                    var newCategory = new Category();
                    newCategory.IsSystem = false;
                    newCategory.EntityTypeId = entityType.Queryable().Where( e => e.Name == "Rock.Model.Attribute" ).Select( e => e.Id ).FirstOrDefault();
                    newCategory.EntityTypeQualifierColumn = "EntityTypeId";
                    newCategory.EntityTypeQualifierValue = Convert.ToString( PersonEntityTypeId );  //Convert.ToString(entityType.Queryable().Where( e => e.Name == "Rock.Model.Person" ).Select( e => e.Id ).FirstOrDefault());
                    newCategory.Name = category;
                    newCategory.Description = "Contains the spiritual gifts attributes";

                    //var newCategoryContext = new RockContext();
                    //newCategoryContext.WrapTransaction( () =>
                    //{
                    //    newCategoryContext.Configuration.AutoDetectChangesEnabled = false;
                    //    newCategoryContext.Categories.Add( newCategory );
                    //    newCategoryContext.SaveChanges( DisableAudit );
                    //} );
                    rockContext.WrapTransaction( () =>
                    {
                        rockContext.Configuration.AutoDetectChangesEnabled = false;
                        rockContext.Categories.Add( newCategory );
                        rockContext.SaveChanges( DisableAudit );
                    } );
                }
                //Check if Attribute exists
                if ( attributeList.Find( a => a.Key == "Rank1" ) == null || attributeList.Find( a => a.Key == "Rank2" ) == null || attributeList.Find( a => a.Key == "Rank3" ) == null || attributeList.Find( a => a.Key == "Rank4" ) == null )
                {
                    var fieldType = new FieldTypeService( rockContext );
                    var newAttributeList = new List<Rock.Model.Attribute>();
                    var fieldTypeId = fieldType.Queryable().Where( e => e.Name == "Defined Value" ).FirstOrDefault().Id;
                    var category2 = new CategoryService( rockContext ).Queryable().Where( gt => gt.Name == "Spiritual Gifts" ).FirstOrDefault();

                    if ( attributeList.Find( a => a.Key == "Rank1" ) == null )
                    {
                        //Creates if attribute doesn't exist
                        var newAttribute = new Rock.Model.Attribute();
                        newAttribute.Key = "Rank1";
                        newAttribute.Name = "Rank 1";
                        newAttribute.FieldTypeId = fieldTypeId;
                        newAttribute.EntityTypeId = PersonEntityTypeId;
                        newAttribute.EntityTypeQualifierValue = string.Empty;
                        newAttribute.EntityTypeQualifierColumn = string.Empty;
                        newAttribute.Description = "Rank 1";
                        newAttribute.DefaultValue = string.Empty;
                        newAttribute.IsMultiValue = false;
                        newAttribute.IsRequired = false;
                        newAttribute.Categories = new List<Category>();
                        newAttribute.Categories.Add( category2 );

                        newAttributeList.Add( newAttribute );

                    }
                    if ( attributeList.Find( a => a.Key == "Rank2" ) == null )
                    {
                        //Creates if attribute doesn't exist
                        var newAttribute = new Rock.Model.Attribute();
                        newAttribute.Key = "Rank2";
                        newAttribute.Name = "Rank 2";
                        newAttribute.FieldTypeId = fieldTypeId;
                        newAttribute.EntityTypeId = PersonEntityTypeId;
                        newAttribute.EntityTypeQualifierValue = string.Empty;
                        newAttribute.EntityTypeQualifierColumn = string.Empty;
                        newAttribute.Description = "Rank 2";
                        newAttribute.DefaultValue = string.Empty;
                        newAttribute.IsMultiValue = false;
                        newAttribute.IsRequired = false;
                        newAttribute.Categories = new List<Category>();
                        newAttribute.Categories.Add( category2 );

                        newAttributeList.Add( newAttribute );
                    }
                    if ( attributeList.Find( a => a.Key == "Rank3" ) == null )
                    {
                        //Creates if attribute doesn't exist
                        var newAttribute = new Rock.Model.Attribute();
                        newAttribute.Key = "Rank3";
                        newAttribute.Name = "Rank 3";
                        newAttribute.FieldTypeId = fieldTypeId;
                        newAttribute.EntityTypeId = PersonEntityTypeId;
                        newAttribute.EntityTypeQualifierValue = string.Empty;
                        newAttribute.EntityTypeQualifierColumn = string.Empty;
                        newAttribute.Description = "Rank 3";
                        newAttribute.DefaultValue = string.Empty;
                        newAttribute.IsMultiValue = false;
                        newAttribute.IsRequired = false;
                        newAttribute.Categories = new List<Category>();
                        newAttribute.Categories.Add( category2 );

                        newAttributeList.Add( newAttribute );
                    }
                    if ( attributeList.Find( a => a.Key == "Rank4" ) == null )
                    {

                        //Creates if attribute doesn't exist
                        var newAttribute = new Rock.Model.Attribute();
                        newAttribute.Key = "Rank4";
                        newAttribute.Name = "Rank 4";
                        newAttribute.FieldTypeId = fieldTypeId;
                        newAttribute.EntityTypeId = PersonEntityTypeId;
                        newAttribute.EntityTypeQualifierValue = string.Empty;
                        newAttribute.EntityTypeQualifierColumn = string.Empty;
                        newAttribute.Description = "Rank 4";
                        newAttribute.DefaultValue = string.Empty;
                        newAttribute.IsMultiValue = false;
                        newAttribute.IsRequired = false;
                        newAttribute.Categories = new List<Category>();
                        newAttribute.Categories.Add( category2 );

                        newAttributeList.Add( newAttribute );
                    }

                    if ( newAttributeList.Any() )
                    {
                        //var newAttributeContext = new RockContext();
                        rockContext.WrapTransaction( () =>
                        {
                            rockContext.Configuration.AutoDetectChangesEnabled = false;
                            rockContext.Attributes.AddRange( newAttributeList );
                            rockContext.SaveChanges( DisableAudit );
                            newAttributeList.Clear();
                        } );
                    }
                }
                //checks if Defined Type exists
                if ( definedTypeList.Find( d => d.Name == "Spiritual Gifts" ) == null )
                {
                    var fieldTypeService = new FieldTypeService( rockContext );

                    //creates Defined Type
                    var newDefinedType = new DefinedType();
                    newDefinedType.IsSystem = false;
                    newDefinedType.FieldTypeId = fieldTypeService.Queryable().Where( f => f.Name == "Text" ).Select( f => f.Id ).FirstOrDefault();
                    newDefinedType.Name = "Spiritual Gifts";
                    newDefinedType.Description = "Defined Type for Spiritual Gifts values";
                    newDefinedType.CategoryId = categoryList.Find( c => c.Name == "Person" ).Id;

                    //var newDTContext = new RockContext();
                    rockContext.WrapTransaction( () =>
                    {
                        rockContext.Configuration.AutoDetectChangesEnabled = false;
                        rockContext.DefinedTypes.Add( newDefinedType );
                        rockContext.SaveChanges( DisableAudit );
                    } );

                }
                //checks if Defined Value exists
                var spiritualGiftsDefineType = new DefinedTypeService( rockContext ).Queryable().Where( d => d.Name == "Spiritual Gifts" ).FirstOrDefault();
                string attributeName = row["AttributeName"] as string;
                int? giftAttributeId = row["GiftAttributeID"] as int?;
                if ( definedValueList.Find( d => d.DefinedTypeId == spiritualGiftsDefineType.Id && d.Value == attributeName ) == null )
                {
                    var definedTypeService = new DefinedTypeService( rockContext );
                    //creates Defined Value
                    var newDefinedValue = new DefinedValue();
                    newDefinedValue.IsSystem = false;
                    newDefinedValue.DefinedTypeId = definedTypeService.Queryable().Where( d => d.Name == "Spiritual Gifts" ).Select( d => d.Id ).FirstOrDefault();
                    newDefinedValue.Value = attributeName;
                    newDefinedValue.Description = "Spiritual Gift attribute value: " + attributeName;
                    newDefinedValue.ForeignId = Convert.ToString(giftAttributeId);

                    //var newDVContext = new RockContext();
                    rockContext.WrapTransaction( () =>
                    {
                        rockContext.Configuration.AutoDetectChangesEnabled = false;
                        rockContext.DefinedValues.Add( newDefinedValue );
                        rockContext.SaveChanges( DisableAudit );
                    } );

                }

                completed++;

                if ( completed % percentage < 1 )
                {
                    int percentComplete = completed / percentage;
                    ReportProgress( percentComplete, string.Format( "{0:N0} spiritual gifts attributes imported ({1}% complete).", completed, percentComplete ) );
                }
                else if ( completed % ReportingNumber < 1 )
                {

                    ReportPartialProgress();
                }
            }

            ReportProgress( 100, string.Format( "Finished spiritual gifts import: {0:N0} spiritual gifts attributes imported.", completed ) );
        }