public async Task <IActionResult> Index(int?collectionYear, int?period, CancellationToken cancellationToken)
        {
            var currentYearPeriod = await _periodService.ReturnPeriod(CollectionType, cancellationToken);

            currentYearPeriod.Year = currentYearPeriod.Year ?? 0;
            var model = new PeriodEndPrepViewModel();

            if (collectionYear != null && period != null)
            {
                model.Year   = collectionYear.Value;
                model.Period = period.Value;
            }
            else
            {
                model.Year   = currentYearPeriod.Year.Value;
                model.Period = currentYearPeriod.Period;
            }

            var isCurrentPeriodSelected = currentYearPeriod.Year == model.Year && currentYearPeriod.Period == model.Period;

            model.IsCurrentPeriod = isCurrentPeriodSelected;
            model.Closed          = (isCurrentPeriodSelected && currentYearPeriod.PeriodClosed) || (collectionYear == currentYearPeriod.Year && period < currentYearPeriod.Period) || (collectionYear <= currentYearPeriod.Year);

            string state = await _periodEndService.GetPrepStateAsync(model.Year, model.Period, CollectionType, cancellationToken);

            model.PeriodEndPrepModel = _stateService.GetPrepState(state);

            return(View(model));
        }
Beispiel #2
0
        protected override async Task DoWork(CancellationToken cancellationToken)
        {
            try
            {
                string state = await _periodEndService.GetPrepStateAsync(null, null, CollectionTypes.ILR, cancellationToken);

                // Send JSON to clients.
                await _periodEndPrepHub.SendMessage(state, cancellationToken);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to {nameof(DoWork)} in {nameof(PeriodEndPrepTimedHostedService)}", ex);
            }
        }
        public async Task <IActionResult> Index(int?collectionYear, int?period, CancellationToken cancellationToken)
        {
            var returnPeriod = await _periodService.ReturnPeriod(CollectionType, cancellationToken);

            var years = await _periodService.GetValidityYearsAsync(CollectionType, null, cancellationToken);

            var year         = collectionYear ?? returnPeriod.Year ?? 0;
            var periodNumber = period ?? returnPeriod.Period;

            var stateString = await _periodEndService.GetPrepStateAsync(year, periodNumber, CollectionType, cancellationToken);

            var state = _stateService.GetPrepState(stateString);

            var model = new ValidityPeriodViewModel
            {
                Year   = year,
                Period = periodNumber,
                PeriodEndInProgress = state.State.PeriodEndStarted && !state.State.PeriodEndFinished,
                AllYears            = years
            };

            return(View(model));
        }