public async Task <IActionResult> Confirm(OrganisationSearchViewModel viewModel) { var user = await GetUser(); if (user is null) { return(RedirectToAction("Index", "Home")); } else if (user.OrganisationId != null && user.Status == ContactStatus.Live) { return(RedirectToAction("Index", "Dashboard")); } else if (string.IsNullOrEmpty(viewModel.Name) || viewModel.SearchString.Length < 2) { ModelState.AddModelError(nameof(viewModel.Name), "Enter a valid search string"); TempData["ShowErrors"] = true; return(RedirectToAction(nameof(Index))); } else if (string.IsNullOrEmpty(viewModel.OrganisationType)) { ModelState.AddModelError(nameof(viewModel.OrganisationType), "Select an organisation type"); TempData["ShowErrors"] = true; viewModel.OrganisationTypes = await _organisationsApiClient.GetOrganisationTypes(); return(View("Type", viewModel)); } if (!string.IsNullOrEmpty(viewModel.OrganisationType)) { viewModel.OrganisationTypes = await _organisationsApiClient.GetOrganisationTypes(); viewModel.OrganisationTypeId = viewModel.OrganisationTypes.Any()? viewModel.OrganisationTypes .First(x => viewModel.OrganisationType != null && x.Type == viewModel.OrganisationType).Id:0; } var organisationSearchResult = await GetOrganisation(viewModel.SearchString, viewModel.Name, viewModel.Ukprn, viewModel.OrganisationType, viewModel.Postcode, viewModel.PageIndex); if (organisationSearchResult != null) { if (organisationSearchResult.CompanyNumber != null) { var isActivelyTrading = await _organisationsApiClient.IsCompanyActivelyTrading(organisationSearchResult.CompanyNumber); if (!isActivelyTrading) { return(View("~/Views/OrganisationSearch/CompanyNotActive.cshtml", viewModel)); } } viewModel.Organisations = new PaginatedList <OrganisationSearchResult>(new List <OrganisationSearchResult> { organisationSearchResult }, 1, 1, 1); viewModel.OrganisationTypes = await _organisationsApiClient.GetOrganisationTypes(); } _sessionService.Set("OrganisationSearchViewModel", viewModel); return(View(viewModel)); }