Exemplo n.º 1
0
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Control[] controls, string selection)
        {
            var ddlDataView          = controls.GetByName <DataViewPicker>(_CtlDataView);
            var ddlRoleType          = controls.GetByName <RockDropDownList>(_CtlRoleType);
            var ddlFormat            = controls.GetByName <RockDropDownList>(_CtlFormat);
            var ddlGroupMemberStatus = controls.GetByName <RockDropDownList>(_CtlGroupStatus);

            var settings = new GroupParticipationSelectSettings(selection);

            if (!settings.IsValid)
            {
                return;
            }

            ddlFormat.SelectedValue = settings.ListFormat.ToString();

            if (settings.DataViewGuid.HasValue)
            {
                var dsService = new DataViewService(new RockContext());

                var dataView = dsService.Get(settings.DataViewGuid.Value);

                if (dataView != null)
                {
                    ddlDataView.SelectedValue = dataView.Id.ToString();
                }
            }

            ddlRoleType.SelectedValue          = settings.RoleType.ToStringSafe();
            ddlGroupMemberStatus.SelectedValue = settings.MemberStatus.ToStringSafe();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the Click event of the btnCancel 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 btnCancel_Click(object sender, EventArgs e)
        {
            // Check if we are editing an existing Data View.
            int dataViewId = hfDataViewId.Value.AsInteger();

            if (dataViewId == 0)
            {
                // If not, check if we are editing a new copy of an existing Data View.
                dataViewId = PageParameter("DataViewId").AsInteger();
            }

            if (dataViewId == 0)
            {
                int?parentCategoryId = PageParameter("ParentCategoryId").AsIntegerOrNull();
                if (parentCategoryId.HasValue)
                {
                    // Cancelling on Add, and we know the parentCategoryId, so we are probably in treeview mode, so navigate to the current page
                    var qryParams = new Dictionary <string, string>();
                    qryParams["CategoryId"] = parentCategoryId.ToString();
                    NavigateToPage(RockPage.Guid, qryParams);
                }
                else
                {
                    // Cancelling on Add.  Return to Grid
                    NavigateToParentPage();
                }
            }
            else
            {
                // Cancelling on Edit.  Return to Details
                DataViewService service = new DataViewService(new RockContext());
                DataView        item    = service.Get(dataViewId);
                ShowReadonlyDetails(item);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the Click event of the btnEdit 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 btnEdit_Click(object sender, EventArgs e)
        {
            var service = new DataViewService(new RockContext());
            var item    = service.Get(int.Parse(hfDataViewId.Value));

            ShowEditDetails(item);
        }
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap     = context.JobDetail.JobDataMap;
            var        rockContext = new RockContext();

            var             dv          = dataMap.GetString("DataView").AsGuid();
            DataViewService dataService = new DataViewService(rockContext);
            var             items       = dataService
                                          .Get(dv);
            List <string> list = new List <string>();
            var           qry  = items.GetQuery(null, null, out _);
            var           personalDeviceService = new PersonalDeviceService(rockContext);
            var           persons = ((IQueryable <Person>)qry).Select(p => p.Id).ToList();
            var           devices = personalDeviceService.Queryable()
                                    .Where(d => persons.Contains(d.PersonAlias.PersonId))
                                    .ToList();

            var errors = new List <string>();

            foreach (var device in devices)
            {
                device.PersonAliasId = null; //disaccociate the device but don't delete
                if (device.MACAddress.IsNotNullOrWhiteSpace())
                {
                    RemoveDeviceFromFrontPorch(device, errors);
                }
                rockContext.SaveChanges();
            }

            context.Result = string.Format("Removed {0} devices. {1} exceptions recorded", devices.Count(), errors.Count());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handles the GridRebind event of the gReport 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 gReport_GridRebind(object sender, EventArgs e)
        {
            var service = new DataViewService(new RockContext());
            var item    = service.Get(int.Parse(hfDataViewId.Value));

            ShowReport(item);
        }
Exemplo n.º 6
0
        protected void dvItemPicker_SelectItem(object sender, EventArgs e)
        {
            if (!dvItemPicker.SelectedValueAsId().HasValue)
            {
                return;
            }
            ddlEntities.Visible = true;

            using (var rockContext = new RockContext())
            {
                DataViewService dataViewService = new DataViewService(rockContext);
                var             dataview        = dataViewService.Get(dvItemPicker.SelectedValueAsId().Value);

                if (dataview.EntityType.Guid == new Guid(Rock.SystemGuid.EntityType.PERSON))
                {
                    List <Person> people = ((IQueryable <Person>)dataview.GetQuery(new DataViewGetQueryArgs()
                    {
                        SortProperty = null, DatabaseTimeoutSeconds = null
                    })).OrderBy(p => p.LastName).ToList();
                    Person emptyPerson   = new Person {
                        Id = -1, FirstName = "All People"
                    };
                    people.Insert(0, emptyPerson);
                    ddlEntities.DataSource = people;
                    ddlEntities.DataBind();
                }
            }
        }
        /// <summary>
        /// Sets the selection.
        /// Implement this version of SetSelection if your DataFilterComponent works the same in all FilterModes
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Type entityType, Control[] controls, string selection)
        {
            var dvpDataView          = controls.GetByName <DataViewItemPicker>(_CtlDataView);
            var ddlRoleType          = controls.GetByName <RockDropDownList>(_CtlRoleType);
            var ddlGroupMemberStatus = controls.GetByName <RockDropDownList>(_CtlGroupStatus);

            var settings = new SelectSettings(selection);

            if (!settings.IsValid)
            {
                return;
            }

            if (settings.DataViewGuid.HasValue)
            {
                var dsService = new DataViewService(new RockContext());

                var dataView = dsService.Get(settings.DataViewGuid.Value);

                dvpDataView.SetValue(dataView);
            }

            ddlRoleType.SelectedValue          = settings.RoleType.ToStringSafe();
            ddlGroupMemberStatus.SelectedValue = settings.MemberStatus.ToStringSafe();
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Retrieves and validates a DataView for use in a Filter of another Data View.
        /// </summary>
        /// <param name="dataViewGuid"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static DataView GetDataViewForFilterComponent(Guid?dataViewGuid, RockContext context = null)
        {
            if (!dataViewGuid.HasValue)
            {
                return(null);
            }

            context = context ?? new RockContext();

            var dsService = new DataViewService(context);

            DataView dataView = dsService.Get(dataViewGuid.Value);

            if (dataView == null ||
                dataView.DataViewFilter == null)
            {
                return(null);
            }

            // Verify that the Data View does not contain any references to itself in any of its components.
            // This configuration would cause a circular reference excpetion during evaluation of the Data View.
            if (dsService.IsViewInFilter(dataView.Id, dataView.DataViewFilter))
            {
                throw new Exception("Filter issue(s): One of the filters contains a circular reference to the Data View itself.");
            }

            return(dataView);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(System.Web.UI.Control[] controls, string selection)
        {
            var settings = new ParticipationRateSelectSettings(selection);

            if (!settings.IsValid())
            {
                return;
            }

            var ddlDataView = (DataViewPicker)controls[0];
            var ddlFormat   = (DropDownList)controls[1];

            if (settings.DataViewGuid.HasValue)
            {
                var dsService = new DataViewService(new RockContext());

                var dataView = dsService.Get(settings.DataViewGuid.Value);

                if (dataView != null)
                {
                    ddlDataView.SelectedValue = dataView.Id.ToString();
                }
            }

            ddlFormat.SelectedValue = settings.MeasureType.ToString();
        }
Exemplo n.º 10
0
 /// <summary>
 /// Handles the Click event of the btnCancel 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 btnCancel_Click(object sender, EventArgs e)
 {
     if (hfDataViewId.Value.Equals("0"))
     {
         int?parentCategoryId = PageParameter("ParentCategoryId").AsInteger(false);
         if (parentCategoryId.HasValue)
         {
             // Cancelling on Add, and we know the parentCategoryId, so we are probably in treeview mode, so navigate to the current page
             var qryParams = new Dictionary <string, string>();
             qryParams["CategoryId"] = parentCategoryId.ToString();
             NavigateToPage(RockPage.Guid, qryParams);
         }
         else
         {
             // Cancelling on Add.  Return to Grid
             NavigateToParentPage();
         }
     }
     else
     {
         // Cancelling on Edit.  Return to Details
         DataViewService service = new DataViewService(new RockContext());
         DataView        item    = service.Get(int.Parse(hfDataViewId.Value));
         ShowReadonlyDetails(item);
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Handles the Click event of the btnDelete 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 btnDelete_Click(object sender, EventArgs e)
        {
            int?categoryId = null;

            var rockContext     = new RockContext();
            var dataViewService = new DataViewService(rockContext);
            var dataView        = dataViewService.Get(int.Parse(hfDataViewId.Value));

            if (dataView != null)
            {
                string errorMessage;
                if (!dataViewService.CanDelete(dataView, out errorMessage))
                {
                    ShowReadonlyDetails(dataView);
                    mdDeleteWarning.Show(errorMessage, ModalAlertType.Information);
                }
                else
                {
                    categoryId = dataView.CategoryId;

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

                    // reload page, selecting the deleted data view's parent
                    var qryParams = new Dictionary <string, string>();
                    if (categoryId != null)
                    {
                        qryParams["CategoryId"] = categoryId.ToString();
                    }

                    NavigateToPage(RockPage.Guid, qryParams);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            var person = GetPersonAliasFromActionAttribute("Person", rockContext, action, errorMessages);

            if (person != null)
            {
                Guid booleanGuid = GetAttributeValue(action, "Boolean").AsGuid();
                if (!booleanGuid.IsEmpty())
                {
                    var attribute = AttributeCache.Get(booleanGuid, rockContext);
                    if (attribute != null)
                    {
                        var dataViewAttributeGuid = GetAttributeValue(action, "DataView").AsGuid();
                        if (dataViewAttributeGuid != Guid.Empty)
                        {
                            var dataViewService = new DataViewService(rockContext);
                            var dataView        = dataViewService.Get(dataViewAttributeGuid);
                            if (dataView != null)
                            {
                                var       timeout       = GetAttributeValue(action, "Timeout").AsIntegerOrNull();
                                Stopwatch stopwatch     = Stopwatch.StartNew();
                                var       qry           = dataView.GetQuery(null, timeout, out errorMessages);
                                var       isPersonFound = false;
                                if (qry != null)
                                {
                                    isPersonFound = qry.Where(e => e.Id == person.Id).Any();
                                    stopwatch.Stop();
                                    DataViewService.AddRunDataViewTransaction(dataView.Id,
                                                                              Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds));
                                }

                                if (isPersonFound)
                                {
                                    SetWorkflowAttributeValue(action, booleanGuid, "True");
                                }
                                else
                                {
                                    SetWorkflowAttributeValue(action, booleanGuid, "False");
                                }
                            }
                        }
                    }
                    else
                    {
                        errorMessages.Add("DataView could not be found.");
                    }
                }
            }
            else
            {
                errorMessages.Add("No person was provided for DataView.");
            }

            errorMessages.ForEach(m => action.AddLogEntry(m, true));

            return(true);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Perform the job using the parameters supplied in the execution context.
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            // Get the configuration settings for this job instance.
            var dataMap = context.JobDetail.JobDataMap;

            var workflowTypeGuid = dataMap.GetString(AttributeKey.Workflow).AsGuidOrNull();
            var dataViewGuid     = dataMap.GetString(AttributeKey.DataView).AsGuidOrNull();

            if (dataViewGuid == null)
            {
                throw new Exception("Data view not selected");
            }

            var rockContext     = new RockContext();
            var dataViewService = new DataViewService(rockContext);
            var dataView        = dataViewService.Get(dataViewGuid.Value);

            if (dataView == null)
            {
                throw new Exception("Data view not found");
            }

            // Get the set of entity key values returned by the Data View.
            var errorMessages = new List <string>();

            var qry = dataView.GetQuery(null, rockContext, null, out errorMessages);

            var modelType = dataView.EntityType.GetType();

            if (qry == null)
            {
                throw new Exception("Data view results not found");
            }

            if (modelType == null)
            {
                throw new Exception("Entity type of data view not found");
            }

            var entityIds = qry.Select(e => e.Id).ToList();

            var entityTypeId   = dataView.EntityTypeId.Value;
            var entityTypeName = modelType.GetFriendlyTypeName();

            int workflowsLaunched = 0;

            // For each entity, create a new transaction to launch a workflow.
            foreach (var entityId in entityIds)
            {
                var transaction = new LaunchEntityWorkflowTransaction(workflowTypeGuid.Value, string.Empty, entityTypeId, entityId);

                Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);

                workflowsLaunched++;
            }

            context.Result = string.Format("{0} workflows launched", workflowsLaunched);
        }
Exemplo n.º 14
0
        /// <summary>
        ///     Returns the Id of the specified DataView.
        /// </summary>
        /// <param name="dataViewGuid">The Guid of an existing Data View.</param>
        /// <returns>The Id of the specified DataView, or null if the Data View does not exist.</returns>
        public static int?GetDataViewId(Guid?dataViewGuid)
        {
            if (!dataViewGuid.HasValue)
            {
                return(null);
            }

            var dsService = new DataViewService(new RockContext());

            var dataView = dsService.Get(dataViewGuid.Value);

            return((dataView != null) ? (int?)dataView.Id : null);
        }
Exemplo n.º 15
0
        private bool CanAutoApply(Person person)
        {
            var userCanApply     = false;
            var approvedDataview = GetAttributeValue("ApprovedDataView").AsGuidOrNull();

            RockContext rockContext = new RockContext();

            if (approvedDataview.HasValue)
            {
                DataViewService dataViewService = new DataViewService(rockContext);
                var             dv = dataViewService.Get(approvedDataview.Value);
                if (dv != null)
                {
                    var qry = (IQueryable <Person>)dv.GetQuery(new DataViewGetQueryArgs {
                        DatabaseTimeoutSeconds = 30
                    });
                    if (qry.Where(p => p.Id == CurrentPersonId).Any())
                    {
                        userCanApply = true;
                    }
                }
            }
            else
            {
                userCanApply = GetAttributeValue("AutoApply").AsBoolean();
            }

            if (!userCanApply)
            {
                return(false);
            }

            var blackListDV = GetAttributeValue("BlacklistDataView").AsGuidOrNull();

            if (blackListDV.HasValue)
            {
                DataViewService dataViewService = new DataViewService(rockContext);
                var             dv = dataViewService.Get(blackListDV.Value);
                if (dv != null)
                {
                    var qry = (IQueryable <Person>)dv.GetQuery(new DataViewGetQueryArgs {
                        DatabaseTimeoutSeconds = 30
                    });
                    if (qry.Where(p => p.Id == person.Id).Any())
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Execute method to write transaction to the database.
        /// </summary>
        public void Execute()
        {
            using (var rockContext = new RockContext())
            {
                var dataViewService = new DataViewService(rockContext);
                var dataView        = dataViewService.Get(DataViewId);

                if (dataView == null)
                {
                    return;
                }

                if (LastRunDateTime != null)
                {
                    dataView.LastRunDateTime = LastRunDateTime;
                    if (ShouldIncrementRunCount)
                    {
                        dataView.RunCount = (dataView.RunCount ?? 0) + 1;
                    }
                }

                if (PersistedLastRefreshDateTime != null)
                {
                    dataView.PersistedLastRefreshDateTime = PersistedLastRefreshDateTime;
                }

                if (PersistedLastRunDurationMilliseconds != null)
                {
                    dataView.PersistedLastRunDurationMilliseconds = PersistedLastRunDurationMilliseconds;
                }

                // We will only update the RunCount if we were given a TimeToRun value.
                if (TimeToRunDurationMilliseconds != null)
                {
                    dataView.TimeToRunDurationMilliseconds = TimeToRunDurationMilliseconds;
                }

                /*
                 *  8/3/2020 - JH
                 *  We are calling the SaveChanges( true ) overload that disables pre/post processing hooks
                 *  because we only want to change the properties explicitly set above. If we don't disable
                 *  these hooks, the [ModifiedDateTime] value will also be updated every time a DataView is
                 *  run, which is not what we want here.
                 *
                 *  Reason: GitHub Issue #4321
                 *  https://github.com/SparkDevNetwork/Rock/issues/4321
                 */
                rockContext.SaveChanges(true);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            var person = GetPersonAliasFromActionAttribute("Person", rockContext, action, errorMessages);

            if (person != null)
            {
                Guid booleanGuid = GetAttributeValue(action, "Boolean").AsGuid();
                if (!booleanGuid.IsEmpty())
                {
                    var attribute = AttributeCache.Read(booleanGuid, rockContext);
                    if (attribute != null)
                    {
                        var dataViewAttributeGuid = GetAttributeValue(action, "DataView").AsGuid();
                        if (dataViewAttributeGuid != Guid.Empty)
                        {
                            var dataViewService = new DataViewService(rockContext);
                            var dataView        = dataViewService.Get(dataViewAttributeGuid);
                            if (dataView != null)
                            {
                                var timeout = GetAttributeValue(action, "Timeout").AsIntegerOrNull();
                                var qry     = dataView.GetQuery(null, timeout, out errorMessages);
                                if (qry != null && qry.Where(e => e.Id == person.Id).Any())
                                {
                                    SetWorkflowAttributeValue(action, booleanGuid, "True");
                                }
                                else
                                {
                                    SetWorkflowAttributeValue(action, booleanGuid, "False");
                                }
                            }
                        }
                    }
                    else
                    {
                        errorMessages.Add("DataView could not be found.");
                    }
                }
            }
            else
            {
                errorMessages.Add("No person was provided for DataView.");
            }

            errorMessages.ForEach(m => action.AddLogEntry(m, true));

            return(true);
        }
Exemplo n.º 18
0
        /// <summary>
        ///     Returns the Guid of the specified DataView.
        /// </summary>
        /// <param name="dataViewId"></param>
        /// <returns>The Guid of the specified DataView, or null if the Data View does not exist.</returns>
        public static Guid?GetDataViewGuid(string dataViewId)
        {
            var id = dataViewId.AsIntegerOrNull();

            if (id == null)
            {
                return(null);
            }

            var dsService = new DataViewService(new RockContext());

            var dataView = dsService.Get(id.Value);

            return(dataView.Guid);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Handles the Click event of the btnDelete 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 btnDelete_Click(object sender, EventArgs e)
        {
            int?categoryId = null;

            var rockContext     = new RockContext();
            var dataViewService = new DataViewService(rockContext);
            var dataView        = dataViewService.Get(int.Parse(hfDataViewId.Value));

            if (dataView != null)
            {
                string errorMessage;
                if (!dataViewService.CanDelete(dataView, out errorMessage))
                {
                    ShowReadonlyDetails(dataView);
                    mdDeleteWarning.Show(errorMessage, ModalAlertType.Information);
                }
                else
                {
                    categoryId = dataView.CategoryId;

                    // delete report filter
                    try
                    {
                        DataViewFilterService dataViewFilterService = new DataViewFilterService(rockContext);
                        DeleteDataViewFilter(dataView.DataViewFilter, dataViewFilterService);
                    }
                    catch
                    {
                        // intentionally ignore if delete fails
                    }

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

                    // reload page, selecting the deleted data view's parent
                    var qryParams = new Dictionary <string, string>();
                    if (categoryId != null)
                    {
                        qryParams["CategoryId"] = categoryId.ToString();
                    }

                    qryParams["DataViewId"]       = null;
                    qryParams["ParentCategoryId"] = null;
                    NavigateToCurrentPageReference(qryParams);
                }
            }
        }
Exemplo n.º 20
0
        private void CheckForBlacklist(ChangeRequest changeRequest)
        {
            var blackListDV = GetAttributeValue("BlacklistDataView").AsGuidOrNull();

            if (blackListDV.HasValue)
            {
                RockContext rockContext      = new RockContext();
                List <int>  relatedPersonIds = new List <int>();

                if (changeRequest.EntityTypeId == EntityTypeCache.Get(typeof(PersonAlias)).Id)
                {
                    PersonAliasService personAliasService = new PersonAliasService(rockContext);
                    var personAlias = personAliasService.Get(changeRequest.EntityId);
                    if (personAlias != null)
                    {
                        relatedPersonIds.Add(personAlias.PersonId);
                    }
                }
                else if (changeRequest.EntityTypeId == EntityTypeCache.Get(typeof(Person)).Id)
                {
                    relatedPersonIds.Add(changeRequest.EntityId);
                }
                else if (changeRequest.EntityTypeId == EntityTypeCache.Get(typeof(Group)).Id)
                {
                    GroupService groupService = new GroupService(rockContext);
                    var          family       = groupService.Get(changeRequest.EntityId);
                    if (family != null)
                    {
                        relatedPersonIds.AddRange(family.Members.Select(m => m.PersonId));
                    }
                }
                DataViewService dataViewService = new DataViewService(rockContext);
                var             dv = dataViewService.Get(blackListDV.Value);
                if (dv != null)
                {
                    var qry = (IQueryable <Person>)dv.GetQuery(new DataViewGetQueryArgs {
                        DatabaseTimeoutSeconds = 30
                    });

                    if (qry.Where(p => relatedPersonIds.Contains(p.Id)).Any())
                    {
                        nbBlacklistWarning.Visible = true;
                    }
                }
            }
        }
Exemplo n.º 21
0
            public void ParseDataViewId(string dataViewId)
            {
                var id = dataViewId.AsIntegerOrNull();

                if (id != null)
                {
                    var dsService = new DataViewService(new RockContext());

                    var dataView = dsService.Get(id.Value);

                    DataViewGuid = dataView.Guid;
                }
                else
                {
                    DataViewGuid = null;
                }
            }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                tbGivingId.Text     = GetBlockUserPreference("GivingIdFilter");
                tbGivingGroup.Text  = GetBlockUserPreference("GivingGroupFilter");
                drpDates.LowerValue = GetBlockUserPreference("LastGiftDateRangeFilterLower").AsDateTime();
                drpDates.UpperValue = GetBlockUserPreference("LastGiftDateRangeFilterUpper").AsDateTime();
                if (GetAttributeValue("DefaultReviewDataView").IsNotNullOrWhiteSpace())
                {
                    DataViewService dataViewService = new DataViewService(new RockContext());
                    dvipReviewDataView.SetValue(dataViewService.Get(GetAttributeValue("DefaultReviewDataView").AsGuid()));
                }
                DisplayResults();
            }
        }
Exemplo n.º 23
0
        private IQueryable <Person> GetRecipients()
        {
            RockContext rockContext = new RockContext();

            var audienceId = this.AlertNotification.AudienceValueId;
            var audience   = DefinedValueCache.Get(audienceId);

            var dataViewGuid = audience.GetAttributeValue("DataView").AsGuid();

            var dataViewService = new DataViewService(rockContext);
            var dataView        = dataViewService.Get(dataViewGuid);

            int           timeout = 30;
            List <string> errorMessages;
            var           qry        = dataView.GetQuery(null, timeout, out errorMessages);
            var           recipients = qry.Select(e => ( Person )e);

            return(recipients);
        }
Exemplo n.º 24
0
        private IQueryable <Person> GetRecipients()
        {
            RockContext rockContext = new RockContext();

            var audienceId = this.AlertNotification.AudienceValueId;
            var audience   = DefinedValueCache.Get(audienceId);

            var dataViewGuid = audience.GetAttributeValue("DataView").AsGuid();

            var dataViewService = new DataViewService(rockContext);
            var dataView        = dataViewService.Get(dataViewGuid);

            var qry = dataView.GetQuery(new DataViewGetQueryArgs {
                DatabaseTimeoutSeconds = 30
            });
            var recipients = qry.Select(e => ( Person )e);

            return(recipients);
        }
Exemplo n.º 25
0
        private void BindGrid()
        {
            Person          person      = new Person();
            var             l           = GetAttributeValue("Limit").AsInteger();
            var             tt          = GetAttributeValue("DataView");
            Guid            newguid     = new Guid(tt);
            RockContext     rockContext = new RockContext();
            DataViewService dataService = new DataViewService(rockContext);
            var             items       = dataService
                                          .Get(newguid);
            List <string> list       = new List <string>();
            var           qry        = items.GetQuery(new DataViewGetQueryArgs());
            var           personList = (IQueryable <Person>)qry;
            var           plist      = personList
                                       .Where(p => p.BirthDate != null)
                                       .OrderBy(p => p.DaysUntilBirthday);
            List <Person> plistd = new List <Person>();

            if (l != 0)
            {
                var plist2 = plist.Take(l);
                plistd = plist2.ToList();
            }
            else
            {
                plistd = plist.ToList();
            }
            var lava = GetAttributeValue("Lava");

            if (string.IsNullOrWhiteSpace(lava))
            {
                gPeople.DataSource = plistd;
                gPeople.DataBind();
            }
            else
            {
                Dictionary <string, object> mergeObjects = new Dictionary <string, object>
                {
                    { "People", plistd }
                };
                lLava.Text = ProcessLava(lava, person, mergeObjects);
            }
        }
Exemplo n.º 26
0
        protected void btnSelect_Click(object sender, EventArgs e)
        {
            var groupId = ( int )ViewState["GroupId"];

            //Make a fake group member so we can get the attributes to filter by
            var groupMember = new GroupMember {
                GroupId = groupId
            };

            groupMember.LoadAttributes();

            var attributes = groupMember.Attributes.Select(a => a.Value).Where(a => a.IsGridColumn).ToList();

            RockContext        rockContext        = new RockContext();
            GroupMemberService groupMemberService = new GroupMemberService(rockContext);

            var qry = groupMemberService.Queryable()
                      .Where(gm => gm.GroupId == groupId);

            foreach (var attribute in attributes)
            {
                var filterControl = phFilter.FindControl("filter_" + attribute.Id.ToString());
                qry = attribute.FieldType.Field.ApplyAttributeQueryFilter(qry, filterControl, attribute, groupMemberService, Rock.Reporting.FilterMode.SimpleFilter);
            }

            if (dvDataView.SelectedValueAsId().HasValue)
            {
                var dataviewId = dvDataView.SelectedValueAsId().Value;

                DataViewService dataViewService = new DataViewService(rockContext);
                var             dataView        = dataViewService.Get(dataviewId);

                if (dataView != null && dataView.IsAuthorized(Authorization.VIEW, CurrentPerson))
                {
                    var dvQuery = dataView.GetQuery(new DataViewGetQueryArgs {
                        DbContext = rockContext, DatabaseTimeoutSeconds = 60
                    });
                    qry = qry.Where(m => dvQuery.Select(p => p.Id).Contains(m.PersonId));
                }
            }

            BuildCommunication(qry.ToList());
        }
Exemplo n.º 27
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed)
        {
            string formattedValue = string.Empty;

            Guid?guid = value.AsGuidOrNull();

            if (guid.HasValue)
            {
                var service  = new DataViewService(new RockContext());
                var dataview = service.Get(guid.Value);

                if (dataview != null)
                {
                    formattedValue = dataview.Name;
                }
            }

            return(base.FormatValue(parentControl, formattedValue, null, condensed));
        }
Exemplo n.º 28
0
        protected void dvpDataViewPicker_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlEntities.Visible = true;
            using (var rockContext = new RockContext())
            {
                var             errors          = new List <string>();
                DataViewService dataViewService = new DataViewService(rockContext);
                var             dataview        = dataViewService.Get(dvpDataViewPicker.SelectedValue.AsInteger());

                if (dataview.EntityType.Guid == new Guid(Rock.SystemGuid.EntityType.PERSON))
                {
                    List <Person> people      = ((IQueryable <Person>)dataview.GetQuery(null, null, out errors)).OrderBy(p => p.LastName).ToList();
                    Person        emptyPerson = new Person {
                        Id = -1, FirstName = "All People"
                    };
                    people.Insert(0, emptyPerson);
                    ddlEntities.DataSource = people;
                    ddlEntities.DataBind();
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Renders the specified writer.
        /// </summary>
        /// <param name="badge">The badge.</param>
        /// <param name="writer">The writer.</param>
        public override void Render(PersonBadgeCache badge, System.Web.UI.HtmlTextWriter writer)
        {
            RockContext rockContext           = new RockContext();
            var         dataViewAttributeGuid = GetAttributeValue(badge, "DataView").AsGuid();
            var         dataViewService       = new DataViewService(rockContext);

            if (dataViewAttributeGuid != Guid.Empty)
            {
                var dataView = dataViewService.Get(dataViewAttributeGuid);
                if (dataView != null)
                {
                    var errors = new List <string>();
                    var qry    = dataView.GetQuery(null, 30, out errors);
                    if (qry != null && qry.Where(e => e.Id == Person.Id).Any())
                    {
                        Dictionary <string, object> mergeValues = new Dictionary <string, object>();
                        mergeValues.Add("Person", Person);
                        writer.Write(GetAttributeValue(badge, "BadgeContent").ResolveMergeFields(mergeValues));
                    }
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Handles the Click event of the btnCancel 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 btnCancel_Click(object sender, EventArgs e)
        {
            if (hfDataViewId.Value.Equals("0"))
            {
                // Cancelling on Add.  Return to tree view with parent category selected
                var qryParams = new Dictionary <string, string>();

                string parentCategoryId = PageParameter("parentCategoryId");
                if (!string.IsNullOrWhiteSpace(parentCategoryId))
                {
                    qryParams["CategoryId"] = parentCategoryId;
                }
                NavigateToPage(this.CurrentPage.Guid, qryParams);
            }
            else
            {
                // Cancelling on Edit.  Return to Details
                DataViewService service = new DataViewService();
                DataView        item    = service.Get(int.Parse(hfDataViewId.Value));
                ShowReadonlyDetails(item);
            }
        }