コード例 #1
0
        /// <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 )
        {
            DataView dataView = null;

            var rockContext = new RockContext();
            DataViewService service = new DataViewService( rockContext );

            int dataViewId = int.Parse( hfDataViewId.Value );
            int? dataViewFilterId = null;

            if ( dataViewId == 0 )
            {
                dataView = new DataView();
                dataView.IsSystem = false;
            }
            else
            {
                dataView = service.Get( dataViewId );
                dataViewFilterId = dataView.DataViewFilterId;
            }

            dataView.Name = tbName.Text;
            dataView.Description = tbDescription.Text;
            dataView.TransformEntityTypeId = ddlTransform.SelectedValueAsInt();
            dataView.EntityTypeId = ddlEntityType.SelectedValueAsInt();
            dataView.CategoryId = cpCategory.SelectedValueAsInt();

            dataView.DataViewFilter = GetFilterControl();

            // update Guids since we are creating a new dataFilter and children and deleting the old one
            SetNewDataFilterGuids( dataView.DataViewFilter );

            if ( !Page.IsValid )
            {
                return;
            }

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


            if ( dataView.Id.Equals( 0 ) )
            {
                service.Add( dataView );
            }

            // Delete old report filter
            if ( dataViewFilterId.HasValue )
            {
                DataViewFilterService dataViewFilterService = new DataViewFilterService( rockContext );
                DataViewFilter dataViewFilter = dataViewFilterService.Get( dataViewFilterId.Value );
                DeleteDataViewFilter( dataViewFilter, dataViewFilterService );
            }

            rockContext.SaveChanges();

            var qryParams = new Dictionary<string, string>();
            qryParams["DataViewId"] = dataView.Id.ToString();
            NavigateToPage( RockPage.Guid, qryParams );
        }
コード例 #2
0
ファイル: DataViewDetail.ascx.cs プロジェクト: pkdevbox/Rock
        /// <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 )
        {
            DataView dataView = null;

            using ( new UnitOfWorkScope() )
            {
                DataViewService service = new DataViewService();

                int dataViewId = int.Parse( hfDataViewId.Value );
                int? dataViewFilterId = null;

                if ( dataViewId == 0 )
                {
                    dataView = new DataView();
                    dataView.IsSystem = false;
                }
                else
                {
                    dataView = service.Get( dataViewId );
                    dataViewFilterId = dataView.DataViewFilterId;
                }

                dataView.Name = tbName.Text;
                dataView.Description = tbDescription.Text;
                dataView.TransformEntityTypeId = ddlTransform.SelectedValueAsInt();
                dataView.EntityTypeId = ddlEntityType.SelectedValueAsInt();
                dataView.CategoryId = cpCategory.SelectedValueAsInt();

                dataView.DataViewFilter = GetFilterControl();

                if ( !Page.IsValid )
                {
                    return;
                }

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

                RockTransactionScope.WrapTransaction( () =>
                {
                    if ( dataView.Id.Equals( 0 ) )
                    {
                        service.Add( dataView, CurrentPersonId );
                    }

                    service.Save( dataView, CurrentPersonId );

                    // Delete old report filter
                    if ( dataViewFilterId.HasValue )
                    {
                        DataViewFilterService dataViewFilterService = new DataViewFilterService();
                        DataViewFilter dataViewFilter = dataViewFilterService.Get( dataViewFilterId.Value );
                        DeleteDataViewFilter( dataViewFilter, dataViewFilterService );
                        dataViewFilterService.Save( dataViewFilter, CurrentPersonId );
                    }

                } );
            }

            var qryParams = new Dictionary<string, string>();
            qryParams["DataViewId"] = dataView.Id.ToString();
            NavigateToPage( RockPage.Guid, qryParams );
        }
コード例 #3
0
ファイル: DataViewDetail.ascx.cs プロジェクト: NewSpring/Rock
        /// <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 )
        {
            DataView dataView = null;

            var rockContext = new RockContext();
            DataViewService service = new DataViewService( rockContext );

            int dataViewId = int.Parse( hfDataViewId.Value );
            int? origDataViewFilterId = null;

            if ( dataViewId == 0 )
            {
                dataView = new DataView();
                dataView.IsSystem = false;
            }
            else
            {
                dataView = service.Get( dataViewId );
                origDataViewFilterId = dataView.DataViewFilterId;
            }

            dataView.Name = tbName.Text;
            dataView.Description = tbDescription.Text;
            dataView.TransformEntityTypeId = ddlTransform.SelectedValueAsInt();
            dataView.EntityTypeId = etpEntityType.SelectedEntityTypeId;
            dataView.CategoryId = cpCategory.SelectedValueAsInt();

            var newDataViewFilter = ReportingHelper.GetFilterFromControls( phFilters );

            if ( !Page.IsValid )
            {
                return;
            }

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

            var adding = dataView.Id.Equals( 0 );
            if ( adding )
            {
                service.Add( dataView );
            }

            rockContext.WrapTransaction( () =>
            {

                if ( origDataViewFilterId.HasValue )
                {
                    // delete old report filter so that we can add the new filter (but with original guids), then drop the old filter
                    DataViewFilterService dataViewFilterService = new DataViewFilterService( rockContext );
                    DataViewFilter origDataViewFilter = dataViewFilterService.Get( origDataViewFilterId.Value );

                    dataView.DataViewFilterId = null;
                    rockContext.SaveChanges();

                    DeleteDataViewFilter( origDataViewFilter, dataViewFilterService );
                }

                dataView.DataViewFilter = newDataViewFilter;
                rockContext.SaveChanges();
            } );

            if ( adding )
            {
                // add EDIT and ADMINISTRATE to the person who added the dataView
                Rock.Security.Authorization.AllowPerson( dataView, Authorization.EDIT, this.CurrentPerson, rockContext );
                Rock.Security.Authorization.AllowPerson( dataView, Authorization.ADMINISTRATE, this.CurrentPerson, rockContext );
            }

            var qryParams = new Dictionary<string, string>();
            qryParams["DataViewId"] = dataView.Id.ToString();
            NavigateToPage( RockPage.Guid, qryParams );
        }