private static async Task DoWrite(
            TextWriter file,
            Release release,
            IList <DataGuidanceSubjectViewModel> subjects)
        {
            // Add header information including publication/release title
            await file.WriteLineAsync(release.Publication.Title);

            await file.WriteLineAsync(
                TimePeriodLabelFormatter.Format(
                    release.Year,
                    release.TimePeriodCoverage,
                    TimePeriodLabelFormat.FullLabel
                    )
                );

            if (!release.DataGuidance.IsNullOrWhitespace())
            {
                await file.WriteLineAsync();

                // Add the release's guidance content
                var guidance = await HtmlToTextUtils.HtmlToText(release.DataGuidance);

                await file.WriteAsync(guidance);

                await file.WriteLineAsync();
            }

            await WriteDataFiles(file, subjects);
        }
        private Task <Either <ActionResult, FastTrackViewModel> > BuildViewModel(FastTrack fastTrack)
        {
            return(_releaseRepository
                   .FindOrNotFoundAsync(fastTrack.ReleaseId)
                   .OnSuccessCombineWith(_ => _tableBuilderService.Query(fastTrack.ReleaseId, fastTrack.Query))
                   .OnSuccess(releaseAndResults =>
            {
                var(release, result) = releaseAndResults;
                var viewModel = _mapper.Map <FastTrackViewModel>(fastTrack);
                viewModel.FullTable = result;
                viewModel.Query.PublicationId = release.PublicationId;
                viewModel.ReleaseSlug = release.Slug;

                var latestRelease = _releaseRepository.GetLatestPublishedRelease(release.PublicationId);
                viewModel.LatestData = latestRelease?.Id == release.Id;
                viewModel.LatestReleaseTitle = latestRelease != null
                        ? TimePeriodLabelFormatter.Format(latestRelease.Year, latestRelease.TimeIdentifier,
                                                          FullLabelBeforeYear) : null;
                return viewModel;
            }));
        }
        public TimePeriodLabels GetTimePeriodLabels(Guid subjectId)
        {
            var observationsQuery = _context
                                    .Observation
                                    .AsQueryable()
                                    .Where(observation => observation.SubjectId == subjectId);

            var orderedTimePeriods = GetDistinctObservationTimePeriods(observationsQuery);

            if (!orderedTimePeriods.Any())
            {
                return(new TimePeriodLabels());
            }

            var first = orderedTimePeriods.First();
            var last  = orderedTimePeriods.Last();

            return(new TimePeriodLabels(
                       TimePeriodLabelFormatter.Format(first.Year, first.TimeIdentifier),
                       TimePeriodLabelFormatter.Format(last.Year, last.TimeIdentifier)));
        }
        private async Task <MetaGuidanceSubjectTimePeriodsViewModel> GetTimePeriods(Guid subjectId)
        {
            var orderedTimePeriods = _context
                                     .Observation
                                     .Where(observation => observation.SubjectId == subjectId)
                                     .Select(observation => new { observation.Year, observation.TimeIdentifier })
                                     .OrderBy(tuple => tuple.Year)
                                     .ThenBy(tuple => tuple.TimeIdentifier);

            if (!orderedTimePeriods.Any())
            {
                return(new MetaGuidanceSubjectTimePeriodsViewModel());
            }

            var first = await orderedTimePeriods.FirstAsync();

            var last = await orderedTimePeriods.LastAsync();

            return(new MetaGuidanceSubjectTimePeriodsViewModel(
                       TimePeriodLabelFormatter.Format(first.Year, first.TimeIdentifier),
                       TimePeriodLabelFormatter.Format(last.Year, last.TimeIdentifier)));
        }
Beispiel #5
0
 public TimePeriodMetaViewModel(int year, TimeIdentifier code)
 {
     Code  = code;
     Label = TimePeriodLabelFormatter.Format(year, code);
     Year  = year;
 }