/// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="groupRequirementTypeId">The group requirement type identifier.</param>
        public void ShowDetail(int groupRequirementTypeId)
        {
            RockContext                 rockContext                 = new RockContext();
            GroupRequirementType        groupRequirementType        = null;
            GroupRequirementTypeService groupRequirementTypeService = new GroupRequirementTypeService(rockContext);

            if (!groupRequirementTypeId.Equals(0))
            {
                groupRequirementType = groupRequirementTypeService.Get(groupRequirementTypeId);
                lActionTitle.Text    = ActionTitle.Edit(GroupRequirementType.FriendlyTypeName).FormatAsHtmlTitle();
                pdAuditDetails.SetEntity(groupRequirementType, ResolveRockUrl("~"));
            }

            if (groupRequirementType == null)
            {
                groupRequirementType = new GroupRequirementType {
                    Id = 0
                };
                groupRequirementType.RequirementCheckType = RequirementCheckType.Manual;
                lActionTitle.Text = ActionTitle.Add(GroupRequirementType.FriendlyTypeName).FormatAsHtmlTitle();
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            hfGroupRequirementTypeId.Value = groupRequirementType.Id.ToString();
            tbName.Text          = groupRequirementType.Name;
            tbDescription.Text   = groupRequirementType.Description;
            tbPositiveLabel.Text = groupRequirementType.PositiveLabel;
            tbNegativeLabel.Text = groupRequirementType.NegativeLabel;
            tbWarningLabel.Text  = groupRequirementType.WarningLabel;
            tbCheckboxLabel.Text = groupRequirementType.CheckboxLabel;
            cbCanExpire.Checked  = groupRequirementType.CanExpire;
            nbExpireInDays.Text  = groupRequirementType.ExpireInDays.ToString();

            ceSqlExpression.Text = groupRequirementType.SqlExpression;
            ceSqlExpression.Help = @"A SQL expression that returns a list of Person Ids that meet the criteria. Example: <pre>SELECT [Id] FROM [Person] WHERE [LastName] = 'Decker'</pre>
The SQL can include Lava merge fields:";

            ceSqlExpression.Help += groupRequirementType.GetMergeObjects(new Group()).lavaDebugInfo();

            ceWarningSqlExpression.Text = groupRequirementType.WarningSqlExpression;

            dpDataView.EntityTypeId  = EntityTypeCache.Read <Person>().Id;
            dpDataView.SelectedValue = groupRequirementType.DataViewId.ToString();

            dpWarningDataView.EntityTypeId  = EntityTypeCache.Read <Person>().Id;
            dpWarningDataView.SelectedValue = groupRequirementType.WarningDataViewId.ToString();

            hfRequirementCheckType.Value = groupRequirementType.RequirementCheckType.ConvertToInt().ToString();
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="groupRequirementTypeId">The group requirement type identifier.</param>
        public void ShowDetail( int groupRequirementTypeId )
        {
            RockContext rockContext = new RockContext();
            GroupRequirementType groupRequirementType = null;
            GroupRequirementTypeService groupRequirementTypeService = new GroupRequirementTypeService( rockContext );

            if ( !groupRequirementTypeId.Equals( 0 ) )
            {
                groupRequirementType = groupRequirementTypeService.Get( groupRequirementTypeId );
                lActionTitle.Text = ActionTitle.Edit( GroupRequirementType.FriendlyTypeName ).FormatAsHtmlTitle();
                pdAuditDetails.SetEntity( groupRequirementType, ResolveRockUrl( "~" ) );
            }

            if ( groupRequirementType == null )
            {
                groupRequirementType = new GroupRequirementType { Id = 0 };
                groupRequirementType.RequirementCheckType = RequirementCheckType.Manual;
                lActionTitle.Text = ActionTitle.Add( GroupRequirementType.FriendlyTypeName ).FormatAsHtmlTitle();
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            hfGroupRequirementTypeId.Value = groupRequirementType.Id.ToString();
            tbName.Text = groupRequirementType.Name;
            tbDescription.Text = groupRequirementType.Description;
            tbPositiveLabel.Text = groupRequirementType.PositiveLabel;
            tbNegativeLabel.Text = groupRequirementType.NegativeLabel;
            tbWarningLabel.Text = groupRequirementType.WarningLabel;
            tbCheckboxLabel.Text = groupRequirementType.CheckboxLabel;
            cbCanExpire.Checked = groupRequirementType.CanExpire;
            nbExpireInDays.Text = groupRequirementType.ExpireInDays.ToString();

            ceSqlExpression.Text = groupRequirementType.SqlExpression;
            ceSqlExpression.Help = @"A SQL expression that returns a list of Person Ids that meet the criteria. Example: <pre>SELECT [Id] FROM [Person] WHERE [LastName] = 'Decker'</pre>
            The SQL can include Lava merge fields:";

            ceSqlExpression.Help += groupRequirementType.GetMergeObjects( new Group() ).lavaDebugInfo();

            ceWarningSqlExpression.Text = groupRequirementType.WarningSqlExpression;

            dpDataView.EntityTypeId = EntityTypeCache.Read<Person>().Id;
            dpDataView.SelectedValue = groupRequirementType.DataViewId.ToString();

            dpWarningDataView.EntityTypeId = EntityTypeCache.Read<Person>().Id;
            dpWarningDataView.SelectedValue = groupRequirementType.WarningDataViewId.ToString();

            hfRequirementCheckType.Value = groupRequirementType.RequirementCheckType.ConvertToInt().ToString();
        }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            RockContext rockContext = new RockContext();
            GroupRequirementTypeService groupRequirementTypeService = new GroupRequirementTypeService(rockContext);
            SortProperty sortProperty = gList.SortProperty;

            var qry = groupRequirementTypeService.Queryable();

            if (sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry.OrderBy(a => a.Name);
            }

            gList.DataSource = qry.ToList();
            gList.DataBind();
        }
        /// <summary>
        /// Handles the Delete event of the gList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gList_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            GroupRequirementTypeService service = new GroupRequirementTypeService( rockContext );
            GroupRequirementType item = service.Get( e.RowKeyId );
            if ( item != null )
            {
                string errorMessage;
                if ( !service.CanDelete( item, out errorMessage ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                service.Delete( item );
                rockContext.SaveChanges();
            }

            BindGrid();
        }
        /// <summary>
        /// Handles the Delete event of the gList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gList_Delete(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            GroupRequirementTypeService service = new GroupRequirementTypeService(rockContext);
            GroupRequirementType        item    = service.Get(e.RowKeyId);

            if (item != null)
            {
                string errorMessage;
                if (!service.CanDelete(item, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                service.Delete(item);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
        /// <summary>
        /// Creates the group requirement controls.
        /// </summary>
        /// <param name="group">The group.</param>
        /// <param name="rockContext">The rock context.</param>
        public void CreateGroupRequirementControls(Group group, RockContext rockContext)
        {
            EnsureChildControls();

            _ddlGroupRequirement.Items.Clear();
            _ddlGroupRequirement.SelectedIndex = -1;

            if (group != null)
            {
                var selectedRequirement = group.GroupRequirements.Select(r => r.GroupRequirementTypeId).FirstOrDefault();
                var groupRequirements   = new GroupRequirementTypeService(rockContext).Queryable().ToList();

                _ddlGroupRequirement.Items.Add(Rock.Constants.None.ListItem);
                _ddlGroupRequirement.Items.AddRange(
                    groupRequirements.Select(r => new ListItem
                {
                    Text  = r.Name,
                    Value = r.Id.ToString()
                }).ToArray()
                    );

                _ddlGroupRequirement.Items.FindByValue(selectedRequirement.ToString()).Selected = true;
            }
        }
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            GroupRequirementType groupRequirementType;

            var rockContext = new RockContext();
            GroupRequirementTypeService groupRequirementTypeService = new GroupRequirementTypeService(rockContext);

            int groupRequirementTypeId = hfGroupRequirementTypeId.Value.AsInteger();

            if (groupRequirementTypeId == 0)
            {
                groupRequirementType = new GroupRequirementType();
            }
            else
            {
                groupRequirementType = groupRequirementTypeService.Get(groupRequirementTypeId);
            }

            groupRequirementType.Name                 = tbName.Text;
            groupRequirementType.Description          = tbDescription.Text;
            groupRequirementType.CanExpire            = cbCanExpire.Checked;
            groupRequirementType.ExpireInDays         = groupRequirementType.CanExpire ? nbExpireInDays.Text.AsIntegerOrNull() : null;
            groupRequirementType.RequirementCheckType = hfRequirementCheckType.Value.ConvertToEnum <RequirementCheckType>(RequirementCheckType.Manual);

            if (groupRequirementType.RequirementCheckType == RequirementCheckType.Sql)
            {
                groupRequirementType.SqlExpression        = ceSqlExpression.Text;
                groupRequirementType.WarningSqlExpression = ceWarningSqlExpression.Text;
            }
            else
            {
                groupRequirementType.SqlExpression        = null;
                groupRequirementType.WarningSqlExpression = null;
            }

            if (groupRequirementType.RequirementCheckType == RequirementCheckType.Dataview)
            {
                groupRequirementType.DataViewId        = dpDataView.SelectedValue.AsIntegerOrNull();
                groupRequirementType.WarningDataViewId = dpWarningDataView.SelectedValue.AsIntegerOrNull();
            }
            else
            {
                groupRequirementType.DataViewId        = null;
                groupRequirementType.WarningDataViewId = null;
            }

            groupRequirementType.PositiveLabel = tbPositiveLabel.Text;
            groupRequirementType.NegativeLabel = tbNegativeLabel.Text;
            groupRequirementType.WarningLabel  = tbWarningLabel.Text;
            groupRequirementType.CheckboxLabel = tbCheckboxLabel.Text;

            if (!Page.IsValid)
            {
                return;
            }

            if (!groupRequirementType.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            if (groupRequirementType.Id == 0)
            {
                groupRequirementTypeService.Add(groupRequirementType);
            }

            rockContext.SaveChanges();

            NavigateToParentPage();
        }
Esempio n. 8
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="groupRequirementTypeId">The group requirement type identifier.</param>
        public void ShowDetail(int groupRequirementTypeId)
        {
            RockContext                 rockContext                 = new RockContext();
            GroupRequirementType        groupRequirementType        = null;
            GroupRequirementTypeService groupRequirementTypeService = new GroupRequirementTypeService(rockContext);

            if (!groupRequirementTypeId.Equals(0))
            {
                groupRequirementType = groupRequirementTypeService.Get(groupRequirementTypeId);
                lActionTitle.Text    = ActionTitle.Edit(GroupRequirementType.FriendlyTypeName).FormatAsHtmlTitle();
                pdAuditDetails.SetEntity(groupRequirementType, ResolveRockUrl("~"));
            }

            if (groupRequirementType == null)
            {
                groupRequirementType = new GroupRequirementType {
                    Id = 0
                };
                groupRequirementType.RequirementCheckType = RequirementCheckType.Manual;
                lActionTitle.Text = ActionTitle.Add(GroupRequirementType.FriendlyTypeName).FormatAsHtmlTitle();
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            hfGroupRequirementTypeId.Value = groupRequirementType.Id.ToString();
            tbName.Text          = groupRequirementType.Name;
            tbDescription.Text   = groupRequirementType.Description;
            tbPositiveLabel.Text = groupRequirementType.PositiveLabel;
            tbNegativeLabel.Text = groupRequirementType.NegativeLabel;
            tbWarningLabel.Text  = groupRequirementType.WarningLabel;
            tbCheckboxLabel.Text = groupRequirementType.CheckboxLabel;
            cbCanExpire.Checked  = groupRequirementType.CanExpire;
            nbExpireInDays.Text  = groupRequirementType.ExpireInDays.ToString();

            nbSQLHelp.InnerHtml = @"A SQL expression that returns a list of Person Ids that meet the criteria. Example:
<pre>
SELECT [Id] FROM [Person]
WHERE [LastName] = 'Decker'</pre>
</pre>
The SQL can include Lava merge fields:

<ul>
   <li>Group</i>
   <li>GroupRequirementType</i>
</ul>

TIP: When calculating for a specific Person, a <strong>Person</strong> merge field will also be included. This can improve performance in cases when the system is checking requirements for a specific person. Example:

<pre>
    SELECT [Id] FROM [Person]
        WHERE [LastName] = 'Decker'
    {% if Person != empty %}
        AND [Id] = {{ Person.Id }}
    {% endif &}
</pre>
";

            nbSQLHelp.InnerHtml += groupRequirementType.GetMergeObjects(new Group(), this.CurrentPerson).lavaDebugInfo();

            ceSqlExpression.Text = groupRequirementType.SqlExpression;

            ceWarningSqlExpression.Text = groupRequirementType.WarningSqlExpression;

            dpDataView.EntityTypeId = EntityTypeCache.Get <Person>().Id;
            dpDataView.SetValue(groupRequirementType.DataViewId);

            dpWarningDataView.EntityTypeId = EntityTypeCache.Get <Person>().Id;
            dpWarningDataView.SetValue(groupRequirementType.WarningDataViewId);

            hfRequirementCheckType.Value = groupRequirementType.RequirementCheckType.ConvertToInt().ToString();
        }
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e )
        {
            GroupRequirementType groupRequirementType;

            var rockContext = new RockContext();
            GroupRequirementTypeService groupRequirementTypeService = new GroupRequirementTypeService( rockContext );

            int groupRequirementTypeId = hfGroupRequirementTypeId.Value.AsInteger();

            if (groupRequirementTypeId == 0)
            {
                groupRequirementType = new GroupRequirementType();
            }
            else
            {
                groupRequirementType = groupRequirementTypeService.Get( groupRequirementTypeId );
            }

            groupRequirementType.Name = tbName.Text;
            groupRequirementType.Description = tbDescription.Text;
            groupRequirementType.CanExpire = cbCanExpire.Checked;
            groupRequirementType.ExpireInDays = groupRequirementType.CanExpire ? nbExpireInDays.Text.AsIntegerOrNull() : null;
            groupRequirementType.RequirementCheckType = hfRequirementCheckType.Value.ConvertToEnum<RequirementCheckType>( RequirementCheckType.Manual );

            if ( groupRequirementType.RequirementCheckType == RequirementCheckType.Sql)
            {
                groupRequirementType.SqlExpression = ceSqlExpression.Text;
                groupRequirementType.WarningSqlExpression = ceWarningSqlExpression.Text;
            }
            else
            {
                groupRequirementType.SqlExpression = null;
                groupRequirementType.WarningSqlExpression = null;
            }

            if (groupRequirementType.RequirementCheckType == RequirementCheckType.Dataview)
            {
                groupRequirementType.DataViewId = dpDataView.SelectedValue.AsIntegerOrNull();
                groupRequirementType.WarningDataViewId = dpWarningDataView.SelectedValue.AsIntegerOrNull();
            }
            else
            {
                groupRequirementType.DataViewId = null;
                groupRequirementType.WarningDataViewId = null;
            }

            groupRequirementType.PositiveLabel = tbPositiveLabel.Text;
            groupRequirementType.NegativeLabel = tbNegativeLabel.Text;
            groupRequirementType.WarningLabel = tbWarningLabel.Text;
            groupRequirementType.CheckboxLabel = tbCheckboxLabel.Text;

            if ( !Page.IsValid )
            {
                return;
            }

            if ( !groupRequirementType.IsValid )
            {
                // Controls will render the error messages
                return;
            }

            if ( groupRequirementType.Id == 0 )
            {
                groupRequirementTypeService.Add( groupRequirementType );
            }

            rockContext.SaveChanges();

            NavigateToParentPage();
        }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            RockContext rockContext = new RockContext();
            GroupRequirementTypeService groupRequirementTypeService = new GroupRequirementTypeService( rockContext );
            SortProperty sortProperty = gList.SortProperty;

            var qry = groupRequirementTypeService.Queryable();

            if ( sortProperty != null )
            {
                qry = qry.Sort( sortProperty );
            }
            else
            {
                qry = qry.OrderBy( a => a.Name );
            }

            gList.DataSource = qry.ToList();
            gList.DataBind();
        }
Esempio n. 11
0
        /// <summary>
        /// Shows the modal dialog to add/edit a Group Requirement
        /// </summary>
        /// <param name="groupRequirementGuid">The group requirement unique identifier.</param>
        protected void gGroupRequirements_ShowEdit( Guid groupRequirementGuid )
        {
            var rockContext = new RockContext();

            var groupRequirementTypeService = new GroupRequirementTypeService( rockContext );
            var list = groupRequirementTypeService.Queryable().OrderBy( a => a.Name ).ToList();
            ddlGroupRequirementType.Items.Clear();
            ddlGroupRequirementType.Items.Add( new ListItem() );
            foreach ( var item in list )
            {
                ddlGroupRequirementType.Items.Add( new ListItem( item.Name, item.Id.ToString() ) );
            }

            var selectedGroupRequirement = this.GroupRequirementsState.FirstOrDefault( a => a.Guid == groupRequirementGuid );
            grpGroupRequirementGroupRole.GroupTypeId = this.CurrentGroupTypeId;
            if ( selectedGroupRequirement != null )
            {
                ddlGroupRequirementType.SelectedValue = selectedGroupRequirement.GroupRequirementTypeId.ToString();
                grpGroupRequirementGroupRole.GroupRoleId = selectedGroupRequirement.GroupRoleId;
            }
            else
            {
                ddlGroupRequirementType.SelectedIndex = 0;
                grpGroupRequirementGroupRole.GroupRoleId = null;
            }

            nbDuplicateGroupRequirement.Visible = false;

            hfGroupRequirementGuid.Value = groupRequirementGuid.ToString();

            ShowDialog( "GroupRequirements", true );
        }