예제 #1
0
        public async Task <ActionResult> Details(int id, string searchQueryString = "", eLookupSearchSource searchSource = eLookupSearchSource.Groups, int skip = 0, string sortBy = null, bool saved = false)
        {
            ViewBag.ShowSaved = saved;

            var model = (await _groupReadService.GetAsync(id, User)).GetResult();

            var viewModel = new GroupDetailViewModel
            {
                SearchQueryString     = searchQueryString,
                SearchSource          = searchSource,
                CanUserEdit           = await _groupReadService.CanEditAsync(id, User),
                CanUserEditGovernance = await _groupReadService.CanEditGovernanceAsync(id, User),
                Group              = model,
                GroupTypeName      = model.GroupTypeId.HasValue ? await _lookup.GetNameAsync(() => model.GroupTypeId) : null,
                LocalAuthorityName = model.LocalAuthorityId.HasValue ? await _lookup.GetNameAsync(() => model.LocalAuthorityId) : null,
                GroupStatusName    = model.StatusId.HasValue ? await _lookup.GetNameAsync(() => model.StatusId, "Group") : null,
                Address            = model.GroupTypeId.OneOfThese(GT.SingleacademyTrust, GT.MultiacademyTrust, GT.ChildrensCentresGroup) ? model.Address.ToString() : null,
                IsUserLoggedOn     = User.Identity.IsAuthenticated,
                GroupTypeId        = model.GroupTypeId ?? -1,
                IsClosed           = model.StatusId == (int)eLookupGroupStatus.Closed || model.StatusId == (int)eLookupGroupStatus.CreatedInError,
                IsClosedInError    = model.StatusId == (int)eLookupGroupStatus.CreatedInError,
                CloseDate          = model.ClosedDate
            };

            if (viewModel.IsUserLoggedOn)
            {
                viewModel.ChangeHistory = await _groupReadService.GetChangeHistoryAsync(id, skip, 100, sortBy.Clean() ?? "requestedDateUtc-desc", User);
            }

            await PopulateEstablishmentList(viewModel.Establishments, model.GroupUId.Value, true);

            return(View(viewModel));
        }
        internal async Task <GovernorsGridViewModel> CreateGovernorsViewModel(int?groupUId = null, int?establishmentUrn = null, EstablishmentModel establishmentModel = null, IPrincipal user = null)
        {
            user             = user ?? User;
            establishmentUrn = establishmentUrn ?? establishmentModel?.Urn;

            var domainModel = await _governorsReadService.GetGovernorListAsync(establishmentUrn, groupUId, user);

            var viewModel = new GovernorsGridViewModel(domainModel, false, groupUId, establishmentUrn, _nomenclatureService,
                                                       (await _cachedLookupService.NationalitiesGetAllAsync()), (await _cachedLookupService.GovernorAppointingBodiesGetAllAsync()));

            if (establishmentUrn.HasValue || establishmentModel != null)
            {
                var estabDomainModel = establishmentModel ?? (await _establishmentReadService.GetAsync(establishmentUrn.Value, user)).GetResult();
                var items            = await _establishmentReadService.GetPermissibleLocalGovernorsAsync(establishmentUrn.Value, user); // The API uses 1 as a default value, hence we have to call another API to deduce whether to show the Governance mode UI section

                viewModel.GovernanceMode = items.Any() ? estabDomainModel.GovernanceMode : null;
            }

            if (groupUId.HasValue)
            {
                var groupModel = (await _groupReadService.GetAsync(groupUId.Value, user)).GetResult();
                viewModel.ShowDelegationInformation = groupModel.GroupTypeId == (int)eLookupGroupType.MultiacademyTrust;
                viewModel.DelegationInformation     = groupModel.DelegationInformation;
            }

            return(viewModel);
        }
예제 #3
0
        public async Task <ActionResult> GroupEditDelegation(int groupUId)
        {
            var group = await _groupReadService.GetAsync(groupUId, User);

            if (group.Success)
            {
                var model = new EditGroupDelegationInformationViewModel
                {
                    DelegationInformation = group.ReturnValue.DelegationInformation
                };

                await _layoutHelper.PopulateLayoutProperties(model, null, groupUId, User);

                return(View(model));
            }
            return(RedirectToRoute("GroupEditGovernance", new { GroupUId = groupUId }));
        }
        public async Task <ActionResult> GroupEditCorporateContact(int groupUId)
        {
            var group = await _groupReadService.GetAsync(groupUId, User);

            if (group.Success)
            {
                var model = new EditGroupCorporateContactViewModel
                {
                    CorporateContact = group.ReturnValue.CorporateContact
                };

                await _layoutHelper.PopulateLayoutProperties(model, null, groupUId, User);

                return(View(model));
            }
            return(RedirectToRoute("GroupEditGovernance", new { GroupUId = groupUId }));
        }
