Ejemplo n.º 1
0
        /// <summary>
        /// Checks the settings.  If false is returned, it's expected that the caller will make
        /// the nbNotice visible to inform the user of the "settings" error.
        /// </summary>
        /// <returns>true if settings are valid; false otherwise</returns>
        private bool CheckSettings()
        {
            _rockContext = _rockContext ?? new RockContext();

            _mode = GetAttributeValue("Mode");

            _autoFill = GetAttributeValue("AutoFillForm").AsBoolean();

            var  groupService         = new GroupService(_rockContext);
            bool groupIsFromQryString = true;

            Guid?groupGuid = GetAttributeValue("Group").AsGuidOrNull();

            if (groupGuid.HasValue)
            {
                _group = groupService.Get(groupGuid.Value);
                groupIsFromQryString = false;
            }

            if (_group == null)
            {
                groupGuid = PageParameter("GroupGuid").AsGuidOrNull();
                if (groupGuid.HasValue)
                {
                    _group = groupService.Get(groupGuid.Value);
                }
            }

            if (_group == null && GetAttributeValue("EnablePassingGroupId").AsBoolean(false))
            {
                int?groupId = PageParameter("GroupId").AsIntegerOrNull();
                if (groupId.HasValue)
                {
                    _group = groupService.Get(groupId.Value);
                }
            }

            if (_group == null)
            {
                nbNotice.Heading = "Unknown Group";
                nbNotice.Text    = "<p>This page requires a valid group identifying parameter and there was not one provided.</p>";
                return(false);
            }
            else
            {
                Guid RsvpGroupTypeGuid = "1A082EFF-30DA-44B2-8E48-02385C20828E".AsGuid();
                var  groupTypeGuids    = new GroupTypeService(_rockContext).Queryable()
                                         .AsNoTracking()
                                         .Where(g =>
                                                g.Guid == RsvpGroupTypeGuid ||
                                                g.InheritedGroupType.Guid == RsvpGroupTypeGuid)
                                         .Select(g => g.Guid)
                                         .ToList();

                if (groupIsFromQryString && groupTypeGuids.Any() && !groupTypeGuids.Contains(_group.GroupType.Guid))
                {
                    _group           = null;
                    nbNotice.Heading = "Invalid Group";
                    nbNotice.Text    = "<p>The selected group is a restricted group type therefore this block cannot be used to add people to these groups (unless configured to allow).</p>";
                    return(false);
                }
                else
                {
                    _defaultGroupRole = _group.GroupType.DefaultGroupRole;
                }
            }

            _dvcConnectionStatus = DefinedValueCache.Get(GetAttributeValue("ConnectionStatus").AsGuid());
            if (_dvcConnectionStatus == null)
            {
                nbNotice.Heading = "Invalid Connection Status";
                nbNotice.Text    = "<p>The selected Connection Status setting does not exist.</p>";
                return(false);
            }

            _dvcRecordStatus = DefinedValueCache.Get(GetAttributeValue("RecordStatus").AsGuid());
            if (_dvcRecordStatus == null)
            {
                nbNotice.Heading = "Invalid Record Status";
                nbNotice.Text    = "<p>The selected Record Status setting does not exist.</p>";
                return(false);
            }

            _married         = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid());
            _homeAddressType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid());
            _familyType      = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid());
            _adultRole       = _familyType.Roles.FirstOrDefault(r => r.Guid.Equals(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid()));

            if (_married == null || _homeAddressType == null || _familyType == null || _adultRole == null)
            {
                nbNotice.Heading = "Missing System Value";
                nbNotice.Text    = "<p>There is a missing or invalid system value. Check the settings for Marital Status of 'Married', Location Type of 'Home', Group Type of 'Family', and Family Group Role of 'Adult'.</p>";
                return(false);
            }

            return(true);
        }