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


C# PersonService.SetAttributeValue方法代码示例

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


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

示例1: rSelection_ItemCommand

        protected void rSelection_ItemCommand( object source, RepeaterCommandEventArgs e )
        {
            if ( KioskCurrentlyActive )
            {
                var person = CurrentCheckInState.CheckIn.Families.Where( f => f.Selected )
                    .SelectMany( f => f.People.Where( p => p.Selected ) )
                    .FirstOrDefault();

                if ( person != null )
                {
                    string selectedAbilityLevelGuid = e.CommandArgument.ToString();

                    //person.Person.LoadAttributes();
                    _personAbilityLevelGuid = person.Person.GetAttributeValue( "AbilityLevel" ).ToUpper();

                    // Only save the ability level if it's changed
                    if ( _personAbilityLevelGuid != selectedAbilityLevelGuid )
                    {
                        // Need to load a fully hydrated person because the person.Person is only a clone.
                        using ( var rockContext = new RockContext() )
                        {
                            Person p = new PersonService( rockContext ).Get( person.Person.Id );
                            if ( p != null )
                            {
                                p.LoadAttributes( rockContext );
                                p.SetAttributeValue( "AbilityLevel", selectedAbilityLevelGuid.ToUpperInvariant() );
                                p.SaveAttributeValues( rockContext );
                            }
                        }
                    }

                    ProcessSelection();
                }
            }
        }
开发者ID:Higherbound,项目名称:Higherbound-2016-website-upgrades,代码行数:35,代码来源:AbilityLevelSelect.ascx.cs

示例2: rSelection_ItemCommand

        /// <summary>
        /// Handles the ItemCommand event of the rSelection control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="RepeaterCommandEventArgs"/> instance containing the event data.</param>
        protected void rSelection_ItemCommand( object source, RepeaterCommandEventArgs e )
        {
            if ( KioskCurrentlyActive )
            {
                var person = CurrentCheckInState.CheckIn.CurrentPerson;
                if ( person != null )
                {
                    string selectedAbilityLevelGuid = e.CommandArgument.ToString();

                    //person.Person.LoadAttributes();
                    _personAbilityLevelGuid = person.Person.GetAttributeValue( "AbilityLevel" ).ToUpper();

                    // Save the fact that user has already selected an ability level so they won't be asked again
                    person.StateParameters.AddOrReplace( "AbilityLevel", _personAbilityLevelGuid.ToString() );

                    // Only save the ability level if it's changed
                    if ( _personAbilityLevelGuid != selectedAbilityLevelGuid )
                    {
                        // Need to load a fully hydrated person because the person.Person is only a clone.
                        using ( var rockContext = new RockContext() )
                        {
                            Person p = new PersonService( rockContext ).Get( person.Person.Id );
                            if ( p != null )
                            {
                                p.LoadAttributes( rockContext );
                                p.SetAttributeValue( "AbilityLevel", selectedAbilityLevelGuid.ToUpperInvariant() );
                                p.SaveAttributeValues( rockContext );
                                person.Person.LoadAttributes( rockContext );
                            }
                        }
                    }

                    ProcessSelection();
                }
            }
        }
开发者ID:NewSpring,项目名称:Rock,代码行数:41,代码来源:AbilityLevelSelect.ascx.cs

示例3: CreatePerson

        /// <summary>
        /// Adds a new person.
        /// </summary>
        /// <param name="firstName">The first name.</param>
        /// <param name="lastName">The last name.</param>
        /// <param name="DOB">The DOB.</param>
        /// <param name="gender">The gender</param>
        /// <param name="attribute">The attribute.</param>
        protected Person CreatePerson( string firstName, string lastName, DateTime? dob, int? gender, string ability, string abilityGroup )
        {
            Person person = new Person();
            person.FirstName = firstName;
            person.LastName = lastName;
            person.BirthDate = dob;

            if ( gender != null )
            {
                person.Gender = (Gender)gender;
            }

            if ( !string.IsNullOrWhiteSpace( ability ) && abilityGroup == "Grade" )
            {
                person.Grade = (int)ability.ConvertToEnum<GradeLevel>();
            }

            var rockContext = new RockContext();
            PersonService ps = new PersonService( rockContext );
            ps.Add( person );
            rockContext.SaveChanges();

            if ( !string.IsNullOrWhiteSpace( ability ) &&  abilityGroup == "Ability" )
            {
                rockContext = new RockContext();
                Person p = new PersonService( rockContext ).Get( person.Id );
                if ( p != null )
                {
                    p.LoadAttributes( rockContext );
                    p.SetAttributeValue( "AbilityLevel", ability );
                    p.SaveAttributeValues(  );
                }
            }

            return person;
        }
