Beispiel #1
0
        /// <summary>
        /// Saves the attribute value.
        /// </summary>
        /// <param name="workflow">The workflow.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <param name="fieldType">Type of the field.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="qualifiers">The qualifiers.</param>
        /// <returns></returns>
        private static bool SaveAttributeValue(Rock.Model.Workflow workflow, string key, string value,
                                               FieldTypeCache fieldType, RockContext rockContext, Dictionary <string, string> qualifiers = null)
        {
            bool createdNewAttribute = false;

            if (workflow.Attributes.ContainsKey(key))
            {
                workflow.SetAttributeValue(key, value);
            }
            else
            {
                // Read the attribute
                var attributeService = new AttributeService(rockContext);
                var attribute        = attributeService
                                       .Get(workflow.TypeId, "WorkflowTypeId", workflow.WorkflowTypeId.ToString())
                                       .Where(a => a.Key == key)
                                       .FirstOrDefault();

                // If workflow attribute doesn't exist, create it
                // ( should only happen first time a background check is processed for given workflow type)
                if (attribute == null)
                {
                    attribute = new Rock.Model.Attribute();
                    attribute.EntityTypeId = workflow.TypeId;
                    attribute.EntityTypeQualifierColumn = "WorkflowTypeId";
                    attribute.EntityTypeQualifierValue  = workflow.WorkflowTypeId.ToString();
                    attribute.Name        = key.SplitCase();
                    attribute.Key         = key;
                    attribute.FieldTypeId = fieldType.Id;
                    attributeService.Add(attribute);

                    if (qualifiers != null)
                    {
                        foreach (var keyVal in qualifiers)
                        {
                            var qualifier = new Rock.Model.AttributeQualifier();
                            qualifier.Key   = keyVal.Key;
                            qualifier.Value = keyVal.Value;
                            attribute.AttributeQualifiers.Add(qualifier);
                        }
                    }

                    createdNewAttribute = true;
                }

                // Set the value for this action's instance to the current time
                var attributeValue = new Rock.Model.AttributeValue();
                attributeValue.Attribute = attribute;
                attributeValue.EntityId  = workflow.Id;
                attributeValue.Value     = value;
                new AttributeValueService(rockContext).Add(attributeValue);
            }

            return(createdNewAttribute);
        }
 /// <summary>
 /// Copies the properties from another AttributeQualifier object to this AttributeQualifier object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this AttributeQualifier target, AttributeQualifier source)
 {
     target.Id          = source.Id;
     target.AttributeId = source.AttributeId;
     target.ForeignGuid = source.ForeignGuid;
     target.ForeignKey  = source.ForeignKey;
     target.IsSystem    = source.IsSystem;
     target.Key         = source.Key;
     target.Value       = source.Value;
     target.Guid        = source.Guid;
     target.ForeignId   = source.ForeignId;
 }
 /// <summary>
 /// Clones this AttributeQualifier object to a new AttributeQualifier object
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param>
 /// <returns></returns>
 public static AttributeQualifier Clone(this AttributeQualifier source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as AttributeQualifier);
     }
     else
     {
         var target = new AttributeQualifier();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Clones this AttributeQualifier object to a new AttributeQualifier object with default values for the properties in the Entity and Model base classes.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static AttributeQualifier CloneWithoutIdentity(this AttributeQualifier source)
        {
            var target = new AttributeQualifier();

            target.CopyPropertiesFrom(source);

            target.Id          = 0;
            target.Guid        = Guid.NewGuid();
            target.ForeignKey  = null;
            target.ForeignId   = null;
            target.ForeignGuid = null;

            return(target);
        }
        private static void SaveAttributeValue( Rock.Model.Workflow workflow, string key, string value, 
            FieldTypeCache fieldType, RockContext rockContext, Dictionary<string, string> qualifiers = null )
        {
            if (workflow.Attributes.ContainsKey(key))
            {
                workflow.SetAttributeValue( key, value );
            }
            else
            {
                // If workflow attribute doesn't exist, create it
                // ( should only happen first time a background check is processed for given workflow type)
                var attribute = new Rock.Model.Attribute();
                attribute.EntityTypeId = workflow.WorkflowType.TypeId;
                attribute.EntityTypeQualifierColumn = "WorkflowTypeId";
                attribute.EntityTypeQualifierValue = workflow.WorkflowTypeId.ToString();
                attribute.Name = key.SplitCase();
                attribute.Key = key;
                attribute.FieldTypeId = fieldType.Id;

                if ( qualifiers != null )
                {
                    foreach( var keyVal in qualifiers )
                    {
                        var qualifier = new Rock.Model.AttributeQualifier();
                        qualifier.Key = keyVal.Key;
                        qualifier.Value = keyVal.Value;
                        attribute.AttributeQualifiers.Add( qualifier );
                    }
                }

                // Set the value for this action's instance to the current time
                var attributeValue = new Rock.Model.AttributeValue();
                attributeValue.Attribute = attribute;
                attributeValue.EntityId = workflow.Id;
                attributeValue.Value = value;
                new AttributeValueService( rockContext ).Add( attributeValue );
            }
        }
 /// <summary>
 /// Instantiates a new DTO object from the entity
 /// </summary>
 /// <param name="attributeQualifier"></param>
 public AttributeQualifierDto(AttributeQualifier attributeQualifier)
 {
     CopyFromModel(attributeQualifier);
 }
 /// <summary>
 /// To the dto.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public static AttributeQualifierDto ToDto(this AttributeQualifier value)
 {
     return(new AttributeQualifierDto(value));
 }