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();
                }
            }
        }
コード例 #2
0
        /// <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();
                }
            }
        }
コード例 #3
0
        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";
            }
        }
コード例 #4
0
        /// <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;
        }
コード例 #5
0
        /// <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();
        }