コード例 #1
0
        /// <summary>
        /// Binds the grid for defined types.
        /// </summary>
        private void rGridType_Bind()
        {
            var queryable = new DefinedTypeService().Queryable().
                            Where(a => a.Category != "" && a.Category != null);

            if (ddlCategoryFilter.SelectedValue != "[All]")
            {
                queryable = queryable.
                            Where(a => a.Category == ddlCategoryFilter.SelectedValue);
            }

            SortProperty sortProperty = rGridType.SortProperty;

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

            rGridType.DataSource = queryable.ToList();
            rGridType.DataBind();
        }
コード例 #2
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)
        {
            DefinedTypeService definedTypeService = new DefinedTypeService(new RockContext());
            DefinedType        definedType        = definedTypeService.Get(hfDefinedTypeId.ValueAsInt());

            ShowEditDetails(definedType);
        }
コード例 #3
0
        /// <summary>
        /// Shows the type of the edit.
        /// </summary>
        /// <param name="typeId">The type id.</param>
        protected void ShowEditType(int typeId)
        {
            var typeModel = new DefinedTypeService().Get(typeId);

            if (typeModel != null)
            {
                var type = Rock.Web.Cache.DefinedTypeCache.Read(typeModel);
                lType.Text             = "Editing " + typeModel.Name;
                hfIdType.Value         = typeId.ToString();
                tbTypeName.Text        = typeModel.Name;
                tbTypeCategory.Text    = typeModel.Category;
                tbTypeDescription.Text = typeModel.Description;
                if (typeModel.FieldTypeId != null)
                {
                    ddlTypeFieldType.SelectedValue = typeModel.FieldTypeId.ToString();
                }
            }
            else
            {
                lType.Text             = "Adding Defined Type";
                hfIdType.Value         = string.Empty;
                tbTypeName.Text        = string.Empty;
                tbTypeCategory.Text    = string.Empty;
                tbTypeDescription.Text = string.Empty;
            }

            pnlTypes.Visible       = false;
            pnlTypeDetails.Visible = true;
        }
コード例 #4
0
        /// <summary>
        /// Handles the Delete event of the rGridType 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 rGridType_Delete(object sender, RowEventArgs e)
        {
            DefinedType type = new DefinedTypeService().Get((int)rGridType.DataKeys[e.RowIndex]["id"]);

            var valueService = new DefinedValueService();
            var typeService  = new DefinedTypeService();


            if (type != null)
            {
                // if this DefinedType has DefinedValues, delete them
                var hasDefinedValues = valueService
                                       .GetByDefinedTypeId(type.Id)
                                       .ToList();

                foreach (var value in hasDefinedValues)
                {
                    valueService.Delete(value, CurrentPersonId);
                    valueService.Save(value, CurrentPersonId);
                }

                typeService.Delete(type, CurrentPersonId);
                typeService.Save(type, CurrentPersonId);
            }

            rGridType_Bind();
        }
