@@ -42,12 +42,12 @@ public class PathfinderService : IPathfinderService
4242 return query ;
4343 }
4444
45- private IQueryable < Pathfinder > QueryPathfinderByIdAsync ( Guid pathfinderId , string clubCode )
45+ private IQueryable < Pathfinder > QueryPathfinderByIdAsync ( Guid pathfinderId )
4646 {
4747 return _dbContext . Pathfinders
4848 . Include ( pc => pc . PathfinderClass )
49- . Include ( c => c . Club )
50- . Where ( c => c . Club . ClubCode == clubCode && c . PathfinderID == pathfinderId ) ;
49+ . Include ( c => c . Club )
50+ . Where ( p => p . PathfinderID == pathfinderId ) ;
5151 }
5252
5353 public PathfinderService (
@@ -144,18 +144,19 @@ await _validator.ValidateAsync(
144144 {
145145 _logger . LogInformation ( "Updating pathfinder with ID {PathfinderId} for club {ClubCode}" , pathfinderId , clubCode ) ;
146146
147- Pathfinder targetPathfinder = await QueryPathfinderByIdAsync ( pathfinderId , clubCode )
147+ Pathfinder targetPathfinder = await QueryPathfinderByIdAsync ( pathfinderId )
148148 . SingleOrDefaultAsync ( token ) ;
149149
150- var club = await _clubService . GetByCodeAsync ( clubCode , token ) ;
151- if ( club == null )
150+ if ( targetPathfinder == default )
152151 {
153- _logger . LogWarning ( "Club with code {ClubCode} not found while updating pathfinder {PathfinderId}" , clubCode , pathfinderId ) ;
152+ _logger . LogWarning ( "Pathfinder with ID {PathfinderId} not found" , pathfinderId ) ;
153+ return default ;
154154 }
155155
156- if ( targetPathfinder == default )
156+ var currentClub = await _clubService . GetByCodeAsync ( clubCode , token ) ;
157+ if ( currentClub == null )
157158 {
158- _logger . LogWarning ( "Pathfinder with ID {PathfinderId } not found for club {ClubCode }" , pathfinderId , clubCode ) ;
159+ _logger . LogWarning ( "Current club with code {ClubCode } not found while updating pathfinder {PathfinderId }" , clubCode , pathfinderId ) ;
159160 return default ;
160161 }
161162
@@ -168,12 +169,13 @@ await _validator.ValidateAsync(
168169 Email = targetPathfinder . Email ,
169170 Grade = updatedPathfinder . Grade ,
170171 IsActive = updatedPathfinder . IsActive ,
171- ClubID = club . ClubID
172+ ClubID = updatedPathfinder . ClubID ?? targetPathfinder . ClubID
172173 } ;
173174
174175 await _validator . ValidateAsync (
175176 mappedPathfinder ,
176- opts => opts . ThrowOnFailures ( ) ,
177+ opts => opts . ThrowOnFailures ( )
178+ . IncludeRuleSets ( "update" ) ,
177179 token ) ;
178180
179181 if ( mappedPathfinder . Grade != null )
@@ -190,6 +192,11 @@ await _validator.ValidateAsync(
190192 targetPathfinder . IsActive = mappedPathfinder . IsActive ;
191193 }
192194
195+ if ( updatedPathfinder . ClubID . HasValue )
196+ {
197+ targetPathfinder . ClubID = updatedPathfinder . ClubID . Value ;
198+ }
199+
193200 await _dbContext . SaveChangesAsync ( token ) ;
194201 _logger . LogInformation ( "Updated pathfinder with ID {PathfinderId} for club {ClubCode}" , pathfinderId , clubCode ) ;
195202
@@ -217,7 +224,7 @@ await _validator.ValidateAsync(
217224 {
218225 try
219226 {
220- var targetPathfinder = await QueryPathfinderByIdAsync ( item . PathfinderId , clubCode )
227+ var targetPathfinder = await QueryPathfinderByIdAsync ( item . PathfinderId )
221228 . SingleOrDefaultAsync ( token ) ;
222229
223230 if ( targetPathfinder != null )
0 commit comments