@@ -141,7 +141,7 @@ public async Task<IActionResult> Index(string returnUrl = null, bool? checkDetai
141141 /// <param name="checkDetails">Whether to check account details.</param>
142142 /// <returns>IActionResult.</returns>
143143 [ HttpGet ]
144- [ Route ( "myaccount-employement " ) ]
144+ [ Route ( "myaccount-employment " ) ]
145145 public async Task < IActionResult > MyEmploymentDetails ( bool ? checkDetails = false )
146146 {
147147 string loginWizardCacheKey = $ "{ this . CurrentUserId } :LoginWizard";
@@ -1003,25 +1003,36 @@ public async Task<IActionResult> ChangeCurrentRole([FromQuery] UserJobRoleUpdate
10031003 return this . View ( "ChangeCurrentRole" , viewModel ) ;
10041004 }
10051005
1006- if ( ! string . IsNullOrWhiteSpace ( viewModel . FilterText ) )
1007- {
1008- var jobRoles = await this . jobRoleService . GetPagedFilteredAsync ( viewModel . FilterText , viewModel . CurrentPage , viewModel . PageSize ) ;
1009- viewModel . RoleList = jobRoles . Item2 ;
1010- viewModel . TotalItems = jobRoles . Item1 ;
1011- viewModel . HasItems = jobRoles . Item1 > 0 ;
1012- }
1013-
10141006 if ( formSubmission )
10151007 {
1016- if ( viewModel . SelectedJobRoleId . HasValue )
1008+ var hasSelectedJobRoleId = int . TryParse ( viewModel . SelectedJobRoleId , out int currentRole ) ;
1009+ if ( hasSelectedJobRoleId && currentRole > 0 )
10171010 {
1018- var newRoleId = viewModel . SelectedJobRoleId . Value ;
1011+ var newRoleId = currentRole ;
10191012 var jobRole = await this . jobRoleService . GetByIdAsync ( newRoleId ) ;
10201013
10211014 if ( jobRole . MedicalCouncilId > 0 && jobRole . MedicalCouncilId < 4 )
10221015 {
10231016 return this . RedirectToAction ( nameof ( this . ChangeMedicalCouncilNo ) , new UserMedicalCouncilNoUpdateViewModel { SelectedJobRoleId = newRoleId } ) ;
10241017 }
1018+ else if ( this . User . IsInRole ( "BasicUser" ) )
1019+ {
1020+ await this . userService . UpdateUserEmployment (
1021+ new elfhHub . Nhs . Models . Entities . UserEmployment
1022+ {
1023+ Id = profile . EmploymentId ,
1024+ UserId = profile . Id ,
1025+ JobRoleId = newRoleId ,
1026+ GradeId = profile . GradeId ,
1027+ SpecialtyId = profile . SpecialtyId ,
1028+ StartDate = profile . JobStartDate ,
1029+ LocationId = profile . LocationId ,
1030+ } ) ;
1031+
1032+ this . ViewBag . SuccessMessage = CommonValidationErrorMessages . EmploymentDetailsUpdated ;
1033+ this . ViewBag . MyAction = "MyEmploymentDetails" ;
1034+ return this . View ( "SuccessMessageMyAccount" ) ;
1035+ }
10251036 else
10261037 {
10271038 return this . RedirectToAction ( nameof ( this . ChangeGrade ) , new UserGradeUpdateViewModel { SelectedJobRoleId = newRoleId } ) ;
@@ -1030,9 +1041,24 @@ public async Task<IActionResult> ChangeCurrentRole([FromQuery] UserJobRoleUpdate
10301041 else
10311042 {
10321043 this . ModelState . AddModelError ( nameof ( viewModel . SelectedJobRoleId ) , CommonValidationErrorMessages . RoleRequired ) ;
1033- return this . View ( "ChangeCurrentRole" , viewModel ) ;
10341044 }
10351045 }
1046+ else
1047+ {
1048+ if ( string . IsNullOrEmpty ( viewModel . FilterText ) )
1049+ {
1050+ viewModel . FilterText = profile . JobRole ;
1051+ viewModel . SelectedJobRoleId = profile . JobRoleId . HasValue ? profile . JobRoleId . ToString ( ) : string . Empty ;
1052+ }
1053+ }
1054+
1055+ if ( ! string . IsNullOrWhiteSpace ( viewModel . FilterText ) )
1056+ {
1057+ var jobRoles = await this . jobRoleService . GetPagedFilteredAsync ( viewModel . FilterText , viewModel . CurrentPage , viewModel . PageSize ) ;
1058+ viewModel . RoleList = jobRoles . Item2 ;
1059+ viewModel . TotalItems = jobRoles . Item1 ;
1060+ viewModel . HasItems = jobRoles . Item1 > 0 ;
1061+ }
10361062
10371063 return this . View ( "ChangeCurrentRole" , viewModel ) ;
10381064 }
@@ -1075,24 +1101,25 @@ public async Task<IActionResult> ChangeMedicalCouncilNo([FromQuery] UserMedicalC
10751101 this . ModelState . AddModelError ( nameof ( viewModel . SelectedMedicalCouncilNo ) , validateMedicalCouncilNumber ) ;
10761102 return this . View ( "ChangeMedicalCouncilNumber" , viewModel ) ;
10771103 }
1078- else if ( direct )
1104+ else if ( this . User . IsInRole ( "BasicUser" ) || direct )
10791105 {
10801106 await this . userService . UpdateUserEmployment (
1081- new elfhHub . Nhs . Models . Entities . UserEmployment
1082- {
1083- Id = profile . EmploymentId ,
1084- UserId = profile . Id ,
1085- JobRoleId = profile . JobRoleId ,
1086- MedicalCouncilId = viewModel . SelectedMedicalCouncilId ,
1087- MedicalCouncilNo = viewModel . SelectedMedicalCouncilNo ,
1088- GradeId = profile . GradeId ,
1089- SpecialtyId = profile . SpecialtyId ,
1090- StartDate = profile . JobStartDate ,
1091- LocationId = profile . LocationId ,
1092- } ) ;
1093-
1094- this . ViewBag . SuccessMessage = "Your medical council number has been changed" ;
1095- return this . View ( "SuccessMessage" ) ;
1107+ new elfhHub . Nhs . Models . Entities . UserEmployment
1108+ {
1109+ Id = profile . EmploymentId ,
1110+ UserId = profile . Id ,
1111+ JobRoleId = viewModel . SelectedJobRoleId ,
1112+ MedicalCouncilId = viewModel . SelectedMedicalCouncilId ,
1113+ MedicalCouncilNo = viewModel . SelectedMedicalCouncilNo ,
1114+ GradeId = profile . GradeId ,
1115+ SpecialtyId = profile . SpecialtyId ,
1116+ StartDate = profile . JobStartDate ,
1117+ LocationId = profile . LocationId ,
1118+ } ) ;
1119+
1120+ this . ViewBag . SuccessMessage = CommonValidationErrorMessages . EmploymentDetailsUpdated ;
1121+ this . ViewBag . MyAction = "MyEmploymentDetails" ;
1122+ return this . View ( "SuccessMessageMyAccount" ) ;
10961123 }
10971124 else
10981125 {
@@ -1111,6 +1138,13 @@ await this.userService.UpdateUserEmployment(
11111138 return this . View ( "ChangeMedicalCouncilNumber" , viewModel ) ;
11121139 }
11131140 }
1141+ else
1142+ {
1143+ if ( string . IsNullOrEmpty ( viewModel . SelectedMedicalCouncilNo ) )
1144+ {
1145+ viewModel . SelectedMedicalCouncilNo = profile . MedicalCouncilNo ;
1146+ }
1147+ }
11141148
11151149 return this . View ( "ChangeMedicalCouncilNumber" , viewModel ) ;
11161150 }
@@ -1198,8 +1232,10 @@ public async Task<IActionResult> ChangePrimarySpecialty([FromQuery] UserPrimaryS
11981232
11991233 if ( formSubmission )
12001234 {
1201- if ( viewModel . SelectedPrimarySpecialtyId . HasValue )
1235+ var hasSelectedPrimarySpeciality = int . TryParse ( viewModel . SelectedPrimarySpecialtyId , out int selectedPrimarySpecialtyId ) ;
1236+ if ( hasSelectedPrimarySpeciality && selectedPrimarySpecialtyId > 0 )
12021237 {
1238+ var newPrimarySpecialtyId = selectedPrimarySpecialtyId ;
12031239 await this . userService . UpdateUserEmployment (
12041240 new elfhHub . Nhs . Models . Entities . UserEmployment
12051241 {
@@ -1209,7 +1245,7 @@ await this.userService.UpdateUserEmployment(
12091245 MedicalCouncilId = profile . MedicalCouncilId ,
12101246 MedicalCouncilNo = profile . MedicalCouncilNo ,
12111247 GradeId = profile . GradeId ,
1212- SpecialtyId = viewModel . SelectedPrimarySpecialtyId . Value ,
1248+ SpecialtyId = newPrimarySpecialtyId ,
12131249 StartDate = profile . JobStartDate ,
12141250 LocationId = profile . LocationId ,
12151251 } ) ;
@@ -1218,8 +1254,15 @@ await this.userService.UpdateUserEmployment(
12181254 }
12191255 else
12201256 {
1221- this . ModelState . AddModelError ( nameof ( viewModel . SelectedPrimarySpecialtyId ) , CommonValidationErrorMessages . SpecialtyNotApplicable ) ;
1222- return this . View ( "ChangePrimarySpecialty" , viewModel ) ;
1257+ this . ModelState . AddModelError ( nameof ( viewModel . SelectedPrimarySpecialtyId ) , CommonValidationErrorMessages . SpecialtyRequired ) ;
1258+ }
1259+ }
1260+ else
1261+ {
1262+ if ( string . IsNullOrWhiteSpace ( viewModel . FilterText ) )
1263+ {
1264+ viewModel . FilterText = profile . PrimarySpecialty ;
1265+ viewModel . SelectedPrimarySpecialtyId = profile . SpecialtyId . HasValue ? profile . SpecialtyId . ToString ( ) : string . Empty ;
12231266 }
12241267 }
12251268
@@ -1274,6 +1317,10 @@ await this.userService.UpdateUserEmployment(
12741317 this . ModelState . Remove ( "Day" ) ;
12751318 this . ModelState . Remove ( "Month" ) ;
12761319 this . ModelState . Remove ( "Year" ) ;
1320+
1321+ viewModel . Day = profile . JobStartDate . HasValue ? profile . JobStartDate . Value . Day : null ;
1322+ viewModel . Month = profile . JobStartDate . HasValue ? profile . JobStartDate . GetValueOrDefault ( ) . Month : null ;
1323+ viewModel . Year = profile . JobStartDate . HasValue ? profile . JobStartDate . Value . Year : null ;
12771324 }
12781325
12791326 return this . View ( "ChangeStartDate" , viewModel ) ;
0 commit comments