コード例 #5
0
        /// <summary>
        /// Reads the specified GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        public static DefinedTypeCache Read(Guid guid)
        {
            ObjectCache cache    = MemoryCache.Default;
            object      cacheObj = cache[guid.ToString()];

            if (cacheObj != null)
            {
                return(Read((int)cacheObj));
            }
            else
            {
                var definedTypeService = new DefinedTypeService();
                var definedTypeModel   = definedTypeService
                                         .Queryable("DefinedValues")
                                         .Where(t => t.Guid == guid)
                                         .FirstOrDefault();

                if (definedTypeModel != null)
                {
                    definedTypeModel.LoadAttributes();
                    var definedType = new DefinedTypeCache(definedTypeModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(DefinedTypeCache.CacheKey(definedType.Id), definedType, cachePolicy);
                    cache.Set(definedType.Guid.ToString(), definedType.Id, cachePolicy);

                    return(definedType);
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Operations to be performed during the upgrade process.
        /// </summary>
        public override void Up()
        {
            var zrDefinedTypeId = new DefinedTypeService(new Rock.Data.RockContext()).Get(ZoomGuid.DefinedType.ZOOM_ROOM.AsGuid()).Id;

            RockMigrationHelper.AddAttributeQualifier(ZoomGuid.Attribute.ZOOM_ROOM_LOCATION_ENTITY_ATTRIBUTE, "definedtype", zrDefinedTypeId.ToString(), "D210E7BF-7C3D-4B8E-A8AB-423C97DA6FACf");
            RockMigrationHelper.AddAttributeQualifier(ZoomGuid.Attribute.ZOOM_ROOM_LOCATION_ENTITY_ATTRIBUTE, "displaydescription", "True", "85D4A488-3F71-49EF-9EBC-28927D4C15A4");
        }
コード例 #7
0
        /// <summary>
        /// Binds the grid for defined types.
        /// </summary>
        private void gDefinedType_Bind()
        {
            var queryable = new DefinedTypeService().Queryable().Select(a =>
                                                                        new
            {
                a.Id,
                a.Category,
                a.Name,
                a.Description,
                FieldTypeName = a.FieldType.Name
            });

            string categoryFilter = tFilter.GetUserPreference("Category");

            if (!string.IsNullOrWhiteSpace(categoryFilter) && categoryFilter != Rock.Constants.All.Text)
            {
                queryable = queryable.Where(a => a.Category == categoryFilter);
            }

            SortProperty sortProperty = gDefinedType.SortProperty;

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

            gDefinedType.DataSource = queryable.ToList();
            gDefinedType.DataBind();
        }
コード例 #8
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        public void ShowDetail(string itemKey, int itemKeyValue)
        {
            if (!itemKey.Equals("definedTypeId"))
            {
                return;
            }

            pnlDetails.Visible = true;
            DefinedType definedType = null;

            if (!itemKeyValue.Equals(0))
            {
                definedType = new DefinedTypeService().Get(itemKeyValue);
            }
            else
            {
                definedType = new DefinedType {
                    Id = 0
                };
            }

            hfDefinedTypeId.SetValue(definedType.Id);

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized("Edit"))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(DefinedType.FriendlyTypeName);
            }

            if (definedType.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(DefinedType.FriendlyTypeName);
            }

            if (readOnly)
            {
                btnEdit.Visible = false;
                ShowReadonlyDetails(definedType);
            }
            else
            {
                btnEdit.Visible = true;
                if (definedType.Id > 0)
                {
                    ShowReadonlyDetails(definedType);
                }
                else
                {
                    ShowEditDetails(definedType);
                }
            }

            BindDefinedTypeAttributesGrid();
            BindDefinedValuesGrid();
        }
コード例 #9
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)
        {
            RockContext        rockContext        = new RockContext();
            DefinedTypeService definedTypeService = new DefinedTypeService(rockContext);
            DefinedType        definedType        = definedTypeService.Get(int.Parse(hfDefinedTypeId.Value));

            if (definedType != null)
            {
                if (!definedType.IsAuthorized(Authorization.EDIT, this.CurrentPerson))
                {
                    mdDeleteWarning.Show("Sorry, You are not authorized to delete this Defined Type.", ModalAlertType.Information);
                    return;
                }

                string errorMessage;
                if (!definedTypeService.CanDelete(definedType, out errorMessage))
                {
                    mdDeleteWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                definedTypeService.Delete(definedType);

                rockContext.SaveChanges();
            }

            NavigateToParentPage();
        }
コード例 #10
0
        /// <summary>
        /// Displays the edit list.
        /// </summary>
        private void DisplayEditList()
        {
            lEditHeader.Text = GetAttributeValue("EditHeader");
            lEditFooter.Text = GetAttributeValue("EditFooter");

            if (_definedType != null)
            {
                using (var rockContext = new RockContext())
                {
                    var entityType  = EntityTypeCache.Get("Rock.Model.DefinedValue");
                    var definedType = new DefinedTypeService(rockContext).Get(_definedType.Id);
                    if (definedType != null && entityType != null)
                    {
                        var attributeService = new AttributeService(rockContext);
                        var attributes       = new AttributeService(rockContext)
                                               .GetByEntityTypeQualifier(entityType.Id, "DefinedTypeId", definedType.Id.ToString(), false)
                                               .ToList();

                        // Verify (and create if necessary) the "Is Link" attribute
                        if (!attributes.Any(a => a.Key == "IsLink"))
                        {
                            var fieldType = FieldTypeCache.Get(Rock.SystemGuid.FieldType.BOOLEAN);
                            if (entityType != null && fieldType != null)
                            {
                                var attribute = new Rock.Model.Attribute();
                                attributeService.Add(attribute);
                                attribute.EntityTypeId = entityType.Id;
                                attribute.EntityTypeQualifierColumn = "DefinedTypeId";
                                attribute.EntityTypeQualifierValue  = definedType.Id.ToString();
                                attribute.FieldTypeId  = fieldType.Id;
                                attribute.Name         = "Is Link";
                                attribute.Key          = "IsLink";
                                attribute.Description  = "Flag indicating if value is a link (vs Header)";
                                attribute.IsGridColumn = true;
                                attribute.DefaultValue = true.ToString();

                                var qualifier1 = new AttributeQualifier();
                                qualifier1.Key   = "truetext";
                                qualifier1.Value = "Yes";
                                attribute.AttributeQualifiers.Add(qualifier1);

                                var qualifier2 = new AttributeQualifier();
                                qualifier2.Key   = "falsetext";
                                qualifier2.Value = "No";
                                attribute.AttributeQualifiers.Add(qualifier2);

                                rockContext.SaveChanges();
                            }
                        }
                    }
                }

                BindGrid();

                pnlView.Visible = false;
                pnlEdit.Visible = true;
            }
        }
コード例 #11
0
        /// <summary>
        /// Binds the grid for defined types.
        /// </summary>
        private void gDefinedType_Bind()
        {
            var queryable = new DefinedTypeService(new RockContext()).Queryable();

            if (_categoryGuids.Any())
            {
                queryable = queryable.Where(a => a.Category != null && _categoryGuids.Contains(a.Category.Guid));
            }
            else
            {
                int?categoryId = tFilter.GetUserPreference("Category").AsIntegerOrNull();
                if (categoryId.HasValue)
                {
                    queryable = queryable.Where(a => a.CategoryId.HasValue && a.CategoryId.Value == categoryId.Value);
                }
            }

            SortProperty sortProperty = gDefinedType.SortProperty;

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

            gDefinedType.DataSource = queryable
                                      .Select(a =>
                                              new
            {
                a.Id,
                Category = a.Category.Name,
                a.Name,
                a.Description,
                a.IsSystem,
                FieldTypeName = a.FieldType.Name
            })
                                      .ToList();

            // SanitizeHtml can't be compilied into a SQL query so we have to ToList() the data and then sanitize the field in the List<T>
            //gDefinedType.DataSource = dataSource
            //    .Select( a =>
            //        new
            //        {
            //            a.Id,
            //            a.Category,
            //            a.Name,
            //            Description = a.Description.ScrubHtmlForGridDisplay(),
            //            a.IsSystem,
            //            a.FieldTypeName
            //        } )
            //    .ToList();
            gDefinedType.DataBind();
        }
コード例 #12
0
ファイル: Zoom.cs プロジェクト: KingdomFirst/RockAssemblies
        public static void SyncZoomRoomDT(RockContext rockContext = null, bool enableLogging = false)
        {
            if (rockContext == null)
            {
                rockContext = new RockContext();
            }
            if (enableLogging)
            {
                LogEvent(rockContext, "SyncZoom", "Sync Zoom Rooms Defined Type", "Started");
            }
            var zoom   = Api();
            var zrList = zoom.GetZoomRoomList().OrderBy(r => r.Zr_Name);

            if (enableLogging)
            {
                LogEvent(rockContext, "SyncZoom", "Get Zoom Rooms using Zoom API", string.Format("zoom.GetZoomRoomList() found {0} rooms.", zrList.Count()));
            }

            var zoomRoomDT = new DefinedTypeService(rockContext).Get(ZoomGuid.DefinedType.ZOOM_ROOM.AsGuid());

            // Delete DefinedValue for any rooms that no longer exist
            var zoomRoomsToDelete = zoomRoomDT.DefinedValues.Where(v => !zrList.Select(zr => zr.Zr_Id).Contains(v.Value));

            foreach (var zrDV in zoomRoomsToDelete)
            {
                zoomRoomDT.DefinedValues.Remove(zrDV);
            }

            if (enableLogging)
            {
                LogEvent(null, "SyncZoom", "Remove Defined Values for Zoom Rooms that no longer exist.", string.Format("Deleted {0} Zoom Room Defined Value(s).", zoomRoomsToDelete.Count()));
            }

            // Add DefinedValue for any new Zoom Rooms
            var newZoomRooms = zrList.Where(r => !zoomRoomDT.DefinedValues.Select(v => v.Value).Contains(r.Zr_Id))
                               .Select(r => new DefinedValue
            {
                Value       = r.Zr_Id,
                Description = r.Zr_Name
            });

            foreach (var roomDV in newZoomRooms)
            {
                zoomRoomDT.DefinedValues.Add(roomDV);
            }
            rockContext.SaveChanges();

            if (enableLogging)
            {
                LogEvent(rockContext, "SyncZoom", "Add Defined Values for new Zoom Rooms.", string.Format("Added {0} Zoom Room Defined Value(s).", newZoomRooms.Count()));
            }
            if (enableLogging)
            {
                LogEvent(rockContext, "SyncZoom", "Sync Zoom Rooms Defined Type", "Finished");
            }
        }
コード例 #13
0
        private static int LoadByGuid2(Guid guid, RockContext rockContext)
        {
            var definedTypeService = new DefinedTypeService(rockContext);

            return(definedTypeService
                   .Queryable().AsNoTracking()
                   .Where(c => c.Guid.Equals(guid))
                   .Select(c => c.Id)
                   .FirstOrDefault());
        }
コード例 #14
0
        /// <summary>
        /// Shows the settings.
        /// </summary>
        protected override void ShowSettings()
        {
            pnlSettings.Visible = true;

            ddlTransactionType.DefinedTypeId = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.FINANCIAL_TRANSACTION_TYPE.AsGuid()).Id;

            DefinedValueCache blockTransactionType = null;
            Guid?blockTransactionTypeGuid          = this.GetAttributeValue("TransactionTypeGuid").AsGuidOrNull();

            if (blockTransactionTypeGuid.HasValue)
            {
                blockTransactionType = DefinedValueCache.Get(blockTransactionTypeGuid.Value);
            }

            ddlTransactionType.SetValue(blockTransactionType != null ? blockTransactionType.Id : ( int? )null);

            var rockContext = new RockContext();

            gtpGroupType.GroupTypes = new GroupTypeService(rockContext).Queryable().OrderBy(a => a.Order).ThenBy(a => a.Name).AsNoTracking().ToList();
            ddlDefinedTypePicker.Items.Clear();
            ddlDefinedTypePicker.Items.Add(new ListItem());
            var definedTypesList = new DefinedTypeService(rockContext).Queryable().OrderBy(a => a.Name)
                                   .Select(a => new
            {
                a.Id,
                a.Name
            }).ToList();

            foreach (var definedType in definedTypesList)
            {
                ddlDefinedTypePicker.Items.Add(new ListItem(definedType.Name, definedType.Id.ToString()));
            }

            var entityTypeGuid          = this.GetAttributeValue("EntityTypeGuid").AsGuidOrNull();
            var entityTypeIdGroupMember = EntityTypeCache.GetId <GroupMember>();

            etpEntityType.EntityTypes = new EntityTypeService(rockContext).Queryable().Where(a => (a.IsEntity && a.SingleValueFieldTypeId.HasValue) || (a.Id == entityTypeIdGroupMember)).OrderBy(t => t.FriendlyName).AsNoTracking().ToList();

            if (entityTypeGuid.HasValue)
            {
                var entityType = EntityTypeCache.Get(entityTypeGuid.Value);
                etpEntityType.SetValue(entityType != null ? entityType.Id : ( int? )null);
            }

            UpdateControlsForEntityType();

            tbEntityTypeQualifierColumn.Text = this.GetAttributeValue("EntityTypeQualifierColumn");

            gtpGroupType.SetValue(this.GetAttributeValue("EntityTypeQualifierValue"));
            cbLimitToActiveGroups.Checked = this.GetAttributeValue("LimitToActiveGroups").AsBoolean();
            ddlDefinedTypePicker.SetValue(this.GetAttributeValue("EntityTypeQualifierValue"));
            tbEntityTypeQualifierValue.Text = this.GetAttributeValue("EntityTypeQualifierValue");

            mdSettings.Show();
        }
コード例 #15
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            var rockContext     = new RockContext();
            var definedTypeGuid = dataMap.GetString("DisabledGroupLocationSchedules").AsGuidOrNull();

            if (definedTypeGuid == null)
            {
                return;
            }
            var definedTypeService   = new DefinedTypeService(rockContext);
            var definedValueService  = new DefinedValueService(rockContext);
            var dtDeactivated        = definedTypeService.Get(definedTypeGuid ?? new Guid());
            var dvDeactivated        = dtDeactivated.DefinedValues.ToList();
            var scheduleService      = new ScheduleService(rockContext);
            var groupLocationService = new GroupLocationService(rockContext);
            var deactivatedGroupLocationSchedules = dvDeactivated.Select(dv => dv.Value.Split('|'))
                                                    .Select(s => new
            {
                GroupLocation = groupLocationService.Get(s[0].AsInteger()),
                Schedule      = scheduleService.Get(s[1].AsInteger()),
            }).ToList();

            //add schedules back
            foreach (var groupLocationSchedule in deactivatedGroupLocationSchedules)
            {
                if (!groupLocationSchedule.GroupLocation.Schedules.Contains(groupLocationSchedule.Schedule))
                {
                    groupLocationSchedule.GroupLocation.Schedules.Add(groupLocationSchedule.Schedule);
                }
            }
            //Remove defined values
            foreach (var value in dvDeactivated)
            {
                definedValueService.Delete(value);
                Rock.Web.Cache.DefinedValueCache.Remove(value.Id);
            }

            //clear defined type cache
            Rock.Web.Cache.DefinedTypeCache.Remove(dtDeactivated.Id);

            rockContext.SaveChanges();

            //flush kiosk cache
            Rock.CheckIn.KioskDevice.Clear();

            context.Result = string.Format("Finished at {0}. Reset {1} GroupScheduleLocations.", Rock.RockDateTime.Now, deactivatedGroupLocationSchedules.Count);
        }