开发者ID:CentralAZ,项目名称:Rockit-CentralAZ,代码行数:44,代码来源:FamilySelect.ascx.cs

示例4: lbNext_Click

        protected void lbNext_Click( object sender, EventArgs e )
        {
            _saveNavigationHistory = true;

            CurrentPageIndex++;

            bool saveEachPage = GetAttributeValue( "SaveValues" ) == "PAGE";
            if ( saveEachPage || CurrentPageIndex >= FormState.Count )
            {
                if ( CurrentPersonId.HasValue )
                {
                    using ( var rockContext = new RockContext() )
                    {
                        var person = new PersonService( rockContext ).Get( CurrentPersonId.Value );
                        if ( person != null )
                        {
                            person.LoadAttributes( rockContext );

                            var pageAttributeIds = new List<int>(); ;
                            if ( saveEachPage && CurrentPageIndex > 0 && CurrentPageIndex <= FormState.Count )
                            {
                                pageAttributeIds = FormState[CurrentPageIndex - 1].Fields
                                    .Where( f => f.AttributeId.HasValue )
                                    .Select( f => f.AttributeId.Value )
                                    .ToList();
                            }

                            foreach ( var keyVal in AttributeValueState )
                            {
                                var attribute = AttributeCache.Read( keyVal.Key );
                                if ( attribute != null && ( CurrentPageIndex >= FormState.Count || !pageAttributeIds.Any() || pageAttributeIds.Contains( attribute.Id ) ) )
                                {
                                    person.SetAttributeValue( attribute.Key, keyVal.Value );
                                }
                            }

                            person.SaveAttributeValues( rockContext );

                            if ( CurrentPageIndex >= FormState.Count )
                            {
                                WorkflowType workflowType = null;
                                Guid? workflowTypeGuid = GetAttributeValue( "Workflow" ).AsGuidOrNull();
                                if ( workflowTypeGuid.HasValue )
                                {
                                    var workflowTypeService = new WorkflowTypeService( rockContext );
                                    workflowType = workflowTypeService.Get( workflowTypeGuid.Value );
                                    if ( workflowType != null )
                                    {
                                        try
                                        {
                                            var workflow = Workflow.Activate( workflowType, person.FullName );
                                            List<string> workflowErrors;
                                            new WorkflowService( rockContext ).Process( workflow, person, out workflowErrors );
                                        }
                                        catch ( Exception ex )
                                        {
                                            ExceptionLogService.LogException( ex, this.Context );
                                        }
                                    }
                                }

                                if ( GetAttributeValue( "DonePage" ).AsGuidOrNull().HasValue )
                                {
                                    NavigateToLinkedPage( "DonePage" );
                                }
                                else
                                {
                                    pnlView.Visible = false;
                                }
                                upnlContent.Update();
                            }
                            else
                            {
                                ShowPage();
                                hfTriggerScroll.Value = "true";
                            }
                        }
                    }
                }
            }
            else
            {
                ShowPage();
                hfTriggerScroll.Value = "true";
            }
        }
开发者ID:NewPointe,项目名称:Rockit,代码行数:86,代码来源:PersonAttributeForms.ascx.cs

示例5: CreatePerson

        /// <summary>
        /// Adds a new person.
        /// </summary>
        /// <param name="firstName">The first name.</param>
        /// <param name="lastName">The last name.</param>
        /// <param name="DOB">The DOB.</param>
        /// <param name="gender">The gender</param>
        /// <param name="attribute">The attribute.</param>
        protected Person CreatePerson( string firstName, string lastName, DateTime? dob, int? gender, string ability, string abilityGroup )
        {
            Person person = new Person().Clone( false );
            person.FirstName = firstName;
            person.LastName = lastName;
            person.BirthDate = dob;

            if ( gender != null )
            {
                person.Gender = (Gender)gender;
            }

            PersonService ps = new PersonService();
            Rock.Data.RockTransactionScope.WrapTransaction( () =>
            {
                ps.Add( person, CurrentPersonId );
                ps.Save( person, CurrentPersonId );
            } );

            if ( !string.IsNullOrWhiteSpace( ability ) )
            {
                if ( abilityGroup == "Grade" )
                {
                    person.Grade = (int)ability.ConvertToEnum<GradeLevel>();
                    ps.Save( person, CurrentPersonId );
                }
                else if ( abilityGroup == "Ability" )
                {
                    Person p = new PersonService().Get( person.Id );
                    if ( p != null )
                    {
                        p.LoadAttributes();
                        p.SetAttributeValue( "AbilityLevel", ability );
                        Rock.Attribute.Helper.SaveAttributeValues( p, CurrentPersonId );
                    }
                }
            }

            return person;
        }
