当前位置: 首页>>代码示例>>C#>>正文


C# PersonAliasService.GetAttributeValue方法代码示例

本文整理汇总了C#中Rock.Model.PersonAliasService.GetAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:C# PersonAliasService.GetAttributeValue方法的具体用法?C# PersonAliasService.GetAttributeValue怎么用?C# PersonAliasService.GetAttributeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rock.Model.PersonAliasService的用法示例。


在下文中一共展示了PersonAliasService.GetAttributeValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute( RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages )
        {
            errorMessages = new List<string>();

            string updateValue = GetAttributeValue( action, "Value" );
            Guid? valueGuid = updateValue.AsGuidOrNull();
            if ( valueGuid.HasValue )
            {
                updateValue = action.GetWorklowAttributeValue( valueGuid.Value );
            }
            else
            {
                updateValue = updateValue.ResolveMergeFields( GetMergeFields( action ) );
            }

            string personAttribute = GetAttributeValue( action, "PersonAttribute" );

            Guid guid = personAttribute.AsGuid();
            if (!guid.IsEmpty())
            {
                var attribute = AttributeCache.Read( guid, rockContext );
                if ( attribute != null )
                {
                    string value = GetAttributeValue( action, "Person" );
                    guid = value.AsGuid();
                    if ( !guid.IsEmpty() )
                    {
                        var attributePerson = AttributeCache.Read( guid, rockContext );
                        if ( attributePerson != null )
                        {
                            string attributePersonValue = action.GetWorklowAttributeValue( guid );
                            if ( !string.IsNullOrWhiteSpace( attributePersonValue ) )
                            {
                                if ( attributePerson.FieldType.Class == "Rock.Field.Types.PersonFieldType" )
                                {
                                    Guid personAliasGuid = attributePersonValue.AsGuid();
                                    if ( !personAliasGuid.IsEmpty() )
                                    {
                                        var person = new PersonAliasService( rockContext ).Queryable()
                                            .Where( a => a.Guid.Equals( personAliasGuid ) )
                                            .Select( a => a.Person )
                                            .FirstOrDefault();
                                        if ( person != null )
                                        {
                                            // update person attribute
                                            person.LoadAttributes();
                                            string originalValue = person.GetAttributeValue( attribute.Key );

                                            // Handle encrypted text fields as well.
                                            if ( attribute.FieldType.Field is Field.Types.EncryptedTextFieldType )
                                            {
                                                updateValue = Security.Encryption.EncryptString( updateValue );
                                            }

                                            Rock.Attribute.Helper.SaveAttributeValue( person, attribute, updateValue, rockContext );

                                            if ( ( originalValue ?? string.Empty ).Trim() != ( updateValue ?? string.Empty ).Trim() )
                                            {
                                                var changes = new List<string>();

                                                string formattedOriginalValue = string.Empty;
                                                if ( !string.IsNullOrWhiteSpace( originalValue ) )
                                                {
                                                    formattedOriginalValue = attribute.FieldType.Field.FormatValue( null, originalValue, attribute.QualifierValues, false );
                                                }

                                                string formattedNewValue = string.Empty;
                                                if ( !string.IsNullOrWhiteSpace( updateValue ) )
                                                {
                                                    formattedNewValue = attribute.FieldType.Field.FormatValue( null, updateValue, attribute.QualifierValues, false );
                                                }

                                                History.EvaluateChange( changes, attribute.Name, formattedOriginalValue, formattedNewValue, attribute.FieldType.Field.IsSensitive() );
                                                if ( changes.Any() )
                                                {
                                                    HistoryService.SaveChanges( rockContext, typeof( Person ),
                                                        Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(),
                                                        person.Id, changes );
                                                }
                                            }

                                            action.AddLogEntry( string.Format( "Set '{0}' attribute to '{1}'.", attribute.Name, updateValue ) );
                                            return true;

                                        }
                                        else
                                        {
                                            errorMessages.Add( string.Format( "Person could not be found for selected value ('{0}')!", guid.ToString() ) );
                                        }
                                    }
                                }
                                else
//.........这里部分代码省略.........
开发者ID:NewSpring,项目名称:Rock,代码行数:101,代码来源:SetPersonAttribute.cs


注:本文中的Rock.Model.PersonAliasService.GetAttributeValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。