private void SortRows( string eventParam, string[] values ) { var groupTypeIds = new List<int>(); using ( var rockContext = new RockContext() ) { if ( eventParam.Equals( "re-order-area" ) ) { Guid groupTypeGuid = new Guid( values[0] ); int newIndex = int.Parse( values[1] ); var allRows = phRows.ControlsOfTypeRecursive<CheckinAreaRow>(); var sortedRow = allRows.FirstOrDefault( a => a.GroupTypeGuid.Equals( groupTypeGuid ) ); if ( sortedRow != null ) { Control parentControl = sortedRow.Parent; var siblingRows = allRows .Where( a => a.Parent.ClientID == sortedRow.Parent.ClientID ) .ToList(); int oldIndex = siblingRows.IndexOf( sortedRow ); var groupTypeService = new GroupTypeService( rockContext ); var groupTypes = new List<GroupType>(); foreach ( var siblingGuid in siblingRows.Select( a => a.GroupTypeGuid ) ) { var groupType = groupTypeService.Get( siblingGuid ); if ( groupType != null ) { groupTypes.Add( groupType ); groupTypeIds.Add( groupType.Id ); } } groupTypeService.Reorder( groupTypes, oldIndex, newIndex ); } } else if ( eventParam.Equals( "re-order-group" ) ) { Guid groupGuid = new Guid( values[0] ); int newIndex = int.Parse( values[1] ); var allRows = phRows.ControlsOfTypeRecursive<CheckinGroupRow>(); var sortedRow = allRows.FirstOrDefault( a => a.GroupGuid.Equals( groupGuid ) ); if ( sortedRow != null ) { Control parentControl = sortedRow.Parent; var siblingRows = allRows .Where( a => a.Parent.ClientID == sortedRow.Parent.ClientID ) .ToList(); int oldIndex = siblingRows.IndexOf( sortedRow ); var groupService = new GroupService( rockContext ); var groups = new List<Group>(); foreach ( var siblingGuid in siblingRows.Select( a => a.GroupGuid ) ) { var group = groupService.Get( siblingGuid ); if ( group != null ) { groups.Add( group ); } } groupService.Reorder( groups, oldIndex, newIndex ); } } rockContext.SaveChanges(); } foreach( int id in groupTypeIds ) { GroupTypeCache.Flush( id ); } Rock.CheckIn.KioskDevice.FlushAll(); BuildRows(); }