Beispiel #1
0
        /// <summary>
        /// Sets the value. ( as Guid )
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="value">The value.</param>
        public override void SetEditValue(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues, string value)
        {
            GroupTypeGroupPicker groupTypeGroupPicker = control as GroupTypeGroupPicker;

            if (groupTypeGroupPicker != null)
            {
                // initialize in case the value isn't set
                groupTypeGroupPicker.GroupTypeId = null;
                groupTypeGroupPicker.GroupId     = null;

                string[] parts       = (value ?? string.Empty).Split('|');
                var      rockContext = new RockContext();
                if (parts.Length >= 1)
                {
                    var groupType = new GroupTypeService(rockContext).Get(parts[0].AsGuid());
                    if (groupType != null)
                    {
                        groupTypeGroupPicker.GroupTypeId = groupType.Id;
                    }

                    if (parts.Length >= 2)
                    {
                        var group = new GroupService(rockContext).Get(parts[1].AsGuid());
                        if (group != null)
                        {
                            groupTypeGroupPicker.GroupId = group.Id;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Reads new values entered by the user for the field ( as Guid )
        /// </summary>
        /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns></returns>
        public override string GetEditValue(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues)
        {
            GroupTypeGroupPicker groupTypeGroupPicker = control as GroupTypeGroupPicker;

            if (groupTypeGroupPicker != null)
            {
                var rockContext = new RockContext();

                Guid?groupTypeGuid = null;
                Guid?groupGuid     = null;
                if (groupTypeGroupPicker.GroupTypeId.HasValue)
                {
                    var groupType = new GroupTypeService(rockContext).Get(groupTypeGroupPicker.GroupTypeId.Value);
                    if (groupType != null)
                    {
                        groupTypeGuid = groupType.Guid;
                    }
                }

                if (groupTypeGroupPicker.GroupId.HasValue)
                {
                    var group = new GroupService(rockContext).Get(groupTypeGroupPicker.GroupId.Value);
                    if (group != null)
                    {
                        groupGuid = group.Guid;
                    }
                }

                return(string.Format("{0}|{1}", groupTypeGuid, groupGuid));
            }

            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Creates the control(s) necessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override System.Web.UI.Control EditControl(Dictionary <string, ConfigurationValue> configurationValues, string id)
        {
            GroupTypeGroupPicker editControl = new GroupTypeGroupPicker {
                ID = id
            };

            if (configurationValues != null && configurationValues.ContainsKey(CONFIG_GROUP_PICKER_LABEL))
            {
                editControl.GroupControlLabel = configurationValues[CONFIG_GROUP_PICKER_LABEL].Value;
            }

            return(editControl);
        }