/// <summary>
        /// Creates the test data view.
        /// </summary>
        private static void CreateTestDataView()
        {
            var rockContext           = new RockContext();
            var dataViewService       = new DataViewService(rockContext);
            var dataViewFilterService = new DataViewFilterService(rockContext);

            var subDataViewFilter = new DataViewFilter
            {
                ForeignKey     = ForeignKey,
                ExpressionType = FilterExpressionType.Filter,
                EntityTypeId   = EntityTypeCache.Get <PropertyFilter>().Id,
                Guid           = Guid.NewGuid(),
                Selection      = $@"[""Property_MiddleName"",""1"",""{DataViewMiddleName}""]"
            };

            dataViewFilterService.Add(subDataViewFilter);
            rockContext.SaveChanges();

            var rootDataViewFilter = new DataViewFilter
            {
                ForeignKey     = ForeignKey,
                ExpressionType = FilterExpressionType.GroupAll,
                Guid           = Guid.NewGuid(),
                ChildFilters   = new List <DataViewFilter>
                {
                    subDataViewFilter
                }
            };

            dataViewFilterService.Add(rootDataViewFilter);
            rockContext.SaveChanges();

            var dataView = new DataView
            {
                ForeignKey     = ForeignKey,
                IsSystem       = false,
                Name           = "TEST " + ForeignKey,
                Description    = "TEST " + ForeignKey,
                EntityTypeId   = EntityTypeCache.Get <Person>().Id,
                Guid           = Guid.NewGuid(),
                DataViewFilter = rootDataViewFilter
            };

            dataViewService.Add(dataView);
            rockContext.SaveChanges();

            subDataViewFilter.DataView  = dataView;
            rootDataViewFilter.DataView = dataView;
            rockContext.SaveChanges();
        }
Пример #2
0
        /// <summary>
        /// Add or update a DataView.
        /// </summary>
        /// <param name="dataContext"></param>
        /// <param name="dataView"></param>
        public void AddOrUpdateDataView(RockContext dataContext, DataView dataView)
        {
            var dataViewService = new DataViewService(dataContext);

            var existingDataView = dataViewService.Queryable().FirstOrDefault(x => x.Guid == dataView.Guid);

            if (existingDataView == null)
            {
                dataViewService.Add(dataView);

                existingDataView = dataView;
            }
            else
            {
                existingDataView.CopyPropertiesFrom(dataView);
            }
        }
Пример #3
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?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();
            dataView.PersistedScheduleIntervalMinutes = nbPersistedScheduleIntervalMinutes.Text.AsIntegerOrNull();

            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 (dataView.PersistedScheduleIntervalMinutes.HasValue)
            {
                dataView.PersistResult(GetAttributeValue("DatabaseTimeout").AsIntegerOrNull() ?? 180);
                dataView.PersistedLastRefreshDateTime = RockDateTime.Now;
                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();
            qryParams["ParentCategoryId"] = null;
            NavigateToCurrentPageReference(qryParams);
        }
Пример #4
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;

            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(this.CurrentPage.Guid, qryParams);
        }