开发者ID:pkdevbox,项目名称:Rock,代码行数:48,代码来源:FamilySelect.ascx.cs

示例6: lbSaveEditInfo_Click

        /// <summary>
        /// Handles the Click event of the lbSaveEditInfo 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 lbSaveEditInfo_Click( object sender, EventArgs e )
        {
            if ( string.IsNullOrEmpty( tbFirstName.Text ) || string.IsNullOrEmpty( tbLastName.Text ) || string.IsNullOrEmpty( dpDOB.Text ) )
            {
                Page.Validate( "Person" );
                mdlInfo.Show();
                return;
            }

            CheckInPerson currentPerson = GetCurrentPerson();
            var rockContext = new RockContext();
            Person person = new PersonService( rockContext ).Get( currentPerson.Person.Id );
            person.LoadAttributes();

            person.FirstName = tbFirstName.Text;
            currentPerson.Person.FirstName = tbFirstName.Text;

            person.LastName = tbLastName.Text;
            currentPerson.Person.LastName = tbLastName.Text;

            person.SuffixValueId = ddlSuffix.SelectedValueAsId();
            currentPerson.Person.SuffixValueId = ddlSuffix.SelectedValueAsId();

            var DOB = dpDOB.SelectedDate;
            if ( DOB != null )
            {
                person.BirthDay = ( (DateTime)DOB ).Day;
                currentPerson.Person.BirthDay = ( (DateTime)DOB ).Day;
                person.BirthMonth = ( (DateTime)DOB ).Month;
                currentPerson.Person.BirthMonth = ( (DateTime)DOB ).Month;
                person.BirthYear = ( (DateTime)DOB ).Year;
                currentPerson.Person.BirthYear = ( (DateTime)DOB ).Year;
            }

            person.NickName = tbNickname.Text.Length > 0 ? tbNickname.Text : tbFirstName.Text;
            currentPerson.Person.NickName = tbNickname.Text.Length > 0 ? tbNickname.Text : tbFirstName.Text;
            var optionGroup = ddlAbilityGrade.SelectedItem.Attributes["optiongroup"];

            if ( !string.IsNullOrEmpty( optionGroup ) )
            {
                // Selected ability level
                if ( optionGroup == "Ability" )
                {
                    person.SetAttributeValue( "AbilityLevel", ddlAbilityGrade.SelectedValue );
                    currentPerson.Person.SetAttributeValue( "AbilityLevel", ddlAbilityGrade.SelectedValue );

                    person.GradeOffset = null;
                    currentPerson.Person.GradeOffset = null;
                }
                // Selected a grade
                else if ( optionGroup == "Grade" )
                {
                    person.GradeOffset = ddlAbilityGrade.SelectedValueAsId();
                    currentPerson.Person.GradeOffset = ddlAbilityGrade.SelectedValueAsId();

                    person.Attributes.Remove( "AbilityLevel" );
                    currentPerson.Person.Attributes.Remove( "AbilityLevel" );
                }
            }

            // Always save the special needs value
            person.SetAttributeValue( SpecialNeedsKey, cbSpecialNeeds.Checked ? "Yes" : string.Empty );
            currentPerson.Person.SetAttributeValue( SpecialNeedsKey, cbSpecialNeeds.Checked ? "Yes" : string.Empty );

            // store the allergies
            var allergyAttribute = Rock.Web.Cache.AttributeCache.Read( new Guid( Rock.SystemGuid.Attribute.PERSON_ALLERGY ), rockContext );
            var allergyAttributeControl = phAttributes.FindControl( string.Format( "attribute_field_{0}", allergyAttribute.Id ) );
            if ( allergyAttributeControl != null )
            {
                person.SetAttributeValue( "Allergy", allergyAttribute.FieldType.Field
                    .GetEditValue( allergyAttributeControl, allergyAttribute.QualifierValues ) );
                currentPerson.Person.SetAttributeValue( "Allergy", allergyAttribute.FieldType.Field
                    .GetEditValue( allergyAttributeControl, allergyAttribute.QualifierValues ) );
            }

            // store the check-in notes
            person.SetAttributeValue( "LegalNotes", tbNoteText.Text );
            currentPerson.Person.SetAttributeValue( "LegalNotes", tbNoteText.Text );

            // Save the attribute change to the db (CheckinPerson already tracked)
            person.SaveAttributeValues();
            rockContext.SaveChanges();
            mdlInfo.Hide();
        }
开发者ID:NewSpring,项目名称:rock-attended-checkin,代码行数:89,代码来源:ActivitySelect.ascx.cs


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