コード例 #1
0
        public async Task <CivilAppearanceDetail> DetailedAppearanceAsync(string fileId, string appearanceId)
        {
            async Task <CivilFileDetailResponse> FileDetails() => await _filesClient.FilesCivilFileIdAsync(_requestAgencyIdentifierId, _requestPartId, fileId);
            async Task <CivilFileContent> FileContent() => await _filesClient.FilesCivilFilecontentAsync(null, null, null, null, fileId);
            async Task <CivilFileAppearancePartyResponse> AppearanceParty() => await _filesClient.FilesCivilAppearanceAppearanceIdPartiesAsync(_requestAgencyIdentifierId, _requestPartId, appearanceId);
            async Task <CivilFileAppearanceApprMethodResponse> AppearanceMethods() => await _filesClient.FilesCivilAppearanceAppearanceIdAppearancemethodsAsync(_requestAgencyIdentifierId, _requestPartId, appearanceId);
            async Task <CivilFileAppearancesResponse> Appearances() => await PopulateDetailAppearancesAsync(FutureYN2.Y, HistoryYN2.Y, fileId);

            var fileDetailTask        = _cache.GetOrAddAsync($"CivilFileDetail-{fileId}", FileDetails);
            var appearancePartyTask   = _cache.GetOrAddAsync($"CivilAppearanceParty-{fileId}-{appearanceId}", AppearanceParty);
            var fileContentTask       = _cache.GetOrAddAsync($"CivilFileContent-{fileId}", FileContent);
            var appearanceMethodsTask = _cache.GetOrAddAsync($"CivilAppearanceMethods-{fileId}-{appearanceId}", AppearanceMethods);
            var appearancesTask       = _cache.GetOrAddAsync($"CivilAppearancesFull-{fileId}", Appearances);

            var detail      = await fileDetailTask;
            var appearances = await appearancesTask;
            var agencyId    = await _locationService.GetLocationAgencyIdentifier(detail?.HomeLocationAgenId);

            var fileContent = await fileContentTask;

            var targetAppearance = appearances?.ApprDetail?.FirstOrDefault(app => app.AppearanceId == appearanceId);

            if (targetAppearance == null || detail == null)
            {
                return(null);
            }

            //Sometimes we can have a bogus location, querying court list wont work.
            ClCivilCourtList civilCourtList = null;

            if (agencyId != null)
            {
                async Task <CourtList> CourtList() => await _filesClient.FilesCourtlistAsync(agencyId, targetAppearance.CourtRoomCd, targetAppearance.AppearanceDt, "CV", detail.FileNumberTxt);

                var courtListTask = _cache.GetOrAddAsync($"CivilCourtList-{agencyId}-{targetAppearance.CourtRoomCd}-{targetAppearance.AppearanceDt}-{detail.FileNumberTxt}", CourtList);
                var courtList     = await courtListTask;
                civilCourtList = courtList.CivilCourtList.FirstOrDefault(cl => cl.AppearanceId == appearanceId);
            }

            var appearanceParty           = await appearancePartyTask;
            var appearanceMethodsResponse = await appearanceMethodsTask;
            var appearanceMethods         = appearanceMethodsResponse.AppearanceMethod;

            var appearanceDetail    = appearances.ApprDetail?.FirstOrDefault(app => app.AppearanceId == appearanceId);
            var fileDetailDocuments = detail.Document.Where(doc => doc.Appearance != null && doc.Appearance.Any(app => app.AppearanceId == appearanceId)).ToList();
            var previousAppearance  = fileContent?.CivilFile.FirstOrDefault(cf => cf.PhysicalFileID == fileId)?.PreviousAppearance.FirstOrDefault(pa => pa?.AppearanceId == appearanceId);

            var detailedAppearance = new CivilAppearanceDetail
            {
                PhysicalFileId       = fileId,
                AgencyId             = await _locationService.GetLocationAgencyIdentifier(detail.HomeLocationAgenId),
                AppearanceId         = appearanceId,
                AppearanceResultCd   = appearanceDetail?.AppearanceResultCd,
                AppearanceReasonCd   = appearanceDetail?.AppearanceReasonCd,
                AppearanceReasonDesc = await _lookupService.GetCivilAppearanceReasonsDescription(appearanceDetail?.AppearanceReasonCd),
                AppearanceResultDesc = await _lookupService.GetCivilAppearanceResultsDescription(appearanceDetail?.AppearanceResultCd),
                CourtRoomCd          = targetAppearance.CourtRoomCd,
                FileNumberTxt        = detail.FileNumberTxt,
                AppearanceDt         = targetAppearance.AppearanceDt,
                AppearanceMethod     = await PopulateAppearanceMethods(appearanceMethods),
                Party              = await PopulateDetailedAppearancePartiesAsync(appearanceParty.Party, civilCourtList?.Parties, previousAppearance, appearanceMethods),
                Document           = await PopulateDetailedAppearanceDocuments(fileDetailDocuments),
                Adjudicator        = await PopulateDetailedAppearanceAdjudicator(previousAppearance, appearanceMethods),
                AdjudicatorComment = previousAppearance?.AdjudicatorComment
            };

            return(detailedAppearance);
        }