Exemple #1
0
        public async Task <IActionResult> UkprnPreview(AddOrganisationViaUkprnViewModel model)
        {
            if (!IsRedirectFromConfirmationPage() && !ModelState.IsValid)
            {
                var addOrganisationModel = _sessionService.GetAddOrganisationDetails();
                if (addOrganisationModel?.UKPRN != null)
                {
                    model.UKPRN = addOrganisationModel.UKPRN.Trim();
                }

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

            AssessorService.Api.Types.Models.UKRLP.UkrlpProviderDetails details;


            try
            {
                _sessionService.SetAddOrganisationDetails(new AddOrganisationViewModel
                {
                    UKPRN = model.UKPRN.Trim()
                });
                var fullProviderDetails = await _apiClient
                                          .GetUkrlpProviderDetails(model.UKPRN.Trim());

                details = _ukrlpProcessingService.ProcessDetails(fullProviderDetails.ToList());
            }
            catch (HttpRequestException ex)
            {
                _logger.LogError(ex, $"Failed to gather organisation details from ukrlp for UKPRN:[{model?.UKPRN}]");
                return(RedirectToAction("UklrpIsUnavailable"));
            }

            if (string.IsNullOrEmpty(details.LegalName))
            {
                return(Redirect("/ukprn-not-found"));
            }

            _sessionService.SetAddOrganisationDetails(new AddOrganisationViewModel
            {
                UKPRN         = model.UKPRN,
                LegalName     = details.LegalName,
                TradingName   = details.TradingName,
                CompanyNumber = details.CompanyNumber,
                CharityNumber = details.CharityNumber
            });

            var vm = new AddOrganisationProviderTypeViewModel
            {
                UKPRN         = model.UKPRN,
                LegalName     = details.LegalName,
                TradingName   = details.TradingName,
                CompanyNumber = details.CompanyNumber,
                CharityNumber = details.CharityNumber
            };

            return(View("~/Views/Roatp/UkprnPreview.cshtml", vm));
        }
Exemple #2
0
        public async Task <IActionResult> AddOrganisation(AddOrganisationProviderTypeViewModel model)
        {
            if (model == null)
            {
                model = new AddOrganisationProviderTypeViewModel();
            }

            model.ProviderTypes = await _apiClient.GetProviderTypes();

            ModelState.Clear();

            return(View("~/Views/Roatp/AddOrganisation.cshtml", model));
        }
Exemple #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));
        }
Exemple #4
0
        public async Task <IActionResult> AddOrganisationDetails(AddOrganisationProviderTypeViewModel model)
        {
            if (!IsRedirectFromConfirmationPage() && !ModelState.IsValid)
            {
                model.ProviderTypes = await _apiClient.GetProviderTypes();

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

            var addOrganisationModel = _sessionService.GetAddOrganisationDetails();

            if (addOrganisationModel == null)
            {
                addOrganisationModel = new AddOrganisationViewModel
                {
                    OrganisationId = model.OrganisationId,
                    ProviderTypeId = model.ProviderTypeId
                };
            }
            else
            {
                if (model.OrganisationId != Guid.Empty)
                {
                    addOrganisationModel.OrganisationId = model.OrganisationId;
                }

                if (model.ProviderTypeId > 0)
                {
                    addOrganisationModel.ProviderTypeId = model.ProviderTypeId;
                }
            }

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

            _sessionService.SetAddOrganisationDetails(addOrganisationModel);

            ModelState.Clear();

            return(View("~/Views/Roatp/AddOrganisationDetails.cshtml", addOrganisationModel));
        }
Exemple #5
0
        private static void UpdateAddOrganisationModelFromProviderTypeModel(AddOrganisationViewModel addOrganisationModel, AddOrganisationProviderTypeViewModel model)
        {
            if (string.IsNullOrEmpty(addOrganisationModel.LegalName))
            {
                addOrganisationModel.LegalName = model.LegalName;
            }
            if (string.IsNullOrEmpty(addOrganisationModel.TradingName))
            {
                addOrganisationModel.TradingName = model.TradingName;
            }
            if (string.IsNullOrEmpty(addOrganisationModel.CompanyNumber))
            {
                addOrganisationModel.CompanyNumber = model.CompanyNumber;
            }
            if (string.IsNullOrEmpty(addOrganisationModel.CharityNumber))
            {
                addOrganisationModel.CharityNumber = model.CharityNumber;
            }
            if (string.IsNullOrEmpty(addOrganisationModel.UKPRN))
            {
                addOrganisationModel.UKPRN = model.UKPRN;
            }

            if (model.OrganisationId != Guid.Empty)
            {
                addOrganisationModel.OrganisationId = model.OrganisationId;
            }

            if (model.ProviderTypeId > 0)
            {
                addOrganisationModel.ProviderTypeId = model.ProviderTypeId;
            }
        }