Beispiel #1
0
        /// <summary>
        /// Get the Financial Transaction Alert Types.
        /// </summary>
        private IQueryable <FinancialTransactionAlertType> GetFinancialTransactionAlertTypes(RockContext rockContext = null)
        {
            rockContext = rockContext ?? new RockContext();
            var financialTransactionAlertTypeService = new FinancialTransactionAlertTypeService(rockContext);

            return(financialTransactionAlertTypeService.Queryable().OrderBy(s => s.Order).ThenBy(s => s.Name));
        }
        /// <summary>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            // Set the date range
            var startDate = PageParameter(PageParameterKey.StartDate).AsDateTime();
            var endDate   = PageParameter(PageParameterKey.EndDate).AsDateTime();

            if (startDate.HasValue || endDate.HasValue)
            {
                drpDateRange.Visible = false;
            }
            else
            {
                drpDateRange.DelimitedValues = gfAlertFilter.GetUserPreference(FilterKey.DateRange);
            }

            // Bind alert types and categories if there is no query param
            var alertTypeId = PageParameter(PageParameterKey.AlertTypeId).AsIntegerOrNull();

            if (alertTypeId.HasValue)
            {
                cblAlertTypes.Visible    = false;
                cblAlertCategory.Visible = false;
            }
            else
            {
                // Bind alert types: the names of the alert types
                using (var rockContext = new RockContext())
                {
                    var alertTypeService = new FinancialTransactionAlertTypeService(rockContext);

                    cblAlertTypes.DataTextField  = "Value";
                    cblAlertTypes.DataValueField = "Key";
                    cblAlertTypes.DataSource     = alertTypeService.Queryable()
                                                   .AsNoTracking()
                                                   .Select(at => new
                    {
                        Key   = at.Id,
                        Value = at.Name
                    })
                                                   .ToList();

                    cblAlertTypes.DataBind();
                }

                var alertTypesValue = gfAlertFilter.GetUserPreference(FilterKey.AlertTypes);

                if (!string.IsNullOrWhiteSpace(alertTypesValue))
                {
                    cblAlertTypes.SetValues(alertTypesValue.Split(';').ToList());
                }

                // Bind alert categories: gratitude and follow-up
                cblAlertCategory.BindToEnum <AlertType>();
                var alertCategoryValue = gfAlertFilter.GetUserPreference(FilterKey.AlertCategory);

                if (!string.IsNullOrWhiteSpace(alertCategoryValue))
                {
                    cblAlertCategory.SetValues(alertCategoryValue.Split(';').ToList());
                }
            }

            // Don't show the person picker if the current context is already a specific person.
            if (GetPerson() != null)
            {
                ppPerson.Visible = false;
            }
            else
            {
                ppPerson.Visible = true;
                var personId = gfAlertFilter.GetUserPreference(FilterKey.Person).AsIntegerOrNull();
                if (personId.HasValue)
                {
                    var person = new PersonService(new RockContext()).Get(personId.Value);
                    ppPerson.SetValue(person);
                }
                else
                {
                    ppPerson.SetValue(null);
                }
            }

            // Set the transaction amount filter
            nreTransactionAmount.DelimitedValues = gfAlertFilter.GetUserPreference(FilterKey.TransactionAmount);

            // Campus picker
            if (GetCampusFromQuery() != null)
            {
                cpCampus.Visible = false;
            }
            else
            {
                cpCampus.SelectedCampusId = gfAlertFilter.GetUserPreference(FilterKey.Campus).AsIntegerOrNull();
            }
        }