public async Task <ActionResult> ReplaceChair(int establishmentUrn, int gid) { var governor = await _governorsReadService.GetGovernorAsync(gid, User); var roles = new List <eLookupGovernorRole> { (eLookupGovernorRole)governor.RoleId }; if (EnumSets.SharedGovernorRoles.Contains(governor.RoleId.Value)) { var localEquivalent = RoleEquivalence.GetLocalEquivalentToSharedRole((eLookupGovernorRole)governor.RoleId); if (localEquivalent != null) { roles.Add(localEquivalent.Value); } } else { roles.AddRange(RoleEquivalence.GetEquivalentToLocalRole((eLookupGovernorRole)governor.RoleId)); } var governors = (await _governorsReadService.GetSharedGovernorsAsync(establishmentUrn, User)).Where(g => roles.Contains((eLookupGovernorRole)g.RoleId) && g.Id != gid).ToList(); var model = new ReplaceChairViewModel { ExistingGovernorId = gid, GovernorFullName = governor.GetFullName(), DateTermEnds = new DateTimeViewModel(governor.AppointmentEndDate), NewLocalGovernor = new GovernorViewModel { DisplayPolicy = await _governorsReadService.GetEditorDisplayPolicyAsync((RoleEquivalence.GetLocalEquivalentToSharedRole((eLookupGovernorRole)governor.RoleId.Value) ?? (eLookupGovernorRole)governor.RoleId.Value), false, User) }, SharedGovernors = (await Task.WhenAll(governors.Select(async g => await SharedGovernorViewModel.MapFromGovernor(g, establishmentUrn, _cachedLookupService)))).ToList(), NewChairType = ReplaceChairViewModel.ChairType.LocalChair, Role = (eLookupGovernorRole)governor.RoleId, RoleName = _nomenclatureService.GetGovernorRoleName((eLookupGovernorRole)governor.RoleId, eTextCase.Lowerase, false) }; await PopulateSelectLists(model.NewLocalGovernor); await _layoutHelper.PopulateLayoutProperties(model, establishmentUrn, null, User); return(View(model)); }
public async Task <ActionResult> SelectSharedGovernor(int establishmentUrn, eLookupGovernorRole role) { var roleName = (await _cachedLookupService.GovernorRolesGetAllAsync()).Single(x => x.Id == (int)role).Name; var governors = (await _governorsReadService.GetSharedGovernorsAsync(establishmentUrn, User)).Where(g => RoleEquivalence.GetEquivalentRole(role).Contains((eLookupGovernorRole)g.RoleId)).ToList(); var sharedGovernors = governors.Select(async g => await SharedGovernorViewModel.MapFromGovernor(g, establishmentUrn, _cachedLookupService)); var viewModel = new SelectSharedGovernorViewModel { Governors = (await Task.WhenAll(sharedGovernors)).ToList(), GovernorType = roleName.ToLowerInvariant(), }; await _layoutHelper.PopulateLayoutProperties(viewModel, establishmentUrn, null, User); return(View(viewModel)); }
public async Task <ActionResult> ReplaceChair(int establishmentUrn, int gid) { var replaceGovernorState = new { ReplacementGovernorId = Request.QueryString["rgid"].ToInteger(), DateTermEndsDay = Request.QueryString["d"].ToInteger(), DateTermEndsMonth = Request.QueryString["m"].ToInteger(), DateTermEndsYear = Request.QueryString["y"].ToInteger(), Reinstate = Request.QueryString["ri"] == "true" }; var governor = await _governorsReadService.GetGovernorAsync(gid, User); var roles = new List <eLookupGovernorRole> { (eLookupGovernorRole)governor.RoleId }; if (EnumSets.SharedGovernorRoles.Contains(governor.RoleId.Value)) { var localEquivalent = RoleEquivalence.GetLocalEquivalentToSharedRole((eLookupGovernorRole)governor.RoleId); if (localEquivalent != null) { roles.Add(localEquivalent.Value); } } else { roles.AddRange(RoleEquivalence.GetEquivalentToLocalRole((eLookupGovernorRole)governor.RoleId)); } var governors = (await _governorsReadService.GetSharedGovernorsAsync(establishmentUrn, User)).Where(g => roles.Contains((eLookupGovernorRole)g.RoleId) && g.Id != gid).ToList(); var model = new ReplaceChairViewModel { ExistingGovernorId = gid, GovernorFullName = governor.GetFullName(), DateTermEnds = new DateTimeViewModel(governor.AppointmentEndDate), NewLocalGovernor = new GovernorViewModel { DisplayPolicy = await _governorsReadService.GetEditorDisplayPolicyAsync((RoleEquivalence.GetLocalEquivalentToSharedRole((eLookupGovernorRole)governor.RoleId.Value) ?? (eLookupGovernorRole)governor.RoleId.Value), false, User) }, SharedGovernors = (await Task.WhenAll(governors.Select(async g => await SharedGovernorViewModel.MapFromGovernor(g, establishmentUrn, _cachedLookupService)))).ToList(), NewChairType = ReplaceChairViewModel.ChairType.LocalChair, Role = (eLookupGovernorRole)governor.RoleId, RoleName = _nomenclatureService.GetGovernorRoleName((eLookupGovernorRole)governor.RoleId, eTextCase.Lowerase, false) }; var models = await _governorsReadService.GetGovernorListAsync(establishmentUrn, principal : User); var localGovernors = models.CurrentGovernors.Where(x => x.RoleId == (int)eLookupGovernorRole.LocalGovernor).OrderBy(x => x.Person_LastName).ToArray(); if (replaceGovernorState.ReplacementGovernorId.HasValue) { model.SelectedNonChair = localGovernors.FirstOrDefault(x => x.Id == replaceGovernorState.ReplacementGovernorId); PrepopulateFields(model.SelectedNonChair, model); } model.ExistingNonChairs = localGovernors.Select(x => new SelectListItem { Text = x.Person_FirstName + " " + x.Person_LastName, Value = x.Id.ToString(), Selected = replaceGovernorState.ReplacementGovernorId.HasValue && replaceGovernorState.ReplacementGovernorId.Value == x.Id }); await PopulateSelectLists(model.NewLocalGovernor); await _layoutHelper.PopulateLayoutProperties(model, establishmentUrn, null, User); if (replaceGovernorState.DateTermEndsDay.HasValue) { model.Reinstate = replaceGovernorState.Reinstate; model.DateTermEnds.Day = replaceGovernorState.DateTermEndsDay; model.DateTermEnds.Month = replaceGovernorState.DateTermEndsMonth; model.DateTermEnds.Year = replaceGovernorState.DateTermEndsYear; } return(View(model)); }