public async Task <IActionResult> SelectOrChangeContactName()
        {
            var epaoid = _contextAccessor.HttpContext.User.FindFirst("http://schemas.portal.com/epaoid")?.Value;

            try
            {
                var organisation = await _organisationsApiClient.GetEpaOrganisation(epaoid);

                var contacts = await _contactsApiClient.GetAllContactsWhoCanBePrimaryForOrganisation(organisation.OrganisationId);

                var viewModel = new SelectOrChangeContactNameViewModel
                {
                    Contacts       = contacts,
                    PrimaryContact = ModelState.IsValid
                        ? organisation.PrimaryContact
                        : ModelState[nameof(SelectOrChangeContactNameViewModel.PrimaryContact)]?.AttemptedValue
                };

                return(View(viewModel));
            }
            catch (EntityNotFoundException e)
            {
                _logger.LogWarning(e, "Failed to find organisation");
                return(RedirectToAction(nameof(HomeController.NotRegistered), nameof(HomeController).RemoveController()));
            }
        }
示例#2
0
        private async Task GatherOrganisationContacts(RegisterViewAndEditOrganisationViewModel viewAndEditModel)
        {
            viewAndEditModel.Contacts = await _contactsApiClient.GetAllContactsForOrganisation(viewAndEditModel.OrganisationId, false);

            viewAndEditModel.Users = await _contactsApiClient.GetAllContactsForOrganisationIncludePrivileges(viewAndEditModel.OrganisationId, true);

            var contactsWhoCanBePrimary = await _contactsApiClient.GetAllContactsWhoCanBePrimaryForOrganisation(viewAndEditModel.OrganisationId);

            if (viewAndEditModel.PrimaryContact != null && contactsWhoCanBePrimary.Any(x => x.Username == viewAndEditModel.PrimaryContact))
            {
                var primaryContact = contactsWhoCanBePrimary.First(x => x.Username == viewAndEditModel.PrimaryContact);
                viewAndEditModel.PrimaryContactName = primaryContact.DisplayName;
                if (primaryContact.Username != null)
                {
                    viewAndEditModel.PrimaryContactName = $"{viewAndEditModel.PrimaryContactName} ({primaryContact.Username})";
                }
            }
        }