/// <summary> /// Handles the Delete event of the gGroupTypeAttributes control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> /// <exception cref="System.NotImplementedException"></exception> protected void gGroupTypeAttributes_Delete(object sender, RowEventArgs e) { Guid attributeGuid = (Guid)e.RowKeyValue; GroupTypeAttributesState.RemoveEntity(attributeGuid); BindGroupTypeAttributesGrid(); }
/// <summary> /// Handles the Click event of the btnSaveGroupTypeAttribute 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 btnSaveGroupTypeAttribute_Click(object sender, EventArgs e) { Rock.Model.Attribute attribute = new Rock.Model.Attribute(); edtGroupTypeAttributes.GetAttributeProperties(attribute); // Controls will show warnings if (!attribute.IsValid) { return; } GroupTypeAttributesState.RemoveEntity(attribute.Guid); GroupTypeAttributesState.Add(attribute); pnlDetails.Visible = true; pnlGroupTypeAttribute.Visible = false; BindGroupTypeAttributesGrid(); }
/// <summary> /// Gs the group type attributes_ show edit. /// </summary> /// <param name="attributeGuid">The attribute GUID.</param> protected void gGroupTypeAttributes_ShowEdit(Guid attributeGuid) { pnlDetails.Visible = false; pnlGroupTypeAttribute.Visible = true; edtGroupTypeAttributes.AttributeEntityTypeId = Rock.Web.Cache.EntityTypeCache.Read(typeof(GroupType)).Id; Attribute attribute; if (attributeGuid.Equals(Guid.Empty)) { attribute = new Attribute(); edtGroupTypeAttributes.ActionTitle = ActionTitle.Add("attribute for group type " + tbName.Text); } else { attribute = GroupTypeAttributesState.First(a => a.Guid.Equals(attributeGuid)); edtGroupTypeAttributes.ActionTitle = ActionTitle.Edit("attribute for group type " + tbName.Text); } edtGroupTypeAttributes.SetAttributeProperties(attribute, typeof(GroupType)); }
/// <summary> /// Binds the group type attributes grid. /// </summary> private void BindGroupTypeAttributesGrid() { gGroupTypeAttributes.DataSource = GroupTypeAttributesState.ToList(); gGroupTypeAttributes.DataBind(); }
/// <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) { using (new UnitOfWorkScope()) { GroupType groupType; GroupTypeService groupTypeService = new GroupTypeService(); AttributeService attributeService = new AttributeService(); int groupTypeId = int.Parse(hfGroupTypeId.Value); if (groupTypeId == 0) { groupType = new GroupType(); groupTypeService.Add(groupType, CurrentPersonId); } else { groupType = groupTypeService.Get(groupTypeId); } groupType.Name = tbName.Text; groupType.Description = tbDescription.Text; groupType.GroupTerm = tbGroupTerm.Text; groupType.GroupMemberTerm = tbGroupMemberTerm.Text; groupType.DefaultGroupRoleId = ddlDefaultGroupRole.SelectedValueAsInt(); groupType.ShowInGroupList = cbShowInGroupList.Checked; groupType.ShowInNavigation = cbShowInNavigation.Checked; groupType.IconCssClass = tbIconCssClass.Text; groupType.IconSmallFileId = imgIconSmall.BinaryFileId; groupType.IconLargeFileId = imgIconLarge.BinaryFileId; groupType.TakesAttendance = cbTakesAttendance.Checked; groupType.AttendanceRule = ddlAttendanceRule.SelectedValueAsEnum <AttendanceRule>(); groupType.AttendancePrintTo = ddlAttendancePrintTo.SelectedValueAsEnum <PrintTo>(); groupType.LocationSelectionMode = ddlLocationSelectionMode.SelectedValueAsEnum <LocationPickerMode>(); groupType.GroupTypePurposeValueId = ddlGroupTypePurpose.SelectedValueAsInt(); groupType.AllowMultipleLocations = cbAllowMultipleLocations.Checked; groupType.InheritedGroupTypeId = gtpInheritedGroupType.SelectedGroupTypeId; groupType.ChildGroupTypes = new List <GroupType>(); groupType.ChildGroupTypes.Clear(); foreach (var item in ChildGroupTypesDictionary) { var childGroupType = groupTypeService.Get(item.Key); if (childGroupType != null) { groupType.ChildGroupTypes.Add(childGroupType); } } DefinedValueService definedValueService = new DefinedValueService(); groupType.LocationTypes = new List <GroupTypeLocationType>(); groupType.LocationTypes.Clear(); foreach (var item in LocationTypesDictionary) { var locationType = definedValueService.Get(item.Key); if (locationType != null) { groupType.LocationTypes.Add(new GroupTypeLocationType { LocationTypeValueId = locationType.Id }); } } if (!groupType.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { groupTypeService.Save(groupType, CurrentPersonId); // get it back to make sure we have a good Id for it for the Attributes groupType = groupTypeService.Get(groupType.Guid); /* Take care of Group Type Attributes */ // delete GroupTypeAttributes that are no longer configured in the UI var groupTypeAttributesQry = attributeService.Get(new GroupType().TypeId, "Id", groupType.Id.ToString()); var selectedAttributes = GroupTypeAttributesState.Select(a => a.Guid); foreach (var attr in groupTypeAttributesQry.Where(a => !selectedAttributes.Contains(a.Guid))) { Rock.Web.Cache.AttributeCache.Flush(attr.Id); attributeService.Delete(attr, CurrentPersonId); attributeService.Save(attr, CurrentPersonId); } string qualifierValue = groupType.Id.ToString(); // add/update the GroupTypeAttributes that are assigned in the UI foreach (var attributeState in GroupTypeAttributesState .Where(a => a.EntityTypeQualifierValue == null || a.EntityTypeQualifierValue.Trim() == string.Empty || a.EntityTypeQualifierValue.Equals(qualifierValue))) { // remove old qualifiers in case they changed var qualifierService = new AttributeQualifierService(); foreach (var oldQualifier in qualifierService.GetByAttributeId(attributeState.Id).ToList()) { qualifierService.Delete(oldQualifier, CurrentPersonId); qualifierService.Save(oldQualifier, CurrentPersonId); } Attribute attribute = groupTypeAttributesQry.FirstOrDefault(a => a.Guid.Equals(attributeState.Guid)); if (attribute == null) { attribute = attributeState.Clone() as Rock.Model.Attribute; attributeService.Add(attribute, CurrentPersonId); } else { attributeState.Id = attribute.Id; attribute.FromDictionary(attributeState.ToDictionary()); foreach (var qualifier in attributeState.AttributeQualifiers) { attribute.AttributeQualifiers.Add(qualifier.Clone() as AttributeQualifier); } } attribute.EntityTypeQualifierColumn = "Id"; attribute.EntityTypeQualifierValue = qualifierValue; attribute.EntityTypeId = Rock.Web.Cache.EntityTypeCache.Read(typeof(GroupType)).Id; Rock.Web.Cache.AttributeCache.Flush(attribute.Id); attributeService.Save(attribute, CurrentPersonId); } /* Take care of Group Attributes */ // delete GroupAttributes that are no longer configured in the UI var groupAttributesQry = attributeService.Get(new Group().TypeId, "GroupTypeId", groupType.Id.ToString()); selectedAttributes = GroupAttributesState.Select(a => a.Guid); foreach (var attr in groupAttributesQry.Where(a => !selectedAttributes.Contains(a.Guid))) { Rock.Web.Cache.AttributeCache.Flush(attr.Id); attributeService.Delete(attr, CurrentPersonId); attributeService.Save(attr, CurrentPersonId); } // add/update the GroupAttributes that are assigned in the UI foreach (var attributeState in GroupAttributesState .Where(a => a.EntityTypeQualifierValue == null || a.EntityTypeQualifierValue.Trim() == string.Empty || a.EntityTypeQualifierValue.Equals(qualifierValue))) { // remove old qualifiers in case they changed var qualifierService = new AttributeQualifierService(); foreach (var oldQualifier in qualifierService.GetByAttributeId(attributeState.Id).ToList()) { qualifierService.Delete(oldQualifier, CurrentPersonId); qualifierService.Save(oldQualifier, CurrentPersonId); } Attribute attribute = groupAttributesQry.FirstOrDefault(a => a.Guid.Equals(attributeState.Guid)); if (attribute == null) { attribute = attributeState.Clone() as Rock.Model.Attribute; attributeService.Add(attribute, CurrentPersonId); } else { attributeState.Id = attribute.Id; attribute.FromDictionary(attributeState.ToDictionary()); foreach (var qualifier in attributeState.AttributeQualifiers) { attribute.AttributeQualifiers.Add(qualifier.Clone() as AttributeQualifier); } } attribute.EntityTypeQualifierColumn = "GroupTypeId"; attribute.EntityTypeQualifierValue = qualifierValue; attribute.EntityTypeId = Rock.Web.Cache.EntityTypeCache.Read(typeof(Group)).Id; Rock.Web.Cache.AttributeCache.Flush(attribute.Id); attributeService.Save(attribute, CurrentPersonId); } }); } NavigateToParentPage(); }
private void RebuildAttributeLists(int?inheritedGroupTypeId, GroupTypeService groupTypeService, AttributeService attributeService, bool clearList) { string qualifierValue = PageParameter("GroupTypeId"); if (clearList) { var attributes = new List <Attribute>(); foreach (var attribute in GroupTypeAttributesState) { if (string.IsNullOrWhiteSpace(attribute.EntityTypeQualifierValue) || attribute.EntityTypeQualifierValue == qualifierValue) { attributes.Add(attribute); } } GroupTypeAttributesState.Clear(); GroupTypeAttributesState.AddAll(attributes); attributes = new List <Attribute>(); foreach (var attribute in GroupAttributesState) { if (string.IsNullOrWhiteSpace(attribute.EntityTypeQualifierValue) || attribute.EntityTypeQualifierValue == qualifierValue) { attributes.Add(attribute); } } GroupAttributesState.Clear(); GroupAttributesState.AddAll(attributes); } while (inheritedGroupTypeId.HasValue) { var inheritedGroupType = groupTypeService.Get(inheritedGroupTypeId.Value); if (inheritedGroupType != null) { qualifierValue = inheritedGroupType.Id.ToString(); var qryGroupTypeAttributes = attributeService.GetByEntityTypeId(new GroupType().TypeId).AsQueryable() .Where(a => a.EntityTypeQualifierColumn.Equals("Id", StringComparison.OrdinalIgnoreCase) && a.EntityTypeQualifierValue.Equals(qualifierValue)); var qryGroupAttributes = attributeService.GetByEntityTypeId(new Group().TypeId).AsQueryable() .Where(a => a.EntityTypeQualifierColumn.Equals("GroupTypeId", StringComparison.OrdinalIgnoreCase) && a.EntityTypeQualifierValue.Equals(qualifierValue)); // TODO: Should probably add GroupTypeCache object so that it can be used during the // databind of the attribute grids, instead of having to do this hack of putting // the inherited group type name into the description property of the attribute // (which is currently how the databound method gets the inherited attributes group type) qryGroupTypeAttributes .ToList() .ForEach(a => a.Description = inheritedGroupType.Name); qryGroupAttributes .ToList() .ForEach(a => a.Description = inheritedGroupType.Name); GroupTypeAttributesState.InsertAll(qryGroupTypeAttributes .OrderBy(a => a.Order) .ThenBy(a => a.Name) .ToList()); GroupAttributesState.InsertAll(qryGroupAttributes .OrderBy(a => a.Order) .ThenBy(a => a.Name) .ToList()); inheritedGroupTypeId = inheritedGroupType.InheritedGroupTypeId; } else { inheritedGroupTypeId = null; } } }