コード例 #16
0
        private static DefinedTypeCache LoadById2(int id, RockContext rockContext)
        {
            var definedTypeService = new DefinedTypeService(rockContext);
            var definedTypeModel   = definedTypeService
                                     .Queryable()
                                     .Where(t => t.Id == id)
                                     .FirstOrDefault();

            if (definedTypeModel != null)
            {
                return(new DefinedTypeCache(definedTypeModel));
            }

            return(null);
        }
コード例 #17
0
 /// <summary>
 /// Handles the Click event of the btnCancelType 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 btnCancelType_Click(object sender, EventArgs e)
 {
     if (hfDefinedTypeId.IsZero())
     {
         // Cancelling on Add.  Return to Grid
         NavigateToParentPage();
     }
     else
     {
         // Cancelling on Edit.  Return to Details
         DefinedTypeService definedTypeService = new DefinedTypeService(new RockContext());
         DefinedType        definedType        = definedTypeService.Get(hfDefinedTypeId.ValueAsInt());
         ShowReadonlyDetails(definedType);
     }
 }
コード例 #18
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            var rockContext = new RockContext();

            var definedTypeService   = new DefinedTypeService(rockContext);
            var definedValueService  = new DefinedValueService(rockContext);
            var dtDeactivated        = definedTypeService.Get(Constants.DEFINED_TYPE_DISABLED_GROUPLOCATIONSCHEDULES.AsGuid());
            var dvDeactivated        = dtDeactivated.DefinedValues.ToList();
            var scheduleService      = new ScheduleService(rockContext);
            var groupLocationService = new GroupLocationService(rockContext);
            var deactivatedGroupLocationSchedules = dvDeactivated.Select(dv => dv.Value.Split('|'))
                                                    .Select(s => new
            {
                GroupLocation = groupLocationService.Get(s[0].AsInteger()),
                Schedule      = scheduleService.Get(s[1].AsInteger()),
            }).ToList();

            //add schedules back
            foreach (var groupLocationSchedule in deactivatedGroupLocationSchedules)
            {
                if (!groupLocationSchedule.GroupLocation.Schedules.Contains(groupLocationSchedule.Schedule))
                {
                    groupLocationSchedule.GroupLocation.Schedules.Add(groupLocationSchedule.Schedule);
                }
            }
            //Remove defined values
            foreach (var value in dvDeactivated)
            {
                definedValueService.Delete(value);
                Rock.Web.Cache.DefinedValueCache.Remove(value.Id);
            }

            //clear defined type cache
            Rock.Web.Cache.DefinedTypeCache.Remove(dtDeactivated.Id);

            rockContext.SaveChanges();

            //clear caches
            KioskTypeCache.Clear();
            Rock.CheckIn.KioskDevice.Clear();
            OccurrenceCache.Clear();
            AttendanceCache.Clear();

            context.Result = string.Format("Finished at {0}. Reset {1} GroupScheduleLocations.", Rock.RockDateTime.Now, deactivatedGroupLocationSchedules.Count);
        }
