Rock.Model.AttributeValueService.GetGlobalAttributeValue C# (CSharp) Method

GetGlobalAttributeValue() public method

Returns a Rock.Model.AttributeValue for a Rock.Model.Attribute by Key.
public GetGlobalAttributeValue ( string key ) : AttributeValue
key string A representing the name of the Global Attribute's key value.
return AttributeValue
        public AttributeValue GetGlobalAttributeValue( string key )
        {
            return Queryable()
                .Where( v =>
                    v.Attribute.Key == key &&
                    !v.Attribute.EntityTypeId.HasValue &&
                    ( v.Attribute.EntityTypeQualifierColumn == null || v.Attribute.EntityTypeQualifierColumn == string.Empty ) &&
                    ( v.Attribute.EntityTypeQualifierColumn == null || v.Attribute.EntityTypeQualifierColumn == string.Empty ) &&
                    !v.EntityId.HasValue )
                .FirstOrDefault();
        }

Usage Example

Ejemplo n.º 1
0
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            string livePlatformUrl = dataMap.GetString("Address") ?? "http://live.newpointe.org/api/v1/events/current";

            //Check ChurchOnline Platform API to see if there is a live event

            using (WebClient wc = new WebClient())
            {
                LivePlatformUrlJson = wc.DownloadString(livePlatformUrl);
            }

            dynamic isServiceLive = JsonConvert.DeserializeObject(LivePlatformUrlJson);

            string isLive = isServiceLive.response.item.isLive.ToString();

            // specify which attribute key we want to work with
            var attributeKey = "LiveService";  //production

            var attributeValueService = new AttributeValueService(rockContext);

            // specify NULL as the EntityId since this is a GlobalAttribute
            var globalAttributeValue = attributeValueService.GetGlobalAttributeValue(attributeKey);

            if (globalAttributeValue != null)
            {
                // save updated value to database
                globalAttributeValue.Value = isLive;
                rockContext.SaveChanges();

                // flush the attributeCache for this attribute so it gets reloaded from the database
                //Rock.Web.Cache.AttributeCache.Flush();

                // flush the GlobalAttributeCache since this attribute is a GlobalAttribute
                Rock.Web.Cache.GlobalAttributesCache.Flush();
            }
        }
All Usage Examples Of Rock.Model.AttributeValueService::GetGlobalAttributeValue