public async Task <RedactedCriminalFileDetailResponse> FileIdAsync(string fileId) { async Task <CriminalFileDetailResponse> FileDetails() => await _filesClient.FilesCriminalFileIdAsync(_requestAgencyIdentifierId, _requestPartId, _requestApplicationCode, fileId); async Task <CriminalFileContent> FileContent() => await _filesClient.FilesCriminalFilecontentAsync(null, null, null, null, fileId); async Task <CriminalFileAppearances> FileAppearances() => await PopulateDetailsAppearancesAsync(fileId, FutureYN.Y, HistoryYN.Y); var fileDetailTask = _cache.GetOrAddAsync($"CriminalFileDetail-{fileId}", FileDetails); var fileContentTask = _cache.GetOrAddAsync($"CriminalFileContent-{fileId}", FileContent); var appearancesTask = _cache.GetOrAddAsync($"CriminalAppearancesFull-{fileId}", FileAppearances); var fileDetail = await fileDetailTask; var fileContent = await fileContentTask; var appearances = await appearancesTask; //CriminalFileContent can return null when an invalid fileId is inserted. if (fileDetail == null || fileContent == null) { return(null); } var detail = _mapper.Map <RedactedCriminalFileDetailResponse>(fileDetail); var documents = PopulateDetailDocuments(fileContent); detail = await PopulateBaseDetail(detail); detail.Appearances = appearances; detail.Witness = await PopulateDetailWitnesses(detail); detail.Participant = await PopulateDetailParticipants(detail, documents, fileContent.AccusedFile); detail.HearingRestriction = await PopulateDetailHearingRestrictions(detail); detail.Crown = PopulateDetailCrown(detail); return(detail); }
private List <Task <CriminalFileDetailResponse> > CriminalFileDetailTasks(List <string> fileIds) { var fileDetailTasks = new List <Task <CriminalFileDetailResponse> >(); foreach (var fileId in fileIds) { async Task <CriminalFileDetailResponse> FileDetails() => await _filesClient.FilesCriminalFileIdAsync(_requestAgencyIdentifierId, _requestPartId, _requestApplicationCode, fileId); fileDetailTasks.Add(_cache.GetOrAddAsync($"CriminalFileDetail-{fileId}", FileDetails)); } return(fileDetailTasks); }