Esempio n. 1
0
        /// <summary>
        /// Gets the existing value for a specific field for the given registrant.
        /// </summary>
        /// <param name="registrant">The registrant.</param>
        /// <param name="person">The person.</param>
        /// <param name="family">The family.</param>
        /// <param name="Field">The field.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        public object GetRegistrantValue(RegistrationRegistrant registrant, Person person, Group family,
                                         RegistrationTemplateFormField Field, RockContext rockContext)
        {
            if (Field.FieldSource == RegistrationFieldSource.PersonField)
            {
                if (person != null)
                {
                    DefinedValueCache dvPhone = null;

                    switch (Field.PersonFieldType)
                    {
                    case RegistrationPersonFieldType.FirstName: return(person.NickName);

                    case RegistrationPersonFieldType.LastName: return(person.LastName);

                    case RegistrationPersonFieldType.Campus:
                    {
                        if (family != null)
                        {
                            return(family.CampusId);
                        }
                        break;
                    }

                    case RegistrationPersonFieldType.Address:
                    {
                        var location = person.GetHomeLocation(rockContext);
                        if (location != null)
                        {
                            return(location.Clone());
                        }
                        break;
                    }

                    case RegistrationPersonFieldType.Email: return(person.Email);

                    case RegistrationPersonFieldType.Birthdate: return(person.BirthDate);

                    case RegistrationPersonFieldType.Grade: return(person.GraduationYear);

                    case RegistrationPersonFieldType.Gender: return(person.Gender);

                    case RegistrationPersonFieldType.MaritalStatus: return(person.MaritalStatusValueId);

                    case RegistrationPersonFieldType.MobilePhone:
                    {
                        dvPhone = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_MOBILE);
                        break;
                    }

                    case RegistrationPersonFieldType.HomePhone:
                    {
                        dvPhone = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME);
                        break;
                    }

                    case RegistrationPersonFieldType.WorkPhone:
                    {
                        dvPhone = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_WORK);
                        break;
                    }
                    }

                    if (dvPhone != null)
                    {
                        var phoneNumber = new PersonService(rockContext).GetPhoneNumber(person, dvPhone);
                        if (phoneNumber != null)
                        {
                            return(phoneNumber.Clone());
                        }
                    }
                }
            }
            else
            {
                var attribute = AttributeCache.Read(Field.AttributeId ?? 0);
                if (attribute != null)
                {
                    switch (Field.FieldSource)
                    {
                    case RegistrationFieldSource.PersonAttribute:
                    {
                        if (person != null)
                        {
                            if (person.Attributes == null)
                            {
                                person.LoadAttributes();
                            }
                            return(person.GetAttributeValue(attribute.Key));
                        }
                        break;
                    }

                    case RegistrationFieldSource.GroupMemberAttribute:
                    {
                        if (registrant != null && registrant.GroupMember != null)
                        {
                            if (registrant.GroupMember.Attributes == null)
                            {
                                registrant.GroupMember.LoadAttributes();
                            }
                            return(registrant.GroupMember.GetAttributeValue(attribute.Key));
                        }
                        break;
                    }

                    case RegistrationFieldSource.RegistrationAttribute:
                    {
                        if (registrant != null)
                        {
                            if (registrant.Attributes == null)
                            {
                                registrant.LoadAttributes();
                            }
                            return(registrant.GetAttributeValue(attribute.Key));
                        }
                        break;
                    }
                    }
                }
            }

            return(null);
        }