Ejemplo n.º 1
0
        public async Task <LevyDeclarations> Get(string payeScheme)
        {
            _logger.Debug($"IApprenticeshipLevyApiClient.GetEmployerLevyDeclarations(\"{payeScheme}\");");

            try
            {
                _levyApiClient = await _levyTokenHttpClientFactory.GetLevyHttpClient();

                var response = await _levyApiClient.GetEmployerLevyDeclarations(payeScheme);

                if (response != null)
                {
                    var filteredDeclarations = GetFilteredDeclarations(response.Declarations);
                    response.Declarations = filteredDeclarations.OrderByDescending(x => x.SubmissionTime).ThenByDescending(x => x.Id).ToList();
                }

                return(response);
            }
            catch (ApiHttpException ex)
            {
                var properties = new Dictionary <string, object>
                {
                    { "RequestCtx.StatusCode", ex.HttpCode }
                };
                _logger.Error(ex, "Issue retrieving levy declarations", properties);
                throw;
            }
        }
        public async Task <LevyDeclarations> GetLevyDeclarations(string empRef, DateTime?fromDate)
        {
            return(await _executionPolicy.ExecuteAsync(async() =>
            {
                var accessToken = await GetOgdAccessToken();

                var earliestDate = new DateTime(2017, 04, 01);
                if (!fromDate.HasValue || fromDate.Value < earliestDate)
                {
                    fromDate = earliestDate;
                }

                var levyDeclartions = await _apprenticeshipLevyApiClient.GetEmployerLevyDeclarations(accessToken, empRef, fromDate);

                _log.Debug($"Received {levyDeclartions?.Declarations?.Count} levy declarations empRef:{empRef} fromDate:{fromDate}");
                return levyDeclartions;
            }));
        }