public async Task <IActionResult> AddOrganisationDetails(AddOrganisationViewModel model)
        {
            var validationMessages = _validator.ValidateProviderType(model.ProviderTypeId);

            if (validationMessages.Any())
            {
                model.ValidationErrors = new List <string>();
                model.ValidationErrors.AddRange(validationMessages);
                model.ProviderTypes = await _apiClient.GetProviderTypes();

                return(View("AddOrganisation", model));
            }

            model.OrganisationTypes = await _apiClient.GetOrganisationTypes(model.ProviderTypeId);

            var sessionModel = _sessionService.GetAddOrganisationDetails(model.OrganisationId);

            if (sessionModel.ProviderTypeId != model.ProviderTypeId)
            {
                sessionModel.OrganisationTypeId = 0;
            }

            _sessionService.SetAddOrganisationDetails(model);

            return(View(model));
        }
        private async Task <int> MapOrganisationDetailsQuestionsToRoatpOrganisationType(Guid applicationId, int providerTypeId)
        {
            int organisationTypeId = 0; // default to 'Unassigned'

            var organisationTypes = await _roatpApiClient.GetOrganisationTypes(providerTypeId);

            string organisationTypePageId     = RoatpWorkflowPageIds.DescribeYourOrganisation.MainSupportingStartPage;
            string organisationTypeQuestionId = RoatpYourOrganisationQuestionIdConstants.OrganisationTypeMainSupporting;

            if (providerTypeId == EmployerProviderTypeId)
            {
                organisationTypePageId     = RoatpWorkflowPageIds.DescribeYourOrganisation.EmployerStartPage;
                organisationTypeQuestionId = RoatpYourOrganisationQuestionIdConstants.OrganisationTypeEmployer;
            }

            var organisationTypePage = await _qnaApiClient.GetPageBySectionNo(applicationId, RoatpWorkflowSequenceIds.YourOrganisation,
                                                                              RoatpWorkflowSectionIds.YourOrganisation.DescribeYourOrganisation, organisationTypePageId);

            var organisationDetailsAnswers = organisationTypePage.PageOfAnswers.FirstOrDefault();

            if (organisationDetailsAnswers != null && organisationTypes != null)
            {
                var organisationTypeAnswer =
                    organisationDetailsAnswers.Answers.FirstOrDefault(x => x.QuestionId == organisationTypeQuestionId);

                if (organisationTypeAnswer != null)
                {
                    var matchingOrganisationType =
                        organisationTypes.FirstOrDefault(x => x.Type.Equals(organisationTypeAnswer.Value));

                    if (matchingOrganisationType != null)
                    {
                        return(matchingOrganisationType.Id);
                    }

                    switch (organisationTypeAnswer.Value)
                    {
                    case RailFranchise:
                        organisationTypeId =
                            organisationTypes.FirstOrDefault(x => x.Type == RoatpMatchRailFranchise).Id;
                        break;

                    case PublicBodyOrganisationType:
                        organisationTypeId =
                            await MapPublicBodyOrganisationType(applicationId, providerTypeId, organisationTypes);

                        break;

                    case EducationalInstituteOrganisationType:
                        organisationTypeId =
                            await MapEducationalInstituteOrganisationType(applicationId, providerTypeId,
                                                                          organisationTypes);

                        break;
                    }
                }
            }

            return(organisationTypeId);
        }
Example #3
0
        public async Task <IActionResult> AddOrganisationType(AddOrganisationProviderTypeViewModel model)
        {
            var addOrganisationModel = new AddOrganisationViewModel();

            if (string.IsNullOrEmpty(model.LegalName))
            {
                addOrganisationModel     = _sessionService.GetAddOrganisationDetails();
                model.LegalName          = addOrganisationModel.LegalName;
                model.ProviderTypeId     = addOrganisationModel.ProviderTypeId;
                model.OrganisationTypeId = addOrganisationModel.OrganisationTypeId;
            }

            if (!IsRedirectFromConfirmationPage() && !ModelState.IsValid && model.ProviderTypeId == 0)
            {
                model.ProviderTypes = await _apiClient.GetProviderTypes();

                return(View("~/Views/Roatp/AddProviderType.cshtml", model));
            }

            addOrganisationModel = _sessionService.GetAddOrganisationDetails();

            if (string.IsNullOrEmpty(addOrganisationModel?.LegalName))
            {
                return(Redirect("organisations-details"));
            }

            UpdateAddOrganisationModelFromProviderTypeModel(addOrganisationModel, model);


            var organisationTypes = await _apiClient.GetOrganisationTypes(addOrganisationModel.ProviderTypeId);

            addOrganisationModel.OrganisationTypes = organisationTypes.ToList().OrderBy(x => x.Id != 0).ThenBy(x => x.Type);

            if (!addOrganisationModel.OrganisationTypes.Any(x => x.Id == addOrganisationModel.OrganisationTypeId))
            {
                addOrganisationModel.OrganisationTypeId = 0;
            }

            _sessionService.SetAddOrganisationDetails(addOrganisationModel);

            ModelState.Clear();

            var vm = Mapper.Map <AddOrganisationTypeViewModel>(addOrganisationModel);

            return(View("~/Views/Roatp/AddOrganisationType.cshtml", vm));
        }