コード例 #19
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 definedType = new DefinedTypeService(new RockContext()).Get(guid.Value);
                if (definedType != null)
                {
                    formattedValue = definedType.Name;
                }
            }

            return(base.FormatValue(parentControl, formattedValue, configurationValues, condensed));
        }
コード例 #20
0
        public static void ClassInitialize(TestContext testContext)
        {
            _rockContext              = new RockContext();
            _accountService           = new FinancialAccountService(_rockContext);
            _batchService             = new FinancialBatchService(_rockContext);
            _transactionService       = new FinancialTransactionService(_rockContext);
            _paymentService           = new FinancialPaymentDetailService(_rockContext);
            _achievementTypeService   = new AchievementTypeService(_rockContext);
            _definedValueService      = new DefinedValueService(_rockContext);
            _definedTypeService       = new DefinedTypeService(_rockContext);
            _transactionDetailService = new FinancialTransactionDetailService(_rockContext);

            DeleteTestData();
            PopulateDefinedValues();
            CreateFinancialTransactionData();
            CreateAchievementTypeData();
        }
コード例 #21
0
        public void CalendarEventsCommand_WithAudienceAsId_RetrievesEventsWithMatchingAudience()
        {
            var rockContext = new RockContext();

            var audienceGuid = SystemGuid.DefinedType.CONTENT_CHANNEL_AUDIENCE_TYPE.AsGuid();

            var definedValueId = new DefinedTypeService(rockContext).Queryable()
                                 .FirstOrDefault(x => x.Guid == audienceGuid)
                                 .DefinedValues.FirstOrDefault(x => x.Value == "All Church").Id;

            var template = GetTestTemplate($"calendarid:'Public' audienceids:'{definedValueId}' startdate:'2018-1-1'");

            TestHelper.AssertTemplateOutput("<Audiences: All Church,",
                                            template,
                                            new LavaTestRenderOptions {
                OutputMatchType = LavaTestOutputMatchTypeSpecifier.Contains
            });
        }