Пример #5
0
        public void GroupsModule_AddDataViews()
        {
            var dataContext = new RockContext();

            // Add Data View Category "Groups".
            const string categoryDataViewName = "Groups";

            Debug.Print($"Adding Data View Category \"{ categoryDataViewName }\"...");

            var entityTypeId = EntityTypeCache.Get(typeof(global::Rock.Model.DataView)).Id;

            var coreHelper = new CoreModuleTestHelper(_SampleDataForeignKey);

            var locationsCategory = coreHelper.CreateCategory(categoryDataViewName, Constants.CategoryLocationsGuid, entityTypeId);

            coreHelper.AddOrUpdateCategory(dataContext, locationsCategory);

            dataContext.SaveChanges();

            // Get Data View service.
            var service = new DataViewService(dataContext);

            int categoryId = CategoryCache.GetId(Constants.CategoryLocationsGuid) ?? 0;

            DataViewFilter rootFilter;

            // Create Data View: Locations Inside Arizona
            const string dataViewLocationsInsideArizona = "Locations in the state of Arizona";

            Debug.Print($"Adding Data View \"{ dataViewLocationsInsideArizona }\"...");

            var dataViewInside = new DataView();

            dataViewInside.IsSystem = false;

            dataViewInside.Name         = dataViewLocationsInsideArizona;
            dataViewInside.Description  = "Locations that are within the state of Arizona.";
            dataViewInside.EntityTypeId = EntityTypeCache.GetId(typeof(global::Rock.Model.Location));
            dataViewInside.CategoryId   = categoryId;
            dataViewInside.Guid         = Constants.DataViewLocationsInsideArizonaGuid;
            dataViewInside.ForeignKey   = _SampleDataForeignKey;

            rootFilter = new DataViewFilter();

            rootFilter.ExpressionType = FilterExpressionType.GroupAll;

            dataViewInside.DataViewFilter = rootFilter;

            var inStateFilter = new TextPropertyFilterSettings {
                PropertyName = "State", Comparison = ComparisonType.EqualTo, Value = "AZ"
            };

            rootFilter.ChildFilters.Add(inStateFilter.GetFilter());

            service.Add(dataViewInside);

            dataContext.SaveChanges();

            // Create Data View: Locations Outside Arizona
            const string dataViewLocationsOutsideArizona = "Locations outside Arizona";

            Debug.Print($"Adding Data View \"{ dataViewLocationsOutsideArizona }\"...");

            var dataViewOutside = new DataView();

            dataViewOutside.IsSystem = false;

            dataViewOutside.Name         = dataViewLocationsOutsideArizona;
            dataViewOutside.Description  = "Locations that are not within the state of Arizona.";
            dataViewOutside.EntityTypeId = EntityTypeCache.GetId(typeof(global::Rock.Model.Location));
            dataViewOutside.CategoryId   = categoryId;
            dataViewOutside.Guid         = Constants.DataViewLocationsOutsideArizonaGuid;
            dataViewOutside.ForeignKey   = _SampleDataForeignKey;

            rootFilter = new DataViewFilter();

            rootFilter.ExpressionType = FilterExpressionType.GroupAll;

            dataViewOutside.DataViewFilter = rootFilter;

            var notInStateFilter = new TextPropertyFilterSettings {
                PropertyName = "State", Comparison = ComparisonType.NotEqualTo, Value = "AZ"
            };

            rootFilter.ChildFilters.Add(notInStateFilter.GetFilter());

            service.Add(dataViewOutside);

            dataContext.SaveChanges();
        }
Пример #6
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          = etpEntityType.SelectedEntityTypeId;
            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;
            }

            var adding = dataView.Id.Equals(0);

            if (adding)
            {
                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();

            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);
        }
Пример #7
0
        public void AddStepDataViews()
        {
            var dataContext = new RockContext();

            // Add Data View Category "Steps".
            const string categoryDataViewStepsName = "Steps";

            Debug.Print($"Adding Data View Category \"{ categoryDataViewStepsName }\"...");

            var entityTypeId = EntityTypeCache.Get(typeof(Rock.Model.DataView)).Id;

            var stepsCategory = CreateCategory(categoryDataViewStepsName, Constants.CategoryStepsGuid, entityTypeId);

            AddOrUpdateCategory(dataContext, stepsCategory);

            dataContext.SaveChanges();

            // Create Data View: Steps Completed
            const string dataViewStepsCompleted2001Name = "Steps Completed in 2001";

            Debug.Print($"Adding Data View \"{ dataViewStepsCompleted2001Name }\"...");

            DataView dataView = new DataView();

            dataView.IsSystem = false;

            var service = new DataViewService(dataContext);

            int categoryId = CategoryCache.GetId(Constants.CategoryStepsGuid) ?? 0;

            dataView.Name         = dataViewStepsCompleted2001Name;
            dataView.Description  = "Steps that have a completion in the year 2001.";
            dataView.EntityTypeId = EntityTypeCache.GetId(typeof(Rock.Model.Step));
            dataView.CategoryId   = categoryId;
            dataView.Guid         = Constants.DataViewStepsCompleted2001Guid;
            dataView.ForeignKey   = _SampleDataForeignKey;

            var rootFilter = new DataViewFilter();

            rootFilter.ExpressionType = FilterExpressionType.GroupAll;

            dataView.DataViewFilter = rootFilter;

            // Add filter for Step Type
            var dateCompletedFilter = new DataViewFilter();

            dateCompletedFilter.ExpressionType = FilterExpressionType.Filter;
            dateCompletedFilter.EntityTypeId   = EntityTypeCache.GetId(typeof(Rock.Reporting.DataFilter.PropertyFilter));

            var dateFilterSettings = new List <string> {
                "Property_CompletedDateTime", "4096", "\tDateRange|||1/01/2001 12:00:00 AM|31/12/2001 12:00:00 AM"
            };

            dateCompletedFilter.Selection = dateFilterSettings.ToJson();

            rootFilter.ChildFilters.Add(dateCompletedFilter);

            service.Add(dataView);

            dataContext.SaveChanges();
        }