/// <summary> /// Sets the value. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="currentPersonId">The current person id.</param> /// <param name="saveValue">if set to <c>true</c> [save value].</param> public void SetValue(string key, string value, int?currentPersonId, bool saveValue) { if (saveValue) { // Save new value var attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.GetGlobalAttributeValue(key); if (attributeValue == null) { var attributeService = new AttributeService(); var attribute = attributeService.GetGlobalAttribute(key); if (attribute != null) { attributeValue = new AttributeValue(); attributeValue.IsSystem = false; attributeValue.AttributeId = attribute.Id; attributeValue.Value = value; attributeValueService.Save(attributeValue, currentPersonId); } } else { attributeValue.Value = value; attributeValueService.Save(attributeValue, currentPersonId); } } // Update cached value if (AttributeValues != null && AttributeValues.Keys.Contains(key)) { string attributeName = AttributeValues[key].Key; AttributeValues[key] = new KeyValuePair <string, string>(attributeName, value); } }
void lvAttributeValues_ItemInserting(object sender, ListViewInsertEventArgs e) { PlaceHolder phInsertValue = lvAttributeValues.InsertItem.FindControl("phInsertValue") as PlaceHolder; if (phInsertValue != null && phInsertValue.Controls.Count == 1) { string value = _attribute.FieldType.Field.GetEditValue(phInsertValue.Controls[0], _attribute.QualifierValues); var attributeValueService = new AttributeValueService(); var attributeValue = new AttributeValue(); attributeValue.AttributeId = _attribute.Id; attributeValue.EntityId = _model.Id; attributeValue.Value = value; int?maxOrder = attributeValueService.Queryable(). Where(a => a.AttributeId == attributeValue.AttributeId && a.EntityId == attributeValue.EntityId). Select(a => ( int? )a.Order).Max(); attributeValue.Order = maxOrder.HasValue ? maxOrder.Value + 1 : 0; attributeValueService.Add(attributeValue, _currentPersonId); attributeValueService.Save(attributeValue, _currentPersonId); _model.LoadAttributes(); } lvAttributeValues.EditIndex = -1; BindData(); }
void lvAttributeValues_ItemUpdating(object sender, ListViewUpdateEventArgs e) { PlaceHolder phEditValue = lvAttributeValues.EditItem.FindControl("phEditValue") as PlaceHolder; if (phEditValue != null && phEditValue.Controls.Count == 1) { string value = _attribute.FieldType.Field.GetEditValue(phEditValue.Controls[0], _attribute.QualifierValues); var attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.Get(( int )e.Keys["Id"]); if (attributeValue == null) { attributeValue = new AttributeValue(); attributeValueService.Add(attributeValue, _currentPersonId); attributeValue.AttributeId = _attribute.Id; attributeValue.EntityId = _model.Id; } attributeValue.Value = value; attributeValueService.Save(attributeValue, _currentPersonId); _model.LoadAttributes(); } lvAttributeValues.EditIndex = -1; BindData(); }
/// <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 ); } }
/// <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); } }
/// <summary> /// Sets the value. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="currentPersonId">The current person id.</param> /// <param name="saveValue">if set to <c>true</c> [save value].</param> public void SetValue(string key, string value, int?currentPersonId, bool saveValue) { if (saveValue) { using (new Rock.Data.UnitOfWorkScope()) { // Save new value var attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.GetGlobalAttributeValue(key); if (attributeValue == null) { var attributeService = new AttributeService(); var attribute = attributeService.GetGlobalAttribute(key); if (attribute == null) { attribute = new Rock.Model.Attribute(); attribute.FieldTypeId = FieldTypeCache.Read(new Guid(SystemGuid.FieldType.TEXT)).Id; attribute.EntityTypeQualifierColumn = string.Empty; attribute.EntityTypeQualifierValue = string.Empty; attribute.Key = key; attribute.Name = key.SplitCase(); attributeService.Add(attribute, currentPersonId); attributeService.Save(attribute, currentPersonId); Attributes.Add(AttributeCache.Read(attribute.Id)); } attributeValue = new AttributeValue(); attributeValueService.Add(attributeValue, currentPersonId); attributeValue.IsSystem = false; attributeValue.AttributeId = attribute.Id; if (!AttributeValues.Keys.Contains(key)) { AttributeValues.Add(key, new KeyValuePair <string, string>(attribute.Name, value)); } } attributeValue.Value = value; attributeValueService.Save(attributeValue, currentPersonId); } } var attributeCache = Attributes.FirstOrDefault(a => a.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); if (attributeCache != null) // (Should never be null) { if (AttributeValues.Keys.Contains(key)) { AttributeValues[key] = new KeyValuePair <string, string>(attributeCache.Name, value); } else { AttributeValues.Add(key, new KeyValuePair <string, string>(attributeCache.Name, value)); } } }
void lvAttributeValues_ItemDeleting(object sender, ListViewDeleteEventArgs e) { var attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.Get(( int )e.Keys["Id"]); if (attributeValue != null) { attributeValueService.Delete(attributeValue, _currentPersonId); attributeValueService.Save(attributeValue, _currentPersonId); _model.LoadAttributes(); } BindData(); }
/// <summary> /// Handles the SaveClick event of the modalDetails 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 modalDetails_SaveClick(object sender, EventArgs e) { if (_displayValueEdit) { int attributeId = 0; if (hfIdValues.Value != string.Empty && !int.TryParse(hfIdValues.Value, out attributeId)) { attributeId = 0; } if (attributeId != 0 && fsEditControl.Controls.Count > 0) { var attribute = Rock.Web.Cache.AttributeCache.Read(attributeId); AttributeValueService attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attributeId, _entityId).FirstOrDefault(); if (attributeValue == null) { attributeValue = new Rock.Model.AttributeValue(); attributeValue.AttributeId = attributeId; attributeValue.EntityId = _entityId; attributeValueService.Add(attributeValue, CurrentPersonId); } var fieldType = Rock.Web.Cache.FieldTypeCache.Read(attribute.FieldType.Id); attributeValue.Value = fieldType.Field.GetEditValue(attribute.GetControl(fsEditControl.Controls[0]), attribute.QualifierValues); attributeValueService.Save(attributeValue, CurrentPersonId); Rock.Web.Cache.AttributeCache.Flush(attributeId); if (!_entityTypeId.HasValue && _entityQualifierColumn == string.Empty && _entityQualifierValue == string.Empty && !_entityId.HasValue) { Rock.Web.Cache.GlobalAttributesCache.Flush(); } } hfIdValues.Value = string.Empty; modalDetails.Hide(); } BindGrid(); }
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(); }
void lvAttributeValues_ItemUpdating( object sender, ListViewUpdateEventArgs e ) { PlaceHolder phEditValue = lvAttributeValues.EditItem.FindControl( "phEditValue" ) as PlaceHolder; if ( phEditValue != null && phEditValue.Controls.Count == 1 ) { string value = _attribute.FieldType.Field.ReadValue( phEditValue.Controls[0] ); var attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.Get( ( int )e.Keys["Id"] ); if ( attributeValue == null ) { attributeValue = new AttributeValue(); attributeValueService.Add( attributeValue, _currentPersonId ); attributeValue.AttributeId = _attribute.Id; attributeValue.EntityId = _model.Id; } attributeValue.Value = value; attributeValueService.Save( attributeValue, _currentPersonId ); Rock.Attribute.Helper.LoadAttributes( _model ); } lvAttributeValues.EditIndex = -1; BindData(); }
void lvAttributeValues_ItemInserting( object sender, ListViewInsertEventArgs e ) { PlaceHolder phInsertValue = lvAttributeValues.InsertItem.FindControl( "phInsertValue" ) as PlaceHolder; if ( phInsertValue != null && phInsertValue.Controls.Count == 1 ) { string value = _attribute.FieldType.Field.ReadValue( phInsertValue.Controls[0] ); var attributeValueService = new AttributeValueService(); var attributeValue = new AttributeValue(); attributeValue.AttributeId = _attribute.Id; attributeValue.EntityId = _model.Id; attributeValue.Value = value; int? maxOrder = attributeValueService.Queryable(). Where( a => a.AttributeId == attributeValue.AttributeId && a.EntityId == attributeValue.EntityId). Select( a => ( int? )a.Order ).Max(); attributeValue.Order = maxOrder.HasValue ? maxOrder.Value + 1 : 0; attributeValueService.Add( attributeValue, _currentPersonId); attributeValueService.Save( attributeValue, _currentPersonId ); Rock.Attribute.Helper.LoadAttributes( _model ); } lvAttributeValues.EditIndex = -1; BindData(); }
void lvAttributeValues_ItemDeleting( object sender, ListViewDeleteEventArgs e ) { var attributeValueService = new AttributeValueService(); var attributeValue = attributeValueService.Get( ( int )e.Keys["Id"] ); if ( attributeValue != null ) { attributeValueService.Delete( attributeValue, _currentPersonId ); attributeValueService.Save( attributeValue, _currentPersonId ); Rock.Attribute.Helper.LoadAttributes( _model ); } BindData(); }
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(); }