/// <summary>
        /// Adds a new defined value to a given DefinedType.
        /// </summary>
        /// <param name="topic">the string value of the new defined value</param>
        /// <param name="definedTypeCache">a defined type cache to which the defined value will be added.</param>
        /// <param name="rockContext"></param>
        /// <returns></returns>
        private DefinedValueCache AddDefinedTypeValue( string topic, DefinedTypeCache definedTypeCache, RockContext rockContext )
        {
            DefinedValueService definedValueService = new DefinedValueService( rockContext );

            DefinedValue definedValue = new DefinedValue {
                Id = 0,
                IsSystem = false,
                Value = topic,
                Description = "",
                CreatedDateTime = RockDateTime.Now,
                DefinedTypeId = definedTypeCache.Id
            };
            definedValueService.Add( definedValue );
            rockContext.SaveChanges();

            Rock.Web.Cache.DefinedValueCache.Flush( definedValue.Id );
            Rock.Web.Cache.DefinedTypeCache.Flush( definedTypeCache.Id );

            return DefinedValueCache.Read( definedValue.Id, rockContext );
        }
Esempio n. 2
0
        /// <summary>
        /// Reads the specified defined type model.
        /// </summary>
        /// <param name="definedTypeModel">The defined type model.</param>
        /// <returns></returns>
        public static DefinedTypeCache Read( Rock.Model.DefinedType definedTypeModel )
        {
            string cacheKey = DefinedTypeCache.CacheKey( definedTypeModel.Id );

            ObjectCache cache = MemoryCache.Default;
            DefinedTypeCache definedType = cache[cacheKey] as DefinedTypeCache;

            if ( definedType != null )
                return definedType;
            else
            {
                definedType = new DefinedTypeCache( definedTypeModel );

                var cachePolicy = new CacheItemPolicy();
                cache.Set( cacheKey, definedType, cachePolicy );
                cache.Set( definedType.Guid.ToString(), definedType.Id, cachePolicy );

                return definedType;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Copies the model.
        /// </summary>
        /// <param name="definedTypeModel">The defined type model.</param>
        /// <returns></returns>
        public static DefinedTypeCache CopyModel( Rock.Model.DefinedType definedTypeModel )
        {
            DefinedTypeCache definedType = new DefinedTypeCache(definedTypeModel);

            definedType.definedValueIds = definedTypeModel.DefinedValues
                .Select( v => v.Id ).ToList();

            return definedType;
        }
Esempio n. 4
0
        /// <summary>
        /// Reads the specified GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        public static DefinedTypeCache Read( Guid guid )
        {
            ObjectCache cache = MemoryCache.Default;
            object cacheObj = cache[guid.ToString()];

            if ( cacheObj != null )
                return Read((int)cacheObj);
            else
            {
                Rock.Model.DefinedTypeService definedTypeService = new Rock.Model.DefinedTypeService();
                Rock.Model.DefinedType definedTypeModel = definedTypeService
                    .Queryable( "DefinedValues" )
                    .Where( t => t.Guid == guid )
                    .FirstOrDefault();

                if ( definedTypeModel != null )
                {
                    var definedType = new DefinedTypeCache( definedTypeModel );

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set( DefinedTypeCache.CacheKey( definedType.Id ), definedType, cachePolicy );
                    cache.Set( definedType.Guid.ToString(), definedType.Id, cachePolicy );

                    return definedType;
                }
                else
                    return null;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit( EventArgs e )
        {
            base.OnInit( e );

            // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it
            this.BlockUpdated += Block_BlockUpdated;
            this.AddConfigurationUpdateTrigger( upnlContent );

            _canEdit = UserCanEdit;
            gLinks.DataKeyNames = new string[] { "Id" };
            gLinks.Actions.AddClick += gLinks_Add;
            gLinks.GridRebind += gLinks_GridRebind;
            gLinks.GridReorder += gLinks_GridReorder;
            gLinks.RowDataBound += gLinks_RowDataBound;
            gLinks.Actions.ShowAdd = _canEdit;
            gLinks.IsDeleteEnabled = _canEdit;
            gLinks.Actions.AddButton.CssClass = "btn-add btn btn-default btn-xs";

            foreach ( var securityField in gLinks.Columns.OfType<SecurityField>() )
            {
                securityField.EntityTypeId = EntityTypeCache.Read( typeof( DefinedValue ) ).Id;
            }

            _definedType = DefinedTypeCache.Read( GetAttributeValue( "DefinedType" ).AsGuid() );
        }