1818 using Microsoft . FeatureManagement . Mvc ;
1919 using Microsoft . Extensions . Configuration ;
2020 using DigitalLearningSolutions . Data . Extensions ;
21+ using Microsoft . AspNetCore . Hosting ;
2122
2223 [ FeatureGate ( FeatureFlags . RefactoredTrackingSystem ) ]
2324 [ Authorize ( Policy = CustomPolicies . UserCentreAdmin ) ]
2627 [ Route ( "TrackingSystem/Delegates/All" ) ]
2728 public class AllDelegatesController : Controller
2829 {
29- private const string DelegateFilterCookieName = "DelegateFilter" ;
30+ private string DelegateFilterCookieName = "DelegateFilter" ;
3031 private readonly IDelegateDownloadFileService delegateDownloadFileService ;
3132 private readonly IJobGroupsDataService jobGroupsDataService ;
3233 private readonly PromptsService promptsService ;
3334 private readonly IPaginateService paginateService ;
3435 private readonly IUserDataService userDataService ;
3536 private readonly IGroupsService groupsService ;
3637 private readonly IConfiguration configuration ;
38+ private readonly IWebHostEnvironment env ;
3739
3840 public AllDelegatesController (
3941 IDelegateDownloadFileService delegateDownloadFileService ,
@@ -42,7 +44,8 @@ public AllDelegatesController(
4244 IJobGroupsDataService jobGroupsDataService ,
4345 IPaginateService paginateService ,
4446 IGroupsService groupsService ,
45- IConfiguration configuration
47+ IConfiguration configuration ,
48+ IWebHostEnvironment env
4649 )
4750 {
4851 this . delegateDownloadFileService = delegateDownloadFileService ;
@@ -52,6 +55,7 @@ IConfiguration configuration
5255 this . paginateService = paginateService ;
5356 this . groupsService = groupsService ;
5457 this . configuration = configuration ;
58+ this . env = env ;
5559 }
5660
5761 [ NoCaching ]
@@ -76,6 +80,8 @@ public IActionResult Index(
7680
7781 sortBy ??= DefaultSortByOptions . Name . PropertyName ;
7882 sortDirection ??= GenericSortingHelper . Ascending ;
83+
84+ DelegateFilterCookieName += env . EnvironmentName ;
7985 existingFilterString = FilteringHelper . GetFilterString (
8086 existingFilterString ,
8187 newFilterToAdd ,
@@ -95,10 +101,8 @@ public IActionResult Index(
95101 var promptsWithOptions = customPrompts . Where ( customPrompt => customPrompt . Options . Count > 0 ) ;
96102 var availableFilters = AllDelegatesViewModelFilterOptions . GetAllDelegatesFilterViewModels ( jobGroups , promptsWithOptions , groups ) ;
97103
98- var CurrentSiteBaseUrl = configuration . GetCurrentSystemBaseUrl ( ) ;
99-
100- if ( ( ( TempData [ "allDelegatesCentreId" ] != null && TempData [ "allDelegatesCentreId" ] . ToString ( ) != User . GetCentreId ( ) . ToString ( ) )
101- || ( TempData [ "LastBaseUrl" ] != null && ( TempData [ "LastBaseUrl" ] . ToString ( ) != CurrentSiteBaseUrl ) ) ) && existingFilterString != null )
104+ if ( existingFilterString != null && TempData [ "allDelegatesCentreId" ] != null &&
105+ TempData [ "allDelegatesCentreId" ] . ToString ( ) != User . GetCentreId ( ) . ToString ( ) )
102106 {
103107 if ( existingFilterString . Contains ( "Answer" ) )
104108 existingFilterString = FilterHelper . RemoveNonExistingPromptFilters ( availableFilters , existingFilterString ) ;
@@ -169,8 +173,8 @@ public IActionResult Index(
169173 {
170174 groupId = null ;
171175 existingFilterString = FilterHelper . RemoveNonExistingFilterOptions ( availableFilters , existingFilterString ) ;
172- }
173- }
176+ }
177+ }
174178
175179 if ( filter . Contains ( "Answer1" ) )
176180 answer1 = filterValue ;
@@ -217,14 +221,13 @@ public IActionResult Index(
217221
218222 result . Page = page ;
219223 TempData [ "Page" ] = result . Page ;
220- TempData [ "LastBaseUrl" ] = configuration . GetCurrentSystemBaseUrl ( ) ;
221224
222225 var model = new AllDelegatesViewModel (
223226 result ,
224227 customPrompts ,
225228 availableFilters
226229 ) ;
227-
230+
228231 model . TotalPages = ( int ) ( resultCount / itemsPerPage ) + ( ( resultCount % itemsPerPage ) > 0 ? 1 : 0 ) ;
229232 model . MatchingSearchResults = resultCount ;
230233
0 commit comments