コード例 #22
0
        /// <summary>
        /// Handles the Click event of the btnSaveType 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 btnSaveType_Click(object sender, EventArgs e)
        {
            DefinedType        definedType = null;
            DefinedTypeService typeService = new DefinedTypeService();

            int definedTypeId = hfDefinedTypeId.ValueAsInt();

            if (definedTypeId == 0)
            {
                definedType          = new DefinedType();
                definedType.IsSystem = false;
                definedType.Order    = 0;
                typeService.Add(definedType, CurrentPersonId);
            }
            else
            {
                DefinedTypeCache.Flush(definedTypeId);
                definedType = typeService.Get(definedTypeId);
            }

            definedType.Name        = tbTypeName.Text;
            definedType.Category    = tbTypeCategory.Text;
            definedType.Description = tbTypeDescription.Text;
            definedType.FieldTypeId = int.Parse(ddlTypeFieldType.SelectedValue);

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

            RockTransactionScope.WrapTransaction(() =>
            {
                typeService.Save(definedType, CurrentPersonId);

                // get it back to make sure we have a good Id
                definedType = typeService.Get(definedType.Guid);
            });

            var qryParams = new Dictionary <string, string>();

            qryParams["definedTypeId"] = definedType.Id.ToString();
            NavigateToPage(this.CurrentPage.Guid, qryParams);
        }
