From 2960493bdf1ddc050bf4a524b669ee22d5d02779 Mon Sep 17 00:00:00 2001 From: Arunima George Date: Mon, 15 Sep 2025 12:47:16 +0100 Subject: [PATCH] TD-6133: Fixed issues on Employment tab - My account --- .../Controllers/LoginWizardController.cs | 16 +++ .../Controllers/MyAccountController.cs | 111 +++++++++++++----- .../Helpers/CommonValidationErrorMessages.cs | 5 + .../UserProfile/UserJobRoleUpdateViewModel.cs | 2 +- .../UserPrimarySpecialtyUpdateViewModel.cs | 2 +- .../UserStartDateUpdateViewModel.cs | 10 -- LearningHub.Nhs.WebUI/Services/UserService.cs | 4 +- .../ChangeMedicalCouncilNumber.cshtml | 4 +- .../_MyAccountSecurityQuestions.cshtml | 4 +- 9 files changed, 108 insertions(+), 50 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/LoginWizardController.cs b/LearningHub.Nhs.WebUI/Controllers/LoginWizardController.cs index 8f1b57a96..795773ca1 100644 --- a/LearningHub.Nhs.WebUI/Controllers/LoginWizardController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/LoginWizardController.cs @@ -611,6 +611,22 @@ public async Task UpdateSecurityQuestionPost(MyAcountSecurityQues if (model != null) { + if ((model.SelectedFirstQuestionId == 0) || (model.SelectedSecondQuestionId == 0)) + { + if (model.SelectedFirstQuestionId == 0) + { + this.ModelState.AddModelError(nameof(model.SelectedFirstQuestionId), CommonValidationErrorMessages.SecurityQuestionRequired); + } + + if (model.SelectedSecondQuestionId == 0) + { + this.ModelState.AddModelError(nameof(model.SelectedSecondQuestionId), CommonValidationErrorMessages.SecurityQuestionRequired); + } + + this.ViewBag.ReturnUrl = returnUrl; + return this.View("SecurityQuestionsDetails", securityViewModel); + } + if (model.SelectedFirstQuestionId == model.SelectedSecondQuestionId) { this.ModelState.AddModelError("DuplicateQuestion", CommonValidationErrorMessages.DuplicateQuestion); diff --git a/LearningHub.Nhs.WebUI/Controllers/MyAccountController.cs b/LearningHub.Nhs.WebUI/Controllers/MyAccountController.cs index ac3adc567..3bb63d6e2 100644 --- a/LearningHub.Nhs.WebUI/Controllers/MyAccountController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/MyAccountController.cs @@ -141,7 +141,7 @@ public async Task Index(string returnUrl = null, bool? checkDetai /// Whether to check account details. /// IActionResult. [HttpGet] - [Route("myaccount-employement")] + [Route("myaccount-employment")] public async Task MyEmploymentDetails(bool? checkDetails = false) { string loginWizardCacheKey = $"{this.CurrentUserId}:LoginWizard"; @@ -1003,25 +1003,36 @@ public async Task ChangeCurrentRole([FromQuery] UserJobRoleUpdate return this.View("ChangeCurrentRole", viewModel); } - if (!string.IsNullOrWhiteSpace(viewModel.FilterText)) - { - var jobRoles = await this.jobRoleService.GetPagedFilteredAsync(viewModel.FilterText, viewModel.CurrentPage, viewModel.PageSize); - viewModel.RoleList = jobRoles.Item2; - viewModel.TotalItems = jobRoles.Item1; - viewModel.HasItems = jobRoles.Item1 > 0; - } - if (formSubmission) { - if (viewModel.SelectedJobRoleId.HasValue) + var hasSelectedJobRoleId = int.TryParse(viewModel.SelectedJobRoleId, out int currentRole); + if (hasSelectedJobRoleId && currentRole > 0) { - var newRoleId = viewModel.SelectedJobRoleId.Value; + var newRoleId = currentRole; var jobRole = await this.jobRoleService.GetByIdAsync(newRoleId); if (jobRole.MedicalCouncilId > 0 && jobRole.MedicalCouncilId < 4) { return this.RedirectToAction(nameof(this.ChangeMedicalCouncilNo), new UserMedicalCouncilNoUpdateViewModel { SelectedJobRoleId = newRoleId }); } + else if (this.User.IsInRole("BasicUser")) + { + await this.userService.UpdateUserEmployment( + new elfhHub.Nhs.Models.Entities.UserEmployment + { + Id = profile.EmploymentId, + UserId = profile.Id, + JobRoleId = newRoleId, + GradeId = profile.GradeId, + SpecialtyId = profile.SpecialtyId, + StartDate = profile.JobStartDate, + LocationId = profile.LocationId, + }); + + this.ViewBag.SuccessMessage = CommonValidationErrorMessages.EmploymentDetailsUpdated; + this.ViewBag.MyAction = "MyEmploymentDetails"; + return this.View("SuccessMessageMyAccount"); + } else { return this.RedirectToAction(nameof(this.ChangeGrade), new UserGradeUpdateViewModel { SelectedJobRoleId = newRoleId }); @@ -1030,9 +1041,24 @@ public async Task ChangeCurrentRole([FromQuery] UserJobRoleUpdate else { this.ModelState.AddModelError(nameof(viewModel.SelectedJobRoleId), CommonValidationErrorMessages.RoleRequired); - return this.View("ChangeCurrentRole", viewModel); } } + else + { + if (string.IsNullOrEmpty(viewModel.FilterText)) + { + viewModel.FilterText = profile.JobRole; + viewModel.SelectedJobRoleId = profile.JobRoleId.HasValue ? profile.JobRoleId.ToString() : string.Empty; + } + } + + if (!string.IsNullOrWhiteSpace(viewModel.FilterText)) + { + var jobRoles = await this.jobRoleService.GetPagedFilteredAsync(viewModel.FilterText, viewModel.CurrentPage, viewModel.PageSize); + viewModel.RoleList = jobRoles.Item2; + viewModel.TotalItems = jobRoles.Item1; + viewModel.HasItems = jobRoles.Item1 > 0; + } return this.View("ChangeCurrentRole", viewModel); } @@ -1075,24 +1101,25 @@ public async Task ChangeMedicalCouncilNo([FromQuery] UserMedicalC this.ModelState.AddModelError(nameof(viewModel.SelectedMedicalCouncilNo), validateMedicalCouncilNumber); return this.View("ChangeMedicalCouncilNumber", viewModel); } - else if (direct) + else if (this.User.IsInRole("BasicUser") || direct) { await this.userService.UpdateUserEmployment( - new elfhHub.Nhs.Models.Entities.UserEmployment - { - Id = profile.EmploymentId, - UserId = profile.Id, - JobRoleId = profile.JobRoleId, - MedicalCouncilId = viewModel.SelectedMedicalCouncilId, - MedicalCouncilNo = viewModel.SelectedMedicalCouncilNo, - GradeId = profile.GradeId, - SpecialtyId = profile.SpecialtyId, - StartDate = profile.JobStartDate, - LocationId = profile.LocationId, - }); - - this.ViewBag.SuccessMessage = "Your medical council number has been changed"; - return this.View("SuccessMessage"); + new elfhHub.Nhs.Models.Entities.UserEmployment + { + Id = profile.EmploymentId, + UserId = profile.Id, + JobRoleId = viewModel.SelectedJobRoleId, + MedicalCouncilId = viewModel.SelectedMedicalCouncilId, + MedicalCouncilNo = viewModel.SelectedMedicalCouncilNo, + GradeId = profile.GradeId, + SpecialtyId = profile.SpecialtyId, + StartDate = profile.JobStartDate, + LocationId = profile.LocationId, + }); + + this.ViewBag.SuccessMessage = CommonValidationErrorMessages.EmploymentDetailsUpdated; + this.ViewBag.MyAction = "MyEmploymentDetails"; + return this.View("SuccessMessageMyAccount"); } else { @@ -1111,6 +1138,13 @@ await this.userService.UpdateUserEmployment( return this.View("ChangeMedicalCouncilNumber", viewModel); } } + else + { + if (string.IsNullOrEmpty(viewModel.SelectedMedicalCouncilNo)) + { + viewModel.SelectedMedicalCouncilNo = profile.MedicalCouncilNo; + } + } return this.View("ChangeMedicalCouncilNumber", viewModel); } @@ -1198,8 +1232,10 @@ public async Task ChangePrimarySpecialty([FromQuery] UserPrimaryS if (formSubmission) { - if (viewModel.SelectedPrimarySpecialtyId.HasValue) + var hasSelectedPrimarySpeciality = int.TryParse(viewModel.SelectedPrimarySpecialtyId, out int selectedPrimarySpecialtyId); + if (hasSelectedPrimarySpeciality && selectedPrimarySpecialtyId > 0) { + var newPrimarySpecialtyId = selectedPrimarySpecialtyId; await this.userService.UpdateUserEmployment( new elfhHub.Nhs.Models.Entities.UserEmployment { @@ -1209,7 +1245,7 @@ await this.userService.UpdateUserEmployment( MedicalCouncilId = profile.MedicalCouncilId, MedicalCouncilNo = profile.MedicalCouncilNo, GradeId = profile.GradeId, - SpecialtyId = viewModel.SelectedPrimarySpecialtyId.Value, + SpecialtyId = newPrimarySpecialtyId, StartDate = profile.JobStartDate, LocationId = profile.LocationId, }); @@ -1218,8 +1254,15 @@ await this.userService.UpdateUserEmployment( } else { - this.ModelState.AddModelError(nameof(viewModel.SelectedPrimarySpecialtyId), CommonValidationErrorMessages.SpecialtyNotApplicable); - return this.View("ChangePrimarySpecialty", viewModel); + this.ModelState.AddModelError(nameof(viewModel.SelectedPrimarySpecialtyId), CommonValidationErrorMessages.SpecialtyRequired); + } + } + else + { + if (string.IsNullOrWhiteSpace(viewModel.FilterText)) + { + viewModel.FilterText = profile.PrimarySpecialty; + viewModel.SelectedPrimarySpecialtyId = profile.SpecialtyId.HasValue ? profile.SpecialtyId.ToString() : string.Empty; } } @@ -1274,6 +1317,10 @@ await this.userService.UpdateUserEmployment( this.ModelState.Remove("Day"); this.ModelState.Remove("Month"); this.ModelState.Remove("Year"); + + viewModel.Day = profile.JobStartDate.HasValue ? profile.JobStartDate.Value.Day : null; + viewModel.Month = profile.JobStartDate.HasValue ? profile.JobStartDate.GetValueOrDefault().Month : null; + viewModel.Year = profile.JobStartDate.HasValue ? profile.JobStartDate.Value.Year : null; } return this.View("ChangeStartDate", viewModel); diff --git a/LearningHub.Nhs.WebUI/Helpers/CommonValidationErrorMessages.cs b/LearningHub.Nhs.WebUI/Helpers/CommonValidationErrorMessages.cs index 440692fae..e41b794f1 100644 --- a/LearningHub.Nhs.WebUI/Helpers/CommonValidationErrorMessages.cs +++ b/LearningHub.Nhs.WebUI/Helpers/CommonValidationErrorMessages.cs @@ -254,5 +254,10 @@ public static class CommonValidationErrorMessages /// location Success Message. /// public const string PersonalDetailsSuccessMessage = "Your personal details has been changed"; + + /// + /// Security question Required. + /// + public const string SecurityQuestionRequired = "Please select a security question"; } } diff --git a/LearningHub.Nhs.WebUI/Models/UserProfile/UserJobRoleUpdateViewModel.cs b/LearningHub.Nhs.WebUI/Models/UserProfile/UserJobRoleUpdateViewModel.cs index a48170b6c..a2e9fe004 100644 --- a/LearningHub.Nhs.WebUI/Models/UserProfile/UserJobRoleUpdateViewModel.cs +++ b/LearningHub.Nhs.WebUI/Models/UserProfile/UserJobRoleUpdateViewModel.cs @@ -24,7 +24,7 @@ public class UserJobRoleUpdateViewModel : PagingViewModel /// /// Gets or sets the selected job role id. /// - public int? SelectedJobRoleId { get; set; } + public string SelectedJobRoleId { get; set; } /// /// Gets or sets the RoleList. diff --git a/LearningHub.Nhs.WebUI/Models/UserProfile/UserPrimarySpecialtyUpdateViewModel.cs b/LearningHub.Nhs.WebUI/Models/UserProfile/UserPrimarySpecialtyUpdateViewModel.cs index 5c91bd661..563b2b668 100644 --- a/LearningHub.Nhs.WebUI/Models/UserProfile/UserPrimarySpecialtyUpdateViewModel.cs +++ b/LearningHub.Nhs.WebUI/Models/UserProfile/UserPrimarySpecialtyUpdateViewModel.cs @@ -24,7 +24,7 @@ public class UserPrimarySpecialtyUpdateViewModel : PagingViewModel /// /// Gets or sets the selected primary specialty id. /// - public int? SelectedPrimarySpecialtyId { get; set; } + public string SelectedPrimarySpecialtyId { get; set; } /// /// Gets or sets the SpecialtyList. diff --git a/LearningHub.Nhs.WebUI/Models/UserProfile/UserStartDateUpdateViewModel.cs b/LearningHub.Nhs.WebUI/Models/UserProfile/UserStartDateUpdateViewModel.cs index 372427781..8d45071cd 100644 --- a/LearningHub.Nhs.WebUI/Models/UserProfile/UserStartDateUpdateViewModel.cs +++ b/LearningHub.Nhs.WebUI/Models/UserProfile/UserStartDateUpdateViewModel.cs @@ -30,16 +30,6 @@ public class UserStartDateUpdateViewModel : IValidatableObject /// public int? Year { get; set; } - /////// - /////// Gets or sets filter text. - /////// - ////public string FilterText { get; set; } - - /// - /// Gets or sets the selected primary specialty id. - /// - public int? SelectedPrimarySpecialtyId { get; set; } - /// /// Gets or sets the GetDate. /// diff --git a/LearningHub.Nhs.WebUI/Services/UserService.cs b/LearningHub.Nhs.WebUI/Services/UserService.cs index b7390de5d..8f5e7c667 100644 --- a/LearningHub.Nhs.WebUI/Services/UserService.cs +++ b/LearningHub.Nhs.WebUI/Services/UserService.cs @@ -1212,7 +1212,7 @@ public async Task GetUserProfileSummaryAsync() if (employmentViewModel.JobRoleId.HasValue) { var job = await this.jobRoleService.GetByIdAsync(employmentViewModel.JobRoleId.Value); - viewModel.JobRole = job.Name; + viewModel.JobRole = job.NameWithStaffGroup; if (employmentViewModel.GradeId.HasValue) { @@ -2008,7 +2008,7 @@ public async Task GetMyEmploymentDetailsAsy if (employmentViewModel.JobRoleId.HasValue) { var job = await this.jobRoleService.GetByIdAsync(employmentViewModel.JobRoleId.Value); - viewModel.JobRole = job.Name; + viewModel.JobRole = job.NameWithStaffGroup; if (employmentViewModel.GradeId.HasValue) { diff --git a/LearningHub.Nhs.WebUI/Views/MyAccount/ChangeMedicalCouncilNumber.cshtml b/LearningHub.Nhs.WebUI/Views/MyAccount/ChangeMedicalCouncilNumber.cshtml index d4ee69910..533865567 100644 --- a/LearningHub.Nhs.WebUI/Views/MyAccount/ChangeMedicalCouncilNumber.cshtml +++ b/LearningHub.Nhs.WebUI/Views/MyAccount/ChangeMedicalCouncilNumber.cshtml @@ -25,7 +25,7 @@ @if (errorHasOccurred) { - + }

Update medical council number

@@ -62,7 +62,7 @@
- + @* *@
diff --git a/LearningHub.Nhs.WebUI/Views/MyAccount/_MyAccountSecurityQuestions.cshtml b/LearningHub.Nhs.WebUI/Views/MyAccount/_MyAccountSecurityQuestions.cshtml index 097575505..3bf78b83c 100644 --- a/LearningHub.Nhs.WebUI/Views/MyAccount/_MyAccountSecurityQuestions.cshtml +++ b/LearningHub.Nhs.WebUI/Views/MyAccount/_MyAccountSecurityQuestions.cshtml @@ -36,7 +36,7 @@ hint-text="" required="true" css-class="nhsuk-u-width-two-thirds" - default-option="" + default-option="Please select a question" select-list-options="@Model.FirstSecurityQuestions" /> @@ -60,7 +60,7 @@ hint-text="" required="true" css-class="nhsuk-u-width-two-thirds" - default-option="" + default-option="Please select a question" select-list-options="@Model.SecondSecurityQuestions" />