/// <summary> /// Job that updates the JobPulse setting with the current date/time. /// This will allow us to notify an admin if the jobs stop running. /// /// Called by the <see cref="IScheduler" /> when a /// <see cref="ITrigger" /> fires that is associated with /// the <see cref="IJob" />. /// </summary> public virtual void Execute(IJobExecutionContext context) { using ( new Rock.Data.UnitOfWorkScope() ) { AttributeService attribService = new AttributeService(); AttributeValueService attributeValueService = new AttributeValueService(); Rock.Core.Attribute jobPulseAttrib = attribService.GetGlobalAttribute( "JobPulse" ); Rock.Core.AttributeValue jobPulseAttribValue = jobPulseAttrib.AttributeValues.FirstOrDefault(); // create attribute value if one does not exist if ( jobPulseAttribValue == null ) { jobPulseAttribValue = new AttributeValue(); jobPulseAttribValue.AttributeId = jobPulseAttrib.Id; attributeValueService.Add( jobPulseAttribValue, null ); } // store todays date and time jobPulseAttribValue.Value = DateTime.Now.ToString(); // save attribute attributeValueService.Save( jobPulseAttribValue, null ); } }
protected override void OnInit( EventArgs e ) { base.OnInit( e ); string entity = AttributeValue( "Entity" ); if ( string.IsNullOrWhiteSpace( entity ) ) entity = PageParameter( "Entity" ); string entityQualifierColumn = AttributeValue( "EntityQualifierColumn" ); if ( string.IsNullOrWhiteSpace( entityQualifierColumn ) ) entityQualifierColumn = PageParameter( "EntityQualifierColumn" ); string entityQualifierValue = AttributeValue( "EntityQualifierValue" ); if ( string.IsNullOrWhiteSpace( entityQualifierValue ) ) entityQualifierValue = PageParameter( "EntityQualifierValue" ); _category = AttributeValue( "AttributeCategory" ); if ( string.IsNullOrWhiteSpace( _category ) ) _category = PageParameter( "AttributeCategory" ); ObjectCache cache = MemoryCache.Default; string cacheKey = string.Format( "Attributes:{0}:{1}:{2}", entity, entityQualifierColumn, entityQualifierValue ); Dictionary<string, List<int>> cachedAttributes = cache[cacheKey] as Dictionary<string, List<int>>; if ( cachedAttributes == null ) { cachedAttributes = new Dictionary<string, List<int>>(); AttributeService attributeService = new AttributeService(); foreach ( var item in attributeService.Queryable(). Where( a => a.Entity == entity && ( a.EntityQualifierColumn ?? string.Empty ) == entityQualifierColumn && ( a.EntityQualifierValue ?? string.Empty ) == entityQualifierValue ). OrderBy( a => a.Category ). ThenBy( a => a.Order ). Select( a => new { a.Category, a.Id } ) ) { if ( !cachedAttributes.ContainsKey( item.Category ) ) cachedAttributes.Add( item.Category, new List<int>() ); cachedAttributes[item.Category].Add( item.Id ); } CacheItemPolicy cacheItemPolicy = null; cache.Set( cacheKey, cachedAttributes, cacheItemPolicy ); } Rock.Attribute.IHasAttributes model = PageInstance.GetCurrentContext( entity ) as Rock.Attribute.IHasAttributes; if ( model != null ) { if ( cachedAttributes.ContainsKey( _category ) ) foreach ( var attributeId in cachedAttributes[_category] ) { var attribute = Rock.Web.Cache.Attribute.Read( attributeId ); if ( attribute != null ) phAttributes.Controls.Add( ( AttributeInstanceValues )this.LoadControl( "~/Blocks/Core/AttributeInstanceValues.ascx", model, attribute, CurrentPersonId ) ); } } string script = @" Sys.Application.add_load(function () { $('div.context-attribute-values .delete').click(function(){ return confirm('Are you sure?'); }); }); "; Page.ClientScript.RegisterStartupScript(this.GetType(), "ConfirmDelete", script, true ); }
private void BindFilter() { ddlCategoryFilter.Items.Clear(); ddlCategoryFilter.Items.Add( "[All]" ); AttributeService attributeService = new AttributeService(); var items = attributeService.Queryable(). Where( a => a.Entity == entity && ( a.EntityQualifierColumn ?? string.Empty ) == entityQualifierColumn && ( a.EntityQualifierValue ?? string.Empty ) == entityQualifierValue && a.Category != "" && a.Category != null ). OrderBy( a => a.Category ). Select( a => a.Category ). Distinct().ToList(); foreach ( var item in items ) ddlCategoryFilter.Items.Add( item ); }
void rGrid_RowDataBound( object sender, GridViewRowEventArgs e ) { if ( e.Row.RowType == DataControlRowType.DataRow ) { Literal lValue = e.Row.FindControl( "lValue" ) as Literal; HtmlAnchor aEdit = e.Row.FindControl( "aEdit" ) as HtmlAnchor; if ( lValue != null && aEdit != null ) { int attributeId = ( int )rGrid.DataKeys[e.Row.RowIndex].Value; AttributeService attributeService = new AttributeService(); var attribute = attributeService.Get( attributeId ); var fieldType = Rock.Web.Cache.FieldType.Read( attribute.FieldTypeId ); AttributeValueService attributeValueService = new AttributeValueService(); int? iEntityId = null; if ( entityId != "null" ) try { iEntityId = Int32.Parse( entityId ); } catch { } var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attributeId, iEntityId ); if ( attributeValue != null ) { string clientUpdateScript = fieldType.Field.ClientUpdateScript( this.Page, "0", attributeValue.Value, "attribute_value_" + BlockInstance.Id.ToString(), hfAttributeValue.ClientID ) + "(\"" + attributeValue.Value.EscapeQuotes() + "\");"; lValue.Text = fieldType.Field.FormatValue( lValue, attributeValue.Value, true ); aEdit.Attributes.Add( "onclick", string.Format( "editValue({0}, {1}, '{2}', '{3}');", attributeId, attributeValue.Id, attributeValue.Value.EscapeQuotes(), clientUpdateScript ) ); } else { string clientUpdateScript = fieldType.Field.ClientUpdateScript( this.Page, "0", string.Empty, "attribute_value_" + BlockInstance.Id.ToString(), hfAttributeValue.ClientID ) + "('');"; aEdit.Attributes.Add( "onclick", string.Format( "editValue({0}, 0, '', \"{1}\");", attributeId, clientUpdateScript ) ); } } } }
private void BindGrid() { using ( new Rock.Data.UnitOfWorkScope() ) { AttributeService attributeService = new AttributeService(); var queryable = attributeService. Queryable(). Where( a => a.Entity == entity && ( a.EntityQualifierColumn ?? string.Empty ) == entityQualifierColumn && ( a.EntityQualifierValue ?? string.Empty ) == entityQualifierValue ); if ( ddlCategoryFilter.SelectedValue != "[All]" ) queryable = queryable. Where( a => a.Category == ddlCategoryFilter.SelectedValue ); rGrid.DataSource = queryable. OrderBy( a => a.Category ). ThenBy( a => a.Name ). Select( a => new { a.Id, a.Category, a.Name, a.Description, a.DefaultValue } ). ToList(); rGrid.DataBind(); } }
void rGrid_RowDataBound( object sender, GridViewRowEventArgs e ) { if ( e.Row.RowType == DataControlRowType.DataRow ) { Literal lValue = e.Row.FindControl( "lValue" ) as Literal; if ( lValue != null ) { int attributeId = ( int )rGrid.DataKeys[e.Row.RowIndex].Value; AttributeService attributeService = new AttributeService(); var attribute = attributeService.Get( attributeId ); var fieldType = Rock.Web.Cache.FieldType.Read( attribute.FieldTypeId ); AttributeValueService attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attributeId, _entityId ).FirstOrDefault(); if ( attributeValue != null ) lValue.Text = fieldType.Field.FormatValue( lValue, attributeValue.Value, true ); } } }
void modalDetails_SaveClick( object sender, EventArgs e ) { int attributeId = 0; if ( hfId.Value != string.Empty && !Int32.TryParse( hfId.Value, out attributeId ) ) attributeId = 0; if ( attributeId != 0 && phEditControl.Controls.Count > 0 ) { AttributeService attributeService = new AttributeService(); var attribute = attributeService.Get( attributeId ); AttributeValueService attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attributeId, _entityId ).FirstOrDefault(); if ( attributeValue == null ) { attributeValue = new Rock.Core.AttributeValue(); attributeValue.AttributeId = attributeId; attributeValue.EntityId = _entityId; attributeValueService.Add( attributeValue, CurrentPersonId ); } var fieldType = Rock.Web.Cache.FieldType.Read( attribute.FieldTypeId ); attributeValue.Value = fieldType.Field.ReadValue( phEditControl.Controls[0] ); attributeValueService.Save(attributeValue, CurrentPersonId); Rock.Web.Cache.Attribute.Flush( attributeId ); } modalDetails.Hide(); BindGrid(); }
protected void ShowEdit( int attributeId, bool setValues ) { AttributeService attributeService = new AttributeService(); var attribute = attributeService.Get( attributeId ); hfId.Value = attribute.Id.ToString(); lCaption.Text = attribute.Name; AttributeValueService attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attributeId, _entityId ).FirstOrDefault(); var fieldType = Rock.Web.Cache.FieldType.Read( attribute.FieldTypeId ); phEditControl.Controls.Clear(); phEditControl.Controls.Add(fieldType.Field.CreateControl((attributeValue != null ? attributeValue.Value : string.Empty), attribute.Required, setValues)); modalDetails.Show(); }