public async Task Handle(LevySchemeDeclarationUpdatedMessage levySchemeDeclaration) { _logger.Debug($"Now generating account projections for id: {levySchemeDeclaration.AccountId} in response to Levy event."); var accountProjections = await _accountProjectionRepository.InitialiseProjection(levySchemeDeclaration.AccountId); accountProjections.BuildLevyTriggeredProjections(DateTime.Today, _applicationConfiguration.NumberOfMonthsToProject); foreach (var accountProjectionReadModel in accountProjections.Projections) { _logger.Debug($"Generated projection: {accountProjectionReadModel.ToJson()}"); } await _accountProjectionRepository.Store(accountProjections); _logger.Info($"Finished generating account projections for account: {levySchemeDeclaration.AccountId}."); }
public async Task Handle(GenerateAccountProjectionCommand message) { _telemetry.AddEmployerAccountId(message.EmployerAccountId); var stopwatch = new Stopwatch(); stopwatch.Start(); var projections = await _accountProjectionRepository.InitialiseProjection(message.EmployerAccountId); var startDate = new DateTime( GetValue(message.StartPeriod?.Year, DateTime.Today.Year), GetValue(message.StartPeriod?.Month, DateTime.Today.Month), GetValue(message.StartPeriod?.Day, DateTime.Today.Day)); var messageProjectionSource = await _accountProjectionService.GetOriginalProjectionSource(message.EmployerAccountId, message.ProjectionSource); if (messageProjectionSource == ProjectionSource.LevyDeclaration) { projections.BuildLevyTriggeredProjections(startDate, _config.NumberOfMonthsToProject); } else { projections.BuildPayrollPeriodEndTriggeredProjections(startDate, _config.NumberOfMonthsToProject); } var expiringFunds = await _expiredFundsService.GetExpiringFunds(projections.Projections, message.EmployerAccountId, messageProjectionSource, startDate); if (expiringFunds.Any()) { projections.UpdateProjectionsWithExpiredFunds(expiringFunds); } await _accountProjectionRepository.Store(projections); stopwatch.Stop(); _telemetry.TrackDuration("BuildAccountProjection", stopwatch.Elapsed); }