コード例 #23
0
        /// <summary>
        /// Handles the Delete event of the gDefinedType 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 gDefinedType_Delete(object sender, RowEventArgs e)
        {
            var definedValueService = new DefinedValueService();
            var definedTypeService  = new DefinedTypeService();

            DefinedType type = definedTypeService.Get(e.RowKeyId);

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

                // if this DefinedType has DefinedValues, see if they can be deleted
                var definedValues = definedValueService.GetByDefinedTypeId(type.Id).ToList();

                foreach (var value in definedValues)
                {
                    if (!definedValueService.CanDelete(value, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }
                }

                RockTransactionScope.WrapTransaction(() =>
                {
                    foreach (var value in definedValues)
                    {
                        definedValueService.Delete(value, CurrentPersonId);
                        definedValueService.Save(value, CurrentPersonId);
                    }

                    definedTypeService.Delete(type, CurrentPersonId);
                    definedTypeService.Save(type, CurrentPersonId);
                });
            }

            gDefinedType_Bind();
        }
コード例 #24
0
        /// <summary>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            ddlCategoryFilter.Items.Clear();
            ddlCategoryFilter.Items.Add(Rock.Constants.All.Text);

            var items = new DefinedTypeService().Queryable()
                        .Where(a => a.Category != string.Empty)
                        .OrderBy(a => a.Category)
                        .Select(a => a.Category)
                        .Distinct()
                        .ToList();

            foreach (var item in items)
            {
                ListItem li = new ListItem(item);
                li.Selected = (!Page.IsPostBack && tFilter.GetUserPreference("Category") == item);
                ddlCategoryFilter.Items.Add(li);
            }
        }
