public async Task <string> MakeNewPeriodAsync(string nextPeriod)
        {
            using var session = await _ms.StartSessionAsync();

            try
            {
                session.StartTransaction();
                var prevPeriod = await _getCurrentPeriodQuery.GetPeriodAsync();

                var oldTotals = await _totalsQuery.GetTotalsAsync(prevPeriod);

                await _close.ClosePeriodAsync(oldTotals, prevPeriod);

                await _open.OpenPeriodAsync(oldTotals, nextPeriod);

                await _setPeriod.SetPeriodAsync(nextPeriod);

                await session.CommitTransactionAsync();

                return(nextPeriod);
            }
            catch (Exception ex)
            {
                await session.AbortTransactionAsync();

                _logger.LogError(ex, "Error while changing period");
            }

            return(nextPeriod);
        }
Esempio n. 2
0
        public async Task InitializeAsync()
        {
            var period = await _getPeriod.GetPeriodAsync();

            if (period != CreatePeriodId() || period == null)
            {
                Period = await _newPeriod.MakeNewPeriodAsync(period);
            }
            else
            {
                Period = period;
            }
        }