Skip to content

Commit 2960493

Browse files
committed
TD-6133: Fixed issues on Employment tab - My account
1 parent c8d3bd2 commit 2960493

File tree

9 files changed

+108
-50
lines changed

9 files changed

+108
-50
lines changed

LearningHub.Nhs.WebUI/Controllers/LoginWizardController.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,22 @@ public async Task<IActionResult> UpdateSecurityQuestionPost(MyAcountSecurityQues
611611

612612
if (model != null)
613613
{
614+
if ((model.SelectedFirstQuestionId == 0) || (model.SelectedSecondQuestionId == 0))
615+
{
616+
if (model.SelectedFirstQuestionId == 0)
617+
{
618+
this.ModelState.AddModelError(nameof(model.SelectedFirstQuestionId), CommonValidationErrorMessages.SecurityQuestionRequired);
619+
}
620+
621+
if (model.SelectedSecondQuestionId == 0)
622+
{
623+
this.ModelState.AddModelError(nameof(model.SelectedSecondQuestionId), CommonValidationErrorMessages.SecurityQuestionRequired);
624+
}
625+
626+
this.ViewBag.ReturnUrl = returnUrl;
627+
return this.View("SecurityQuestionsDetails", securityViewModel);
628+
}
629+
614630
if (model.SelectedFirstQuestionId == model.SelectedSecondQuestionId)
615631
{
616632
this.ModelState.AddModelError("DuplicateQuestion", CommonValidationErrorMessages.DuplicateQuestion);

LearningHub.Nhs.WebUI/Controllers/MyAccountController.cs

Lines changed: 79 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

LearningHub.Nhs.WebUI/Helpers/CommonValidationErrorMessages.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,5 +254,10 @@ public static class CommonValidationErrorMessages
254254
/// location Success Message.
255255
/// </summary>
256256
public const string PersonalDetailsSuccessMessage = "Your personal details has been changed";
257+
258+
/// <summary>
259+
/// Security question Required.
260+
/// </summary>
261+
public const string SecurityQuestionRequired = "Please select a security question";
257262
}
258263
}

LearningHub.Nhs.WebUI/Models/UserProfile/UserJobRoleUpdateViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class UserJobRoleUpdateViewModel : PagingViewModel
2424
/// <summary>
2525
/// Gets or sets the selected job role id.
2626
/// </summary>
27-
public int? SelectedJobRoleId { get; set; }
27+
public string SelectedJobRoleId { get; set; }
2828

2929
/// <summary>
3030
/// Gets or sets the RoleList.

LearningHub.Nhs.WebUI/Models/UserProfile/UserPrimarySpecialtyUpdateViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class UserPrimarySpecialtyUpdateViewModel : PagingViewModel
2424
/// <summary>
2525
/// Gets or sets the selected primary specialty id.
2626
/// </summary>
27-
public int? SelectedPrimarySpecialtyId { get; set; }
27+
public string SelectedPrimarySpecialtyId { get; set; }
2828

2929
/// <summary>
3030
/// Gets or sets the SpecialtyList.

LearningHub.Nhs.WebUI/Models/UserProfile/UserStartDateUpdateViewModel.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ public class UserStartDateUpdateViewModel : IValidatableObject
3030
/// </summary>
3131
public int? Year { get; set; }
3232

33-
/////// <summary>
34-
/////// Gets or sets filter text.
35-
/////// </summary>
36-
////public string FilterText { get; set; }
37-
38-
/// <summary>
39-
/// Gets or sets the selected primary specialty id.
40-
/// </summary>
41-
public int? SelectedPrimarySpecialtyId { get; set; }
42-
4333
/// <summary>
4434
/// Gets or sets the GetDate.
4535
/// </summary>

LearningHub.Nhs.WebUI/Services/UserService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ public async Task<UserProfileSummaryViewModel> GetUserProfileSummaryAsync()
12121212
if (employmentViewModel.JobRoleId.HasValue)
12131213
{
12141214
var job = await this.jobRoleService.GetByIdAsync(employmentViewModel.JobRoleId.Value);
1215-
viewModel.JobRole = job.Name;
1215+
viewModel.JobRole = job.NameWithStaffGroup;
12161216

12171217
if (employmentViewModel.GradeId.HasValue)
12181218
{
@@ -2008,7 +2008,7 @@ public async Task<MyAccountEmploymentDetailsViewModel> GetMyEmploymentDetailsAsy
20082008
if (employmentViewModel.JobRoleId.HasValue)
20092009
{
20102010
var job = await this.jobRoleService.GetByIdAsync(employmentViewModel.JobRoleId.Value);
2011-
viewModel.JobRole = job.Name;
2011+
viewModel.JobRole = job.NameWithStaffGroup;
20122012

20132013
if (employmentViewModel.GradeId.HasValue)
20142014
{

LearningHub.Nhs.WebUI/Views/MyAccount/ChangeMedicalCouncilNumber.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
@if (errorHasOccurred)
2727
{
28-
<vc:error-summary order-of-property-names="@(new[] { nameof(Model) })" />
28+
<vc:error-summary order-of-property-names="@(new[] { nameof(Model.SelectedMedicalCouncilNo) })" />
2929
}
3030

3131
<h1 class="nhsuk-heading-xl">Update medical council number</h1>
@@ -62,7 +62,7 @@
6262

6363
<div class="nhsuk-form-group">
6464
<input type="hidden" name="SelectedJobRoleId" value="@Model.SelectedJobRoleId">
65-
<input type="hidden" name="direct" value="@Context.Request.Query["direct"]">
65+
@* <input type="hidden" name="direct" value="@Context.Request.Query["direct"]"> *@
6666
<input type="hidden" name="formSubmission" value="true">
6767
<button type="submit" class="nhsuk-button">Continue</button>
6868
</div>

LearningHub.Nhs.WebUI/Views/MyAccount/_MyAccountSecurityQuestions.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
hint-text=""
3737
required="true"
3838
css-class="nhsuk-u-width-two-thirds"
39-
default-option=""
39+
default-option="Please select a question"
4040
select-list-options="@Model.FirstSecurityQuestions" />
4141
</div>
4242

@@ -60,7 +60,7 @@
6060
hint-text=""
6161
required="true"
6262
css-class="nhsuk-u-width-two-thirds"
63-
default-option=""
63+
default-option="Please select a question"
6464
select-list-options="@Model.SecondSecurityQuestions" />
6565
</div>
6666

0 commit comments

Comments
 (0)