/// <summary>
 /// Shows the person view.
 /// </summary>
 /// <param name="familyPersonState">State of the family person.</param>
 private void ShowPersonView(FamilyRegistrationState.FamilyPersonState familyPersonState)
 {
     pnlEditFamily.Visible = false;
     pnlEditPerson.Visible = true;
     mdEditFamily.Title    = familyPersonState.FullName;
     upContent.Update();
 }
Beispiel #2
0
        /// <summary>
        /// Creates the dynamic person controls.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        private void CreateDynamicPersonControls(FamilyRegistrationState.FamilyPersonState familyPersonState)
        {
            var fakePerson    = new Person();
            var attributeList = familyPersonState.PersonAttributeValuesState.Select(a => AttributeCache.Get(a.Value.AttributeId)).ToList();

            fakePerson.Attributes      = attributeList.ToDictionary(a => a.Key, v => v);
            fakePerson.AttributeValues = familyPersonState.PersonAttributeValuesState;

            var adultAttributeKeysToEdit = this.RequiredAttributesForAdults.OrderBy(a => a.Order).ToList();

            adultAttributeKeysToEdit.AddRange(this.OptionalAttributesForAdults.OrderBy(a => a.Order).ToList());

            avcAdultAttributes.IncludedAttributes = adultAttributeKeysToEdit.ToArray();
            avcAdultAttributes.ValidationGroup    = btnDonePerson.ValidationGroup;
            avcAdultAttributes.NumberOfColumns    = 2;
            avcAdultAttributes.ShowCategoryLabel  = false;
            avcAdultAttributes.AddEditControls(fakePerson);

            var childAttributeKeysToEdit = this.RequiredAttributesForChildren.OrderBy(a => a.Order).ToList();

            childAttributeKeysToEdit.AddRange(this.OptionalAttributesForChildren.OrderBy(a => a.Order).ToList());

            avcChildAttributes.IncludedAttributes = childAttributeKeysToEdit.ToArray();
            avcChildAttributes.ValidationGroup    = btnDonePerson.ValidationGroup;
            avcChildAttributes.NumberOfColumns    = 2;
            avcChildAttributes.ShowCategoryLabel  = false;
            avcChildAttributes.AddEditControls(fakePerson);

            // override the attribute's IsRequired and set Required based on whether the attribute is part of the Required or Optional set of attributes for the Registration
            foreach (Control attributeControl in avcAdultAttributes.ControlsOfTypeRecursive <Control>().OfType <Control>())
            {
                if (attributeControl is IHasRequired && attributeControl.ID.IsNotNullOrWhiteSpace())
                {
                    int?attributeControlAttributeId = attributeControl.ID.Replace("attribute_field_", string.Empty).AsIntegerOrNull();
                    if (attributeControlAttributeId.HasValue)
                    {
                        (attributeControl as IHasRequired).Required = this.RequiredAttributesForAdults.Any(a => a.Id == attributeControlAttributeId.Value);
                    }
                }
            }

            foreach (Control attributeControl in avcChildAttributes.ControlsOfTypeRecursive <Control>().OfType <Control>())
            {
                if (attributeControl is IHasRequired && attributeControl.ID.IsNotNullOrWhiteSpace())
                {
                    int?attributeControlAttributeId = attributeControl.ID.Replace("attribute_field_", string.Empty).AsIntegerOrNull();
                    if (attributeControlAttributeId.HasValue)
                    {
                        (attributeControl as IHasRequired).Required = this.RequiredAttributesForChildren.Any(a => a.Id == attributeControlAttributeId.Value);
                    }
                }
            }
        }
        /// <summary>
        /// Creates the dynamic person controls.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        private void CreateDynamicPersonControls(FamilyRegistrationState.FamilyPersonState familyPersonState)
        {
            var fakePerson    = new Person();
            var attributeList = familyPersonState.PersonAttributeValuesState.Select(a => AttributeCache.Get(a.Value.AttributeId)).ToList();

            fakePerson.Attributes      = attributeList.ToDictionary(a => a.Key, v => v);
            fakePerson.AttributeValues = familyPersonState.PersonAttributeValuesState;

            var adultAttributeKeysToEdit = this.RequiredAttributesForAdults.OrderBy(a => a.Order).ToList();

            adultAttributeKeysToEdit.AddRange(this.OptionalAttributesForAdults.OrderBy(a => a.Order).ToList());

            avcAdultAttributes.IncludedAttributes = adultAttributeKeysToEdit.ToArray();

            // override the attribute's IsRequired and set Required based on whether the attribute is part of the Required or Optional set of attributes for the Registration
            avcAdultAttributes.RequiredAttributes = this.RequiredAttributesForAdults.ToArray();

            avcAdultAttributes.ValidationGroup   = btnDonePerson.ValidationGroup;
            avcAdultAttributes.NumberOfColumns   = 2;
            avcAdultAttributes.ShowCategoryLabel = false;
            avcAdultAttributes.AddEditControls(fakePerson);

            var childAttributeKeysToEdit = this.RequiredAttributesForChildren.OrderBy(a => a.Order).ToList();

            childAttributeKeysToEdit.AddRange(this.OptionalAttributesForChildren.OrderBy(a => a.Order).ToList());

            avcChildAttributes.IncludedAttributes = childAttributeKeysToEdit.ToArray();

            // override the attribute's IsRequired and set Required based on whether the attribute is part of the Required or Optional set of attributes for the Registration
            avcChildAttributes.RequiredAttributes = this.RequiredAttributesForChildren.ToArray();

            avcChildAttributes.ValidationGroup   = btnDonePerson.ValidationGroup;
            avcChildAttributes.NumberOfColumns   = 2;
            avcChildAttributes.ShowCategoryLabel = false;
            avcChildAttributes.AddEditControls(fakePerson);
        }
        /// <summary>
        /// Edits the group member.
        /// </summary>
        /// <param name="groupMemberId">The group member identifier.</param>
        private void EditGroupMember(Guid?groupMemberGuid)
        {
            var rockContext = new RockContext();

            FamilyRegistrationState.FamilyPersonState familyPersonState = null;

            if (groupMemberGuid.HasValue)
            {
                familyPersonState = EditFamilyState.FamilyPersonListState.FirstOrDefault(a => a.GroupMemberGuid == groupMemberGuid);
            }

            if (familyPersonState == null)
            {
                // create a new temp record so we can set the defaults for the new person
                familyPersonState = FamilyRegistrationState.FamilyPersonState.FromTemporaryPerson();
                familyPersonState.GroupMemberGuid = Guid.NewGuid();

                // default Gender to Unknown so that it'll prompt to select gender if it hasn't been selected yet
                familyPersonState.Gender                  = Gender.Unknown;
                familyPersonState.IsAdult                 = false;
                familyPersonState.IsMarried               = false;
                familyPersonState.RecordStatusValueId     = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE.AsGuid()).Id;
                familyPersonState.ConnectionStatusValueId = CurrentCheckInState.CheckInType.Registration.DefaultPersonConnectionStatusId;

                var firstFamilyMember = EditFamilyState.FamilyPersonListState.FirstOrDefault();
                if (firstFamilyMember != null)
                {
                    // if this family already has a person, default the LastName to the first person
                    familyPersonState.LastName = firstFamilyMember.LastName;
                }
            }

            hfGroupMemberGuid.Value = familyPersonState.GroupMemberGuid.ToString();
            tglAdultChild.Checked   = familyPersonState.IsAdult;

            // only allow Adult/Child and Relationship to be changed for newly added people
            tglAdultChild.Visible = !familyPersonState.PersonId.HasValue;

            ddlChildRelationShipToAdult.Visible       = !familyPersonState.PersonId.HasValue;
            lChildRelationShipToAdultReadOnly.Visible = familyPersonState.PersonId.HasValue;

            ShowControlsForRole(tglAdultChild.Checked);
            if (familyPersonState.Gender == Gender.Unknown)
            {
                bgGender.SelectedValue = null;
            }
            else
            {
                bgGender.SetValue(familyPersonState.Gender.ConvertToInt());
            }
            tglAdultMaritalStatus.Checked = familyPersonState.IsMarried;

            ddlChildRelationShipToAdult.Items.Clear();

            foreach (var relationShipType in CurrentCheckInState.CheckInType.Registration.KnownRelationships)
            {
                ddlChildRelationShipToAdult.Items.Add(new ListItem(relationShipType.Value, relationShipType.Key.ToString()));
            }

            ddlChildRelationShipToAdult.SetValue(familyPersonState.ChildRelationshipToAdult);
            lChildRelationShipToAdultReadOnly.Text = CurrentCheckInState.CheckInType.Registration.KnownRelationships.GetValueOrNull(familyPersonState.ChildRelationshipToAdult);

            // Only show the RecordStatus if they aren't currently active
            dvpRecordStatus.Visible = false;
            if (familyPersonState.PersonId.HasValue)
            {
                var personRecordStatusValueId = new PersonService(rockContext).GetSelect(familyPersonState.PersonId.Value, a => a.RecordStatusValueId);
                if (personRecordStatusValueId.HasValue)
                {
                    dvpRecordStatus.Visible = personRecordStatusValueId != _personRecordStatusActiveId;
                }
            }

            tbFirstName.Focus();
            tbFirstName.Text   = familyPersonState.FirstName;
            tbLastName.Text    = familyPersonState.LastName;
            tbAlternateID.Text = familyPersonState.AlternateID;

            dvpSuffix.DefinedTypeId = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.PERSON_SUFFIX.AsGuid()).Id;
            dvpSuffix.SetValue(familyPersonState.SuffixValueId);

            dvpRecordStatus.DefinedTypeId = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.PERSON_RECORD_STATUS.AsGuid()).Id;
            dvpRecordStatus.SetValue(familyPersonState.RecordStatusValueId);
            hfConnectionStatus.Value = familyPersonState.ConnectionStatusValueId.ToString();

            bool showSmsButton = CurrentCheckInState.CheckInType.Registration.DisplaySmsButton;

            if (showSmsButton)
            {
                bgSMS.Visible       = true;
                bgSMS.SelectedValue = null;

                if (CurrentCheckInState.CheckInType.Registration.DefaultSmsEnabled)
                {
                    bgSMS.SetValue("True");
                }
            }
            else
            {
                bgSMS.Visible = false;
            }

            var mobilePhoneNumber = familyPersonState.MobilePhoneNumber;

            if (mobilePhoneNumber != null)
            {
                pnMobilePhone.CountryCode = familyPersonState.MobilePhoneCountryCode;
                pnMobilePhone.Number      = mobilePhoneNumber;

                if (showSmsButton)
                {
                    // Set this value if it exists
                    if (familyPersonState.MobilePhoneSmsEnabled.HasValue)
                    {
                        bgSMS.SetValue(familyPersonState.MobilePhoneSmsEnabled.Value.ToTrueFalse());
                    }
                }
            }
            else
            {
                pnMobilePhone.CountryCode = string.Empty;
                pnMobilePhone.Number      = string.Empty;
            }

            tbEmail.Text             = familyPersonState.Email;
            dpBirthDate.SelectedDate = familyPersonState.BirthDate;
            if (familyPersonState.GradeOffset.HasValue)
            {
                gpGradePicker.SetValue(familyPersonState.GradeOffset);
            }
            else
            {
                gpGradePicker.SelectedValue = null;
            }

            CreateDynamicPersonControls(familyPersonState);

            ShowPersonView(familyPersonState);
        }
        /// <summary>
        /// Creates the dynamic person controls.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        private void CreateDynamicPersonControls(FamilyRegistrationState.FamilyPersonState familyPersonState, bool setValues)
        {
            phAdultAttributes.Controls.Clear();
            phChildAttributes.Controls.Clear();
            var fakePerson    = new Person();
            var attributeList = familyPersonState.PersonAttributeValuesState.Select(a => AttributeCache.Get(a.Value.AttributeId)).ToList();

            fakePerson.Attributes      = attributeList.ToDictionary(a => a.Key, v => v);
            fakePerson.AttributeValues = familyPersonState.PersonAttributeValuesState;

            var adultAttributeKeysToEdit = this.RequiredAttributesForAdults.OrderBy(a => a.Order).Select(a => a.Key).ToList();

            adultAttributeKeysToEdit.AddRange(this.OptionalAttributesForAdults.OrderBy(a => a.Order).Select(a => a.Key).ToList());

            Rock.Attribute.Helper.AddEditControls(
                string.Empty,
                adultAttributeKeysToEdit,
                fakePerson,
                phAdultAttributes,
                btnDonePerson.ValidationGroup,
                setValues,
                new List <string>(),
                2);

            var childAttributeKeysToEdit = this.RequiredAttributesForChildren.OrderBy(a => a.Order).Select(a => a.Key).ToList();

            childAttributeKeysToEdit.AddRange(this.OptionalAttributesForChildren.OrderBy(a => a.Order).Select(a => a.Key).ToList());

            Rock.Attribute.Helper.AddEditControls(
                string.Empty,
                childAttributeKeysToEdit,
                fakePerson,
                phChildAttributes,
                btnDonePerson.ValidationGroup,
                setValues,
                new List <string>(),
                2);

            // override the attribute's IsRequired and set Required based on whether the attribute is part of the Required or Optional set of attributes for the Registration
            foreach (Control attributeControl in phAdultAttributes.ControlsOfTypeRecursive <Control>().OfType <Control>())
            {
                if (attributeControl is IHasRequired && attributeControl.ID.IsNotNullOrWhiteSpace())
                {
                    int?attributeControlAttributeId = attributeControl.ID.Replace("attribute_field_", string.Empty).AsIntegerOrNull();
                    if (attributeControlAttributeId.HasValue)
                    {
                        (attributeControl as IHasRequired).Required = this.RequiredAttributesForAdults.Any(a => a.Id == attributeControlAttributeId.Value);
                    }
                }
            }

            foreach (Control attributeControl in phChildAttributes.ControlsOfTypeRecursive <Control>().OfType <Control>())
            {
                if (attributeControl is IHasRequired && attributeControl.ID.IsNotNullOrWhiteSpace())
                {
                    int?attributeControlAttributeId = attributeControl.ID.Replace("attribute_field_", string.Empty).AsIntegerOrNull();
                    if (attributeControlAttributeId.HasValue)
                    {
                        (attributeControl as IHasRequired).Required = this.RequiredAttributesForChildren.Any(a => a.Id == attributeControlAttributeId.Value);
                    }
                }
            }
        }