Пример #1
0
        public async Task <IEnumerable <IReport> > GetAvailableReportsAsync(int collectionYear, int period, CancellationToken cancellationToken = default(CancellationToken))
        {
            var authorisedReports = new List <IReport>();

            var openPeriods = await _periodService.GetOpenPeriodsAsync(cancellationToken);

            var isOpenPeriod = openPeriods.Any(p => p.CollectionYear == collectionYear && p.PeriodNumber == period);

            var allIlrReturnPeriodsForYear = (await _periodService.GetAllIlrPeriodsAsync(cancellationToken))
                                             .Where(w => w.CollectionYear == collectionYear);

            var isLastPeriodInYear = !allIlrReturnPeriodsForYear.Any() || (period == allIlrReturnPeriodsForYear.Where(r => r.StartDateTimeUtc < _dateTimeProvider.GetNowUtc()).Max(o => o.PeriodNumber));

            foreach (var report in _reports.Where(r => isOpenPeriod || isLastPeriodInYear || r.IsApplicableForClosedPeriodOnly))
            {
                if (await _authorisationService.IsAuthorisedForReport(report))
                {
                    authorisedReports.Add(report);
                }
            }

            IEnumerable <string> collectionsForYear = new List <string>();

            if (!_collectionsByYear.TryGetValue(collectionYear, out collectionsForYear))
            {
                _collectionsByYear.Add(collectionYear, (await _collectionsService.GetAllCollectionsForYear(collectionYear, cancellationToken)).Select(s => s.CollectionName));
            }

            return(authorisedReports
                   .Where(w => _collectionsByYear[collectionYear].Contains(w.CollectionName.Replace(Constants.CollectionYearToken, collectionYear.ToString())) || w.ReportType == ReportType.Validation));
        }