コード例 #25
0
        /// <summary>
        /// Binds the grid for defined types.
        /// </summary>
        private void gDefinedType_Bind()
        {
            var queryable = new DefinedTypeService(new RockContext()).Queryable();

            if (_categoryGuids.Any())
            {
                queryable = queryable.Where(a => a.Category != null && _categoryGuids.Contains(a.Category.Guid));
            }
            else
            {
                int?categoryId = tFilter.GetUserPreference("Category").AsIntegerOrNull();
                if (categoryId.HasValue)
                {
                    queryable = queryable.Where(a => a.CategoryId.HasValue && a.CategoryId.Value == categoryId.Value);
                }
            }

            SortProperty sortProperty = gDefinedType.SortProperty;

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

            gDefinedType.DataSource = queryable
                                      .Select(a =>
                                              new
            {
                a.Id,
                Category = a.Category.Name,
                a.Name,
                a.Description,
                a.IsSystem,
                FieldTypeName = a.FieldType.Name
            })
                                      .ToList();
            gDefinedType.DataBind();
        }
コード例 #26
0
        /// <summary>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            if (ddlCategoryFilter.SelectedItem == null)
            {
                ddlCategoryFilter.Items.Clear();
                ddlCategoryFilter.Items.Add("[All]");

                DefinedTypeService typeService = new DefinedTypeService();
                var items = typeService.Queryable().
                            Where(a => a.Category != "" && a.Category != null).
                            OrderBy(a => a.Category).
                            Select(a => a.Category).
                            Distinct().ToList();

                foreach (var item in items)
                {
                    ddlCategoryFilter.Items.Add(item);
                }
            }
        }
コード例 #27
0
ファイル: LocationTests.cs プロジェクト: SparkDevNetwork/Rock
        private static void RemoveTestData()
        {
            var dataContext = new RockContext();

            // Remove Defined Values for Countries
            var definedTypeService = new DefinedTypeService(dataContext);

            var countryCodeValues = new List <string> {
                CountryCodeWithMandatoryAddressRequirements, CountryCodeWithOptionalAddressRequirements, CountryCodeWithMixedAddressRequirements
            };

            definedTypeService.DeleteValues(SystemGuid.DefinedType.LOCATION_COUNTRIES, countryCodeValues);

            // Remove test locations.
            var locationService = new LocationService(dataContext);

            locationService.DeleteRange(locationService.Queryable().Where(x => countryCodeValues.Contains(x.Country)));

            dataContext.SaveChanges();
        }
