/// <summary> /// Handles the Click event of the btnAddLocation 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 btnAddLocation_Click( object sender, EventArgs e ) { CheckinGroupEditor checkinGroupEditor = phCheckinGroupTypes.ControlsOfTypeRecursive<CheckinGroupEditor>().FirstOrDefault( a => a.GroupGuid == new Guid( hfAddLocationGroupGuid.Value ) ); // Add the location (ignore if they didn't pick one, or they picked one that already is selected) var location = new LocationService( new RockContext() ).Get( locationPicker.SelectedValue.AsInteger() ); if ( location != null ) { if ( !checkinGroupEditor.Locations.Any( a => a.LocationId == location.Id ) ) { CheckinGroupEditor.LocationGridItem gridItem = new CheckinGroupEditor.LocationGridItem(); gridItem.LocationId = location.Id; gridItem.Name = location.Name; gridItem.FullNamePath = location.Name; gridItem.ParentLocationId = location.ParentLocationId; var parentLocation = location.ParentLocation; while ( parentLocation != null ) { gridItem.FullNamePath = parentLocation.Name + " > " + gridItem.FullNamePath; parentLocation = parentLocation.ParentLocation; } checkinGroupEditor.Locations.Add( gridItem ); } } checkinGroupEditor.Expanded = true; ( checkinGroupEditor.Parent as CheckinGroupTypeEditor ).Expanded = true; mdLocationPicker.Hide(); }
/// <summary> /// Creates the group editor controls. /// </summary> /// <param name="group">The group.</param> /// <param name="parentControl">The parent control.</param> /// <param name="rockContext">The rock context.</param> /// <param name="createExpanded">if set to <c>true</c> [create expanded].</param> private void CreateGroupEditorControls( Group group, Control parentControl, RockContext rockContext, bool createExpanded = false ) { CheckinGroupEditor groupEditor = new CheckinGroupEditor(); groupEditor.ID = "GroupEditor_" + group.Guid.ToString( "N" ); if ( createExpanded ) { groupEditor.Expanded = true; } parentControl.Controls.Add( groupEditor ); groupEditor.SetGroup( group, rockContext ); var locationService = new LocationService( rockContext ); var locationQry = locationService.Queryable().Select( a => new { a.Id, a.ParentLocationId, a.Name } ); groupEditor.Locations = new List<CheckinGroupEditor.LocationGridItem>(); foreach ( var location in group.GroupLocations.Select( a => a.Location ).OrderBy( o => o.Name ) ) { var gridItem = new CheckinGroupEditor.LocationGridItem(); gridItem.LocationId = location.Id; gridItem.Name = location.Name; gridItem.FullNamePath = location.Name; gridItem.ParentLocationId = location.ParentLocationId; var parentLocationId = location.ParentLocationId; while ( parentLocationId != null ) { var parentLocation = locationQry.FirstOrDefault( a => a.Id == parentLocationId ); gridItem.FullNamePath = parentLocation.Name + " > " + gridItem.FullNamePath; parentLocationId = parentLocation.ParentLocationId; } groupEditor.Locations.Add( gridItem ); } groupEditor.AddLocationClick += groupEditor_AddLocationClick; groupEditor.DeleteLocationClick += groupEditor_DeleteLocationClick; groupEditor.DeleteGroupClick += groupEditor_DeleteGroupClick; }
/// <summary> /// Handles the Click event of the btnAddLocation 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 btnAddLocation_Click( object sender, EventArgs e ) { CheckinGroupEditor checkinGroupEditor = phCheckinGroupTypes.ControlsOfTypeRecursive<CheckinGroupEditor>().FirstOrDefault( a => a.GroupGuid == new Guid( hfAddLocationGroupGuid.Value ) ); // Add the location (ignore if they didn't pick one, or they picked one that already is selected) if ( locationPicker.Location != null ) { if ( !checkinGroupEditor.Locations.Any( a => a.LocationId == locationPicker.Location.Id ) ) { CheckinGroupEditor.LocationGridItem gridItem = new CheckinGroupEditor.LocationGridItem(); gridItem.LocationId = locationPicker.Location.Id; gridItem.Name = locationPicker.Location.Name; checkinGroupEditor.Locations.Add( gridItem ); } } checkinGroupEditor.ForceContentVisible = true; ( checkinGroupEditor.Parent as CheckinGroupTypeEditor ).ForceContentVisible = true; mdLocationPicker.Hide(); }