public async Task <IActionResult> ViewStandard(string standardReference) { var contact = await GetUserContact(); var org = await _orgApiClient.GetOrganisationByUserId(contact.Id); var existingApplications = (await _applicationApiClient.GetStandardApplications(contact.Id))? .Where(p => p.ApplicationStatus != ApplicationStatus.Declined); var existingEmptyApplication = existingApplications.FirstOrDefault(x => x.StandardCode == null); if (existingEmptyApplication != null) { return(RedirectToAction("ConfirmStandard", new { Id = existingEmptyApplication.Id, StandardReference = standardReference })); } else { var createApplicationRequest = await _applicationService.BuildInitialRequest(contact, org, _config.ReferenceFormat); var id = await _applicationApiClient.CreateApplication(createApplicationRequest); return(RedirectToAction("ConfirmStandard", new { Id = id, StandardReference = standardReference })); } }