コード例 #28
0
        /// <summary>
        /// Handles the Click event of the btnSaveType 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 btnSaveType_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            DefinedType        definedType = null;
            DefinedTypeService typeService = new DefinedTypeService(rockContext);

            int definedTypeId = hfDefinedTypeId.ValueAsInt();

            if (definedTypeId == 0)
            {
                definedType          = new DefinedType();
                definedType.IsSystem = false;
                definedType.Order    = 0;
                typeService.Add(definedType);
            }
            else
            {
                DefinedTypeCache.Flush(definedTypeId);
                definedType = typeService.Get(definedTypeId);
            }

            definedType.FieldTypeId = FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT).Id;
            definedType.Name        = tbTypeName.Text;
            definedType.CategoryId  = cpCategory.SelectedValueAsInt();
            definedType.Description = tbTypeDescription.Text;
            definedType.HelpText    = tbHelpText.Text;

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

            rockContext.SaveChanges();

            var qryParams = new Dictionary <string, string>();

            qryParams["definedTypeId"] = definedType.Id.ToString();
            NavigateToPage(RockPage.Guid, qryParams);
        }
コード例 #29
0
        /// <summary>
        /// Handles the Delete event of the gDefinedType 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 gDefinedType_Delete(object sender, RowEventArgs e)
        {
            var rockContext         = new RockContext();
            var definedValueService = new DefinedValueService(rockContext);
            var definedTypeService  = new DefinedTypeService(rockContext);

            DefinedType type = definedTypeService.Get(e.RowKeyId);

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

                // if this DefinedType has DefinedValues, see if they can be deleted
                var definedValues = definedValueService.GetByDefinedTypeId(type.Id).ToList();

                foreach (var value in definedValues)
                {
                    if (!definedValueService.CanDelete(value, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }
                }

                foreach (var value in definedValues)
                {
                    definedValueService.Delete(value);
                }

                definedTypeService.Delete(type);

                rockContext.SaveChanges();
            }

            gDefinedType_Bind();
        }
コード例 #30
0
        /// <summary>
        /// Handles the Click event of the btnSaveType 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 btnSaveType_Click(object sender, EventArgs e)
        {
            DefinedType        definedType = null;
            DefinedTypeService typeService = new DefinedTypeService();

            int definedTypeId = hfDefinedTypeId.ValueAsInt();

            if (definedTypeId == 0)
            {
                definedType          = new DefinedType();
                definedType.IsSystem = false;
                definedType.Order    = 0;
                typeService.Add(definedType, CurrentPersonId);
            }
            else
            {
                Rock.Web.Cache.DefinedTypeCache.Flush(definedTypeId);
                definedType = typeService.Get(definedTypeId);
            }

            definedType.Name        = tbTypeName.Text;
            definedType.Category    = tbTypeCategory.Text;
            definedType.Description = tbTypeDescription.Text;
            definedType.FieldTypeId = int.Parse(ddlTypeFieldType.SelectedValue);

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

            RockTransactionScope.WrapTransaction(() =>
            {
                typeService.Save(definedType, CurrentPersonId);

                // get it back to make sure we have a good Id
                definedType = typeService.Get(definedType.Guid);
            });

            ShowReadonlyDetails(definedType);
        }
コード例 #31
0
        private void BindFilter()
        {
            if ( ddlCategoryFilter.SelectedItem == null )
            {
                ddlCategoryFilter.Items.Clear();
                ddlCategoryFilter.Items.Add( "[All]" );

                DefinedTypeService typeService = new DefinedTypeService();
                var items = typeService.Queryable().
                    Where( a => a.Category != "" && a.Category != null ).
                    OrderBy( a => a.Category ).
                    Select( a => a.Category ).
                    Distinct().ToList();

                foreach ( var item in items )
                    ddlCategoryFilter.Items.Add( item );
            }
        }