예제 #5
0
        public async Task PopulateLayoutProperties(object viewModel, int?establishmentUrn, int?groupUId, IPrincipal user, Action <EstablishmentModel> processEstablishment = null, Action <GroupModel> processGroup = null)
        {
            if (establishmentUrn.HasValue && groupUId.HasValue)
            {
                throw new InvalidParameterException("Both urn and uid cannot be populated");
            }

            if (!establishmentUrn.HasValue && !groupUId.HasValue)
            {
                throw new InvalidParameterException($"Both {nameof(establishmentUrn)} and {nameof(groupUId)} parameters are null");
            }

            if (establishmentUrn.HasValue)
            {
                var domainModel   = (await _establishmentReadService.GetAsync(establishmentUrn.Value, user)).GetResult();
                var displayPolicy = await _establishmentReadService.GetDisplayPolicyAsync(domainModel, user);

                var permissibleGovernanceModes = await _establishmentReadService.GetPermissibleLocalGovernorsAsync(establishmentUrn.Value, user);

                if (!permissibleGovernanceModes.Any())
                {
                    domainModel.GovernanceModeId = null;                                    // hack the model returned.
                }
                var vm = (IEstablishmentPageViewModel)viewModel;
                vm.Layout = EstabLayout;
                vm.Name   = domainModel.Name;
                if (domainModel.TypeId.HasValue)
                {
                    vm.TypeName = (await _cls.GetNameAsync(() => domainModel.TypeId));
                }
                vm.SelectedTab      = "governance";
                vm.Urn              = domainModel.Urn;
                vm.TabDisplayPolicy = new TabDisplayPolicy(domainModel, displayPolicy, user);
                vm.LegalParentGroup = EstablishmentController.GetLegalParent(vm.Urn.Value, await _groupReadService.GetAllByEstablishmentUrnAsync(vm.Urn.Value, user), user); // I agree, this shouldn't be a static.  We should refector all this. We should have a base view model class.
                processEstablishment?.Invoke(domainModel);
            }
            else if (groupUId.HasValue)
            {
                var domainModel = (await _groupReadService.GetAsync(groupUId.Value, user)).GetResult();
                var vm          = (IGroupPageViewModel)viewModel;
                vm.Layout      = GroupsLayout;
                vm.GroupName   = domainModel.Name;
                vm.GroupTypeId = domainModel.GroupTypeId.Value;
                vm.GroupUId    = groupUId;
                if (vm.GroupTypeId.HasValue)
                {
                    vm.GroupTypeName = (await _cls.GetNameAsync(() => vm.GroupTypeId));
                }
                vm.SelectedTabName = "governance";
                vm.ListOfEstablishmentsPluralName = _nomenclatureService.GetEstablishmentsPluralName((eLookupGroupType)vm.GroupTypeId.Value);
                processGroup?.Invoke(domainModel);
            }
        }
예제 #6
0
        private async Task <Tuple <int, string> > TryGetGoupUid(ChangeHistoryViewModel model)
        {
            int?groupUid  = null;
            var groupName = "";

            if (model.GroupSearchModel.AutoSuggestValueAsInt.HasValue)
            {
                groupUid = model.GroupSearchModel.AutoSuggestValueAsInt.Value;
                var group = await _groupReadService.GetAsync(groupUid.Value, User);

                if (group.Success)
                {
                    groupName = group.ReturnValue.Name;
                }
            }

            if (groupUid == null || string.IsNullOrWhiteSpace(groupName))
            {
                ApiPagedResult <SearchGroupDocument> results = null;
                var searchText = model.GroupSearchModel.Text.Clean();
                if (searchText != null)
                {
                    results =
                        await _groupReadService.SearchByIdsAsync(searchText, searchText.ToInteger(), searchText, searchText.ToInteger(), User);
                }

                if (results == null || results.Count == 0)
                {
                    var payload = new GroupSearchPayload(model.Skip, model.Take)
                    {
                        Text = model.GroupSearchModel.Text.Clean()
                    };

                    results = await _groupReadService.SearchAsync(payload, User);
                }

                if (results != null && results.Count > 0)
                {
                    groupUid  = results.Items.First().GroupUId;
                    groupName = results.Items.First().Name;
                }
                else
                {
                    return(null);
                }
            }

            return(new Tuple <int, string>(groupUid.Value, groupName));
        }
예제 #7
0
        internal async Task <GovernorsGridViewModel> CreateGovernorsViewModel(int?groupUId = null, int?establishmentUrn = null, EstablishmentModel establishmentModel = null, IPrincipal user = null)
        {
            user             = user ?? User;
            establishmentUrn = establishmentUrn ?? establishmentModel?.Urn;
            GovernorsGridViewModel viewModel;

            try
            {
                var domainModel = await _governorsReadService.GetGovernorListAsync(establishmentUrn, groupUId, user);

                var governorPermissions = await _governorsReadService.GetGovernorPermissions(establishmentUrn, groupUId, user);

                viewModel = new GovernorsGridViewModel(domainModel,
                                                       false,
                                                       groupUId,
                                                       establishmentUrn,
                                                       _nomenclatureService,
                                                       await _cachedLookupService.NationalitiesGetAllAsync(),
                                                       await _cachedLookupService.GovernorAppointingBodiesGetAllAsync(),
                                                       governorPermissions);

                if (establishmentUrn.HasValue || establishmentModel != null)
                {
                    var estabDomainModel = establishmentModel ?? (await _establishmentReadService.GetAsync(establishmentUrn.Value, user)).GetResult();
                    var items            = await _establishmentReadService.GetPermissibleLocalGovernorsAsync(establishmentUrn.Value, user); // The API uses 1 as a default value, hence we have to call another API to deduce whether to show the Governance mode UI section

                    viewModel.GovernanceMode = items.Any() ? estabDomainModel.GovernanceMode : null;
                }

                if (groupUId.HasValue)
                {
                    var groupModel = (await _groupReadService.GetAsync(groupUId.Value, user)).GetResult();
                    viewModel.ShowDelegationAndCorpContactInformation = groupModel.GroupTypeId == (int)eLookupGroupType.MultiacademyTrust;
                    viewModel.DelegationInformation = groupModel.DelegationInformation;
                    viewModel.CorporateContact      = groupModel.CorporateContact;
                }
            }
            catch (Exception)   // to more gracefully handle Texuna services UsageQuotaExceededException
            {
                viewModel = new GovernorsGridViewModel {
                    DomainModel = new GovernorsDetailsDto()
                };
            }

            return(viewModel);
        }