public async Task <IActionResult> Index()
        {
            OrganisationResponse organisation;

            try
            {
                var ukprn = _contextAccessor.HttpContext.User.FindFirst("http://schemas.portal.com/ukprn")?.Value;
                if (ukprn != null)
                {
                    organisation = await _organisationsApiClient.Get(ukprn);
                }
                else
                {
                    var epaoid          = _contextAccessor.HttpContext.User.FindFirst("http://schemas.portal.com/epaoid")?.Value;
                    var epaOrganisation = await _organisationsApiClient.GetEpaOrganisation(epaoid);

                    organisation = new OrganisationResponse
                    {
                        EndPointAssessorName           = epaOrganisation.Name,
                        EndPointAssessorOrganisationId = epaOrganisation.OrganisationId,
                        EndPointAssessorUkprn          = (int?)epaOrganisation.Ukprn,
                        Id             = epaOrganisation.Id,
                        PrimaryContact = epaOrganisation.PrimaryContact,
                        Status         = epaOrganisation.Status
                    };
                }
            }
            catch (EntityNotFoundException e)
            {
                _logger.LogWarning(e, "Failed to find organisation");
                return(RedirectToAction(nameof(HomeController.NotRegistered), nameof(HomeController).RemoveController()));
            }

            return(View(organisation));
        }
Beispiel #2
0
        public async Task <IActionResult> AccessDenied()
        {
            if (TempData.Keys.Contains(nameof(PrivilegeAuthorizationDeniedContext)))
            {
                var deniedContext = JsonConvert
                                    .DeserializeObject <PrivilegeAuthorizationDeniedContext>(TempData[nameof(PrivilegeAuthorizationDeniedContext)]
                                                                                             .ToString());

                var userId = Guid.Parse(User.FindFirst("UserId").Value);
                var user   = await _contactsApiClient.GetById(userId);

                OrganisationResponse organisation = null;
                try
                {
                    organisation = await _organisationsApiClient.GetOrganisationByUserId(userId);
                }
                catch (Exception ex)
                {
                    _logger.LogWarning(ex.Message, ex);
                    if (user.OrganisationId == null && user.Status == ContactStatus.Live)
                    {
                        return(RedirectToAction("Index", "OrganisationSearch"));
                    }
                }

                if (user.OrganisationId != null && user.Status == ContactStatus.InvitePending)
                {
                    return(RedirectToAction("InvitePending", "Home"));
                }

                if (organisation != null && organisation.Status == OrganisationStatus.Applying ||
                    organisation.Status == OrganisationStatus.New)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }

                var privilege = (await _contactsApiClient.GetPrivileges()).Single(p => p.Id == deniedContext.PrivilegeId);

                var usersPrivileges = await _contactsApiClient.GetContactPrivileges(userId);

                return(View("~/Views/Account/AccessDeniedForPrivilege.cshtml", new AccessDeniedViewModel
                {
                    Title = privilege.UserPrivilege,
                    Rights = privilege.PrivilegeData.Rights,
                    PrivilegeId = deniedContext.PrivilegeId,
                    ContactId = userId,
                    UserHasUserManagement = usersPrivileges.Any(up => up.Privilege.Key == Privileges.ManageUsers),
                    ReturnController = deniedContext.Controller,
                    ReturnAction = deniedContext.Action,
                    IsUsersOrganisationLive = organisation?.Status == OrganisationStatus.Live
                }));
            }
            else if (TempData.Keys.Contains("UnavailableFeatureContext"))
            {
                return(View("~/Views/Account/UnavailableFeature.cshtml"));
            }

            return(View());
        }
        public async Task <CreateApplicationRequest> BuildInitialRequest(ContactResponse contact, OrganisationResponse organisation, string referenceFormat)
        {
            var startApplicationRequest = new StartApplicationRequest
            {
                UserReference   = contact.Id.ToString(),
                WorkflowType    = WorkflowType,
                ApplicationData = JsonConvert.SerializeObject(new ApplicationData
                {
                    UseTradingName          = false,
                    OrganisationName        = organisation.EndPointAssessorName,
                    OrganisationReferenceId = organisation.Id.ToString(),
                    OrganisationType        = organisation.OrganisationType,
                    CompanySummary          = organisation.CompanySummary,
                    CharitySummary          = organisation.CharitySummary
                })
            };

            return(await BuildRequest(startApplicationRequest, ApplicationTypes.Initial, contact.Id, organisation.Id, referenceFormat));
        }
        public async Task <CreateApplicationRequest> BuildOrganisationWithdrawalRequest(ContactResponse contact, OrganisationResponse organisation, string referenceFormat)
        {
            var pipelinesCount         = _learnerDetailsApiClient.GetPipelinesCount(organisation.EndPointAssessorOrganisationId, null);
            var earliestWithdrawalDate = _organisationsApiClient.GetEarliestWithdrawalDate(organisation.Id, null);

            await Task.WhenAll(pipelinesCount, earliestWithdrawalDate);

            var startApplicationRequest = new StartApplicationRequest
            {
                UserReference   = contact.Id.ToString(),
                WorkflowType    = WorkflowType,
                ApplicationData = JsonConvert.SerializeObject(new ApplicationData
                {
                    UseTradingName           = false,
                    OrganisationName         = organisation.EndPointAssessorName,
                    OrganisationReferenceId  = organisation.Id.ToString(),
                    PipelinesCount           = pipelinesCount.Result,
                    EarliestDateOfWithdrawal = earliestWithdrawalDate.Result
                })
            };

            return(await BuildRequest(startApplicationRequest, ApplicationTypes.OrganisationWithdrawal, contact.Id, organisation.Id, referenceFormat));
        }
        private async Task <Guid> CreateOrganisationWithdrawalApplication(ContactResponse contact, OrganisationResponse organisation)
        {
            var createApplicationRequest = await _applicationService.BuildOrganisationWithdrawalRequest(
                contact,
                organisation,
                _config.ReferenceFormat);

            return(await _applicationApiClient.CreateApplication(createApplicationRequest));
        }
        private async Task <Guid> CreateWithdrawalApplication(ContactResponse contact, OrganisationResponse organisation, int larsCode, string iFateReferenceNumber, string standardTitle, string standardOrVersion, IEnumerable <string> versions)
        {
            var createApplicationRequest = await _applicationService.BuildStandardWithdrawalRequest(
                contact,
                organisation,
                larsCode,
                _config.ReferenceFormat,
                standardOrVersion);

            var id = await _applicationApiClient.CreateApplication(createApplicationRequest);

            var standardApplicationType = versions != null && versions.Any() ? StandardApplicationTypes.VersionWithdrawal : StandardApplicationTypes.StandardWithdrawal;
            await _applicationApiClient.UpdateStandardData(id, larsCode, iFateReferenceNumber, standardTitle, versions?.ToList(), standardApplicationType);

